Skip to content

Commit

Permalink
Merge pull request #2330 from mirpedrol/fix-linting-create-template
Browse files Browse the repository at this point in the history
Fix linting when creating a pipeline skipping some parts of the template
  • Loading branch information
drpatelh authored Jun 21, 2023
2 parents 591ab1e + f5c4f4e commit ab8ca2e
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
- Error if module container specification has quay.io as prefix when it shouldn't have ([#2278])(https://github.com/nf-core/tools/pull/2278/files)
- Detect if container is 'simple name' and try to contact quay.io server by default ([#2281](https://github.com/nf-core/tools/pull/2281))
- Warn about null/None/empty default values in `nextflow_schema.json` ([#3328](https://github.com/nf-core/tools/pull/2328))
- Fix linting when creating a pipeline skipping some parts of the template and add CI test ([#2330](https://github.com/nf-core/tools/pull/2330))

### Modules

Expand Down
30 changes: 29 additions & 1 deletion nf_core/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ def render_template(self):
if self.template_yaml:
with open(self.outdir / "pipeline_template.yml", "w") as fh:
yaml.safe_dump(self.template_yaml, fh)
run_prettier_on_file(self.outdir / "pipeline_template.yml")

def update_nextflow_schema(self):
"""
Expand Down Expand Up @@ -403,6 +404,12 @@ def fix_linting(self):
".github/workflows/awstest.yml",
".github/workflows/awsfulltest.yml",
],
"files_unchanged": [
"CODE_OF_CONDUCT.md",
f"assets/nf-core-{short_name}_logo_light.png",
f"docs/images/nf-core-{short_name}_logo_light.png",
f"docs/images/nf-core-{short_name}_logo_dark.png",
],
"nextflow_config": [
"manifest.name",
"manifest.homePage",
Expand All @@ -415,9 +422,26 @@ def fix_linting(self):
lint_config["files_exist"].extend(
[
".github/ISSUE_TEMPLATE/bug_report.yml",
".github/ISSUE_TEMPLATE/feature_request.yml",
".github/PULL_REQUEST_TEMPLATE.md",
".github/CONTRIBUTING.md",
".github/.dockstore.yml",
".gitignore",
]
)
lint_config["files_unchanged"].extend(
[
".github/ISSUE_TEMPLATE/bug_report.yml",
".github/ISSUE_TEMPLATE/config.yml",
".github/ISSUE_TEMPLATE/feature_request.yml",
".github/PULL_REQUEST_TEMPLATE.md",
".github/workflows/branch.yml",
".github/workflows/linting_comment.yml",
".github/workflows/linting.yml",
".github/CONTRIBUTING.md",
".github/.dockstore.yml",
]
)
lint_config["files_unchanged"] = [".github/ISSUE_TEMPLATE/bug_report.yml"]

# Add CI specific configurations
if not self.template_params["ci"]:
Expand Down Expand Up @@ -446,6 +470,10 @@ def fix_linting(self):
if not self.template_params["github_badges"] or not self.template_params["github"]:
lint_config["readme"] = ["nextflow_badge"]

# If the pipeline is unbranded
if not self.template_params["branded"]:
lint_config["files_unchanged"].extend([".github/ISSUE_TEMPLATE/bug_report.yml"])

# Add the lint content to the preexisting nf-core config
config_fn, nf_core_yml = nf_core.utils.load_tools_config(self.outdir)
nf_core_yml["lint"] = lint_config
Expand Down
7 changes: 7 additions & 0 deletions tests/data/pipeline_create_template_skip.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
prefix: testprefix
skip:
- github
- ci
- github_badges
- igenomes
- nf_core_configs
29 changes: 29 additions & 0 deletions tests/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

TEST_DATA_DIR = Path(__file__).parent / "data"
PIPELINE_TEMPLATE_YML = TEST_DATA_DIR / "pipeline_create_template.yml"
PIPELINE_TEMPLATE_YML_SKIP = TEST_DATA_DIR / "pipeline_create_template_skip.yml"


class NfcoreCreateTest(unittest.TestCase):
Expand Down Expand Up @@ -107,3 +108,31 @@ def test_pipeline_creation_initiation_customize_template(self, mock_questionary,
assert os.path.exists(pipeline_template)
with open(pipeline_template) as fh:
assert fh.read() == PIPELINE_TEMPLATE_YML.read_text()

@with_temporary_folder
def test_pipeline_creation_with_yml_skip(self, tmp_path):
pipeline = nf_core.create.PipelineCreate(
name=self.pipeline_name,
description=self.pipeline_description,
author=self.pipeline_author,
version=self.pipeline_version,
no_git=False,
force=True,
outdir=tmp_path,
template_yaml_path=PIPELINE_TEMPLATE_YML_SKIP,
plain=True,
default_branch=self.default_branch,
)
pipeline.init_pipeline()
assert not os.path.isdir(os.path.join(pipeline.outdir, ".git"))

# Check pipeline yml has been dumped and matches input
pipeline_template = os.path.join(pipeline.outdir, "pipeline_template.yml")
assert os.path.exists(pipeline_template)
with open(pipeline_template) as fh:
assert fh.read() == PIPELINE_TEMPLATE_YML_SKIP.read_text()

# Check that some of the skipped files are not present
assert not os.path.exists(os.path.join(pipeline.outdir, "CODE_OF_CONDUCT.md"))
assert not os.path.exists(os.path.join(pipeline.outdir, ".github"))
assert not os.path.exists(os.path.join(pipeline.outdir, "conf", "igenomes.config"))

0 comments on commit ab8ca2e

Please sign in to comment.