Skip to content

Commit

Permalink
Merge pull request #2388 from mirpedrol/save-template-info
Browse files Browse the repository at this point in the history
Save pipeline template info to `.nf-core.yml`
mirpedrol authored Aug 7, 2023
2 parents ef1b51a + e8c289e commit 65b4b5f
Showing 3 changed files with 33 additions and 22 deletions.
14 changes: 7 additions & 7 deletions nf_core/create.py
Original file line number Diff line number Diff line change
@@ -187,9 +187,7 @@ def customize_template(self, template_areas):
"""Customizes the template parameters.
Args:
name (str): Name for the pipeline.
description (str): Description for the pipeline.
author (str): Authors name of the pipeline.
template_areas (list<str>): List of available template areas to skip.
"""
template_yaml = {}
prefix = questionary.text("Pipeline prefix", style=nf_core.utils.nfcore_question_style).unsafe_ask()
@@ -351,11 +349,13 @@ def render_template(self):
# Update the .nf-core.yml with linting configurations
self.fix_linting()

log.debug("Dumping pipeline template yml to file")
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")
config_fn, config_yml = nf_core.utils.load_tools_config(self.outdir)
with open(self.outdir / config_fn, "w") as fh:
config_yml.update(template=self.template_yaml)
yaml.safe_dump(config_yml, fh)
log.debug(f"Dumping pipeline template yml to pipeline config file '{config_fn.name}'")
run_prettier_on_file(self.outdir / config_fn)

def update_nextflow_schema(self):
"""
2 changes: 2 additions & 0 deletions nf_core/lint/files_exist.py
Original file line number Diff line number Diff line change
@@ -78,6 +78,7 @@ def files_exist(self):
Singularity
parameters.settings.json
pipeline_template.yml # saving information in .nf-core.yml
.nf-core.yaml # NB: Should be yml, not yaml
bin/markdown_to_html.r
conf/aws.config
@@ -181,6 +182,7 @@ def files_exist(self):
files_fail_ifexists = [
"Singularity",
"parameters.settings.json",
"pipeline_template.yml", # saving information in .nf-core.yml
".nf-core.yaml", # yml not yaml
os.path.join("bin", "markdown_to_html.r"),
os.path.join("conf", "aws.config"),
39 changes: 24 additions & 15 deletions tests/test_create.py
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
from unittest import mock

import git
import yaml

import nf_core.create

@@ -58,6 +59,8 @@ def test_pipeline_creation_initiation(self, tmp_path):
assert os.path.isdir(os.path.join(pipeline.outdir, ".git"))
assert f" {self.default_branch}\n" in git.Repo.init(pipeline.outdir).git.branch()
assert not os.path.exists(os.path.join(pipeline.outdir, "pipeline_template.yml"))
with open(os.path.join(pipeline.outdir, ".nf-core.yml")) as fh:
assert "template" not in fh.read()

@with_temporary_folder
def test_pipeline_creation_initiation_with_yml(self, tmp_path):
@@ -77,11 +80,13 @@ def test_pipeline_creation_initiation_with_yml(self, tmp_path):
assert os.path.isdir(os.path.join(pipeline.outdir, ".git"))
assert f" {self.default_branch}\n" in git.Repo.init(pipeline.outdir).git.branch()

# 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.read_text()
# Check pipeline template yml has been dumped to `.nf-core.yml` and matches input
assert not os.path.exists(os.path.join(pipeline.outdir, "pipeline_template.yml"))
assert os.path.exists(os.path.join(pipeline.outdir, ".nf-core.yml"))
with open(os.path.join(pipeline.outdir, ".nf-core.yml")) as fh:
nfcore_yml = yaml.safe_load(fh)
assert "template" in nfcore_yml
assert nfcore_yml["template"] == yaml.safe_load(PIPELINE_TEMPLATE_YML.read_text())

@mock.patch.object(nf_core.create.PipelineCreate, "customize_template")
@mock.patch.object(nf_core.create.questionary, "confirm")
@@ -103,11 +108,13 @@ def test_pipeline_creation_initiation_customize_template(self, mock_questionary,
assert os.path.isdir(os.path.join(pipeline.outdir, ".git"))
assert f" {self.default_branch}\n" in git.Repo.init(pipeline.outdir).git.branch()

# 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.read_text()
# Check pipeline template yml has been dumped to `.nf-core.yml` and matches input
assert not os.path.exists(os.path.join(pipeline.outdir, "pipeline_template.yml"))
assert os.path.exists(os.path.join(pipeline.outdir, ".nf-core.yml"))
with open(os.path.join(pipeline.outdir, ".nf-core.yml")) as fh:
nfcore_yml = yaml.safe_load(fh)
assert "template" in nfcore_yml
assert nfcore_yml["template"] == yaml.safe_load(PIPELINE_TEMPLATE_YML.read_text())

@with_temporary_folder
def test_pipeline_creation_with_yml_skip(self, tmp_path):
@@ -126,11 +133,13 @@ def test_pipeline_creation_with_yml_skip(self, tmp_path):
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 pipeline template yml has been dumped to `.nf-core.yml` and matches input
assert not os.path.exists(os.path.join(pipeline.outdir, "pipeline_template.yml"))
assert os.path.exists(os.path.join(pipeline.outdir, ".nf-core.yml"))
with open(os.path.join(pipeline.outdir, ".nf-core.yml")) as fh:
nfcore_yml = yaml.safe_load(fh)
assert "template" in nfcore_yml
assert nfcore_yml["template"] == yaml.safe_load(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"))

0 comments on commit 65b4b5f

Please sign in to comment.