Skip to content

Commit

Permalink
Merge pull request #2189 from awgymer/template-yml-to-file-on-create
Browse files Browse the repository at this point in the history
Dump template yml to file in pipeline repo after creation
  • Loading branch information
awgymer authored Mar 27, 2023
2 parents e3b3ed3 + 326e600 commit c655a60
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 15 deletions.
9 changes: 7 additions & 2 deletions nf_core/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def __init__(
plain=False,
default_branch=None,
):
self.template_params, skip_paths_keys = self.create_param_dict(
self.template_params, skip_paths_keys, self.template_yaml = self.create_param_dict(
name, description, author, version, template_yaml_path, plain
)

Expand Down Expand Up @@ -178,7 +178,7 @@ def create_param_dict(self, name, description, author, version, template_yaml_pa
if not re.match(r"^[a-z]+$", param_dict["short_name"]):
raise UserWarning("[red]Invalid workflow name: must be lowercase without punctuation.")

return param_dict, skip_paths
return param_dict, skip_paths, template_yaml

def customize_template(self, template_areas):
"""Customizes the template parameters.
Expand Down Expand Up @@ -348,6 +348,11 @@ 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)

def update_nextflow_schema(self):
"""
Removes unused parameters from the nextflow schema.
Expand Down
1 change: 1 addition & 0 deletions tests/data/pipeline_create_template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
prefix: testprefix
92 changes: 79 additions & 13 deletions tests/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,47 @@
"""
import os
import unittest
from pathlib import Path
from unittest import mock

import git

import nf_core.create

from .utils import with_temporary_folder

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


class NfcoreCreateTest(unittest.TestCase):
@with_temporary_folder
def setUp(self, tmp_path):
def setUp(self):
self.pipeline_name = "nf-core/test"
self.pipeline_description = "just for 4w3s0m3 tests"
self.pipeline_author = "Chuck Norris"
self.pipeline_version = "1.0.0"
self.default_branch = "default"

self.pipeline = nf_core.create.PipelineCreate(
def test_pipeline_creation(self):
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,
plain=True,
default_branch=self.default_branch,
)

assert pipeline.template_params["name"] == self.pipeline_name
assert pipeline.template_params["description"] == self.pipeline_description
assert pipeline.template_params["author"] == self.pipeline_author
assert pipeline.template_params["version"] == self.pipeline_version

@with_temporary_folder
def test_pipeline_creation_initiation(self, tmp_path):
pipeline = nf_core.create.PipelineCreate(
name=self.pipeline_name,
description=self.pipeline_description,
author=self.pipeline_author,
Expand All @@ -30,14 +53,57 @@ def setUp(self, tmp_path):
plain=True,
default_branch=self.default_branch,
)
pipeline.init_pipeline()
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"))

def test_pipeline_creation(self):
assert self.pipeline.template_params["name"] == self.pipeline_name
assert self.pipeline.template_params["description"] == self.pipeline_description
assert self.pipeline.template_params["author"] == self.pipeline_author
assert self.pipeline.template_params["version"] == self.pipeline_version

def test_pipeline_creation_initiation(self):
self.pipeline.init_pipeline()
assert os.path.isdir(os.path.join(self.pipeline.outdir, ".git"))
assert f" {self.default_branch}\n" in git.Repo.init(self.pipeline.outdir).git.branch()
@with_temporary_folder
def test_pipeline_creation_initiation_with_yml(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,
plain=True,
default_branch=self.default_branch,
)
pipeline.init_pipeline()
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()

@mock.patch.object(nf_core.create.PipelineCreate, "customize_template")
@mock.patch.object(nf_core.create.questionary, "confirm")
@with_temporary_folder
def test_pipeline_creation_initiation_customize_template(self, mock_questionary, mock_customize, tmp_path):
mock_questionary.unsafe_ask.return_value = True
mock_customize.return_value = {"prefix": "testprefix"}
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,
default_branch=self.default_branch,
)
pipeline.init_pipeline()
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()

0 comments on commit c655a60

Please sign in to comment.