Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🩹 added patch command for subworkflows #2861

Merged
merged 29 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
7d24e75
added patch command for subworkflows
ctuni Mar 18, 2024
ef7371f
Merge branch 'dev' into master
ctuni Mar 18, 2024
86e3e2f
forgot to import patch in init
ctuni Mar 18, 2024
9a0b2e7
Merge branch 'master' of https://github.com/ctuni/tools
ctuni Mar 18, 2024
26b39c2
added files for the tests
ctuni Mar 18, 2024
015a61b
created draft for test file
ctuni Mar 18, 2024
563e232
ruff format
ctuni Mar 18, 2024
31505ab
cleaning up
ctuni Mar 18, 2024
4d0dc85
added tests
ctuni Mar 18, 2024
3030a76
ruff
ctuni Mar 18, 2024
6b885ff
ruff format
ctuni Mar 18, 2024
dfcfb5b
removed split
ctuni Mar 18, 2024
2991930
mypy
ctuni Mar 18, 2024
e909d3c
setup_patch
ctuni Mar 18, 2024
fd5b0d1
called function correctly
ctuni Mar 18, 2024
cdd9cfb
wraping up for the day
ctuni Mar 18, 2024
7f40b3a
Merge branch 'dev' of https://github.com/nf-core/tools
mirpedrol Nov 15, 2024
7cd3dea
update and fix swf patch tests
mirpedrol Nov 15, 2024
424bbae
Merge branch 'dev' into master
ewels Nov 21, 2024
25940f7
apply patch reverse when linting a patched subworkflow
mirpedrol Nov 22, 2024
b2cfd01
update get_patch_fn to work with subworkflows
mirpedrol Nov 22, 2024
6ec2dcd
move modules_differ.py to components_differ.py
mirpedrol Nov 22, 2024
27582f9
add subworkflows patch missing tests
mirpedrol Nov 25, 2024
4f93d57
fix subworkflows update test
mirpedrol Nov 25, 2024
5ad4570
update changelog
mirpedrol Nov 25, 2024
37ca244
add help text for --remove flag
mirpedrol Nov 25, 2024
805ba91
apply code review suggestions to patch tests
mirpedrol Nov 25, 2024
84cec26
Update tests/modules/test_patch.py
mirpedrol Nov 25, 2024
8b2bec4
apply suggestions by @mashehu
mirpedrol Nov 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

### Subworkflows

- Add `nf-core subworkflows patch` command ([#2861](https://github.com/nf-core/tools/pull/2861))

### General

- Include .nf-core.yml in `nf-core pipelines bump-version` ([#3220](https://github.com/nf-core/tools/pull/3220))
Expand Down
4 changes: 2 additions & 2 deletions nf_core/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,7 @@ def command_modules_update(
default=".",
help=r"Pipeline directory. [dim]\[default: current working directory][/]",
)
@click.option("-r", "--remove", is_flag=True, default=False)
@click.option("-r", "--remove", is_flag=True, default=False, help="Remove an existent patch file and regenerate it.")
def command_modules_patch(ctx, tool, directory, remove):
"""
Create a patch file for minor changes in a module
Expand Down Expand Up @@ -1578,7 +1578,7 @@ def command_subworkflows_install(ctx, subworkflow, directory, prompt, force, sha
default=".",
help=r"Pipeline directory. [dim]\[default: current working directory][/]",
)
@click.option("-r", "--remove", is_flag=True, default=False)
@click.option("-r", "--remove", is_flag=True, default=False, help="Remove an existent patch file and regenerate it.")
def subworkflows_patch(ctx, tool, dir, remove):
"""
Create a patch file for minor changes in a subworkflow
Expand Down
20 changes: 10 additions & 10 deletions tests/modules/test_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def test_create_patch_no_change(self):
module_path = Path(self.pipeline_dir, "modules", REPO_NAME, BISMARK_ALIGN)

# Check that no patch file has been added to the directory
assert set(os.listdir(module_path)) == {"main.nf", "meta.yml", "environment.yml"}
assert "bismark-align.diff" in set(os.listdir(module_path))
mirpedrol marked this conversation as resolved.
Show resolved Hide resolved

# Check the 'modules.json' contains no patch file for the module
modules_json_obj = nf_core.modules.modules_json.ModulesJson(self.pipeline_dir)
Expand All @@ -94,7 +94,7 @@ def test_create_patch_change(self):

patch_fn = f"{'-'.join(BISMARK_ALIGN.split('/'))}.diff"
# Check that a patch file with the correct name has been created
assert set(os.listdir(module_path)) == {"main.nf", "meta.yml", "environment.yml", patch_fn}
assert patch_fn in set(os.listdir(module_path))
mirpedrol marked this conversation as resolved.
Show resolved Hide resolved

# Check the 'modules.json' contains a patch file for the module
modules_json_obj = nf_core.modules.modules_json.ModulesJson(self.pipeline_dir)
Expand Down Expand Up @@ -127,7 +127,7 @@ def test_create_patch_try_apply_successful(self):

patch_fn = f"{'-'.join(BISMARK_ALIGN.split('/'))}.diff"
# Check that a patch file with the correct name has been created
assert set(os.listdir(module_path)) == {"main.nf", "meta.yml", "environment.yml", patch_fn}
assert patch_fn in set(os.listdir(module_path))

# Check the 'modules.json' contains a patch file for the module
modules_json_obj = nf_core.modules.modules_json.ModulesJson(self.pipeline_dir)
Expand All @@ -153,7 +153,7 @@ def test_create_patch_try_apply_successful(self):
update_obj.move_files_from_tmp_dir(BISMARK_ALIGN, install_dir, REPO_NAME, SUCCEED_SHA)

# Check that a patch file with the correct name has been created
assert set(os.listdir(module_path)) == {"main.nf", "meta.yml", "environment.yml", patch_fn}
assert patch_fn in set(os.listdir(module_path))

# Check the 'modules.json' contains a patch file for the module
modules_json_obj = nf_core.modules.modules_json.ModulesJson(self.pipeline_dir)
Expand Down Expand Up @@ -195,7 +195,7 @@ def test_create_patch_try_apply_failed(self):

patch_fn = f"{'-'.join(BISMARK_ALIGN.split('/'))}.diff"
# Check that a patch file with the correct name has been created
assert set(os.listdir(module_path)) == {"main.nf", "meta.yml", "environment.yml", patch_fn}
assert patch_fn in set(os.listdir(module_path))

# Check the 'modules.json' contains a patch file for the module
modules_json_obj = nf_core.modules.modules_json.ModulesJson(self.pipeline_dir)
Expand Down Expand Up @@ -234,7 +234,7 @@ def test_create_patch_update_success(self):

patch_fn = f"{'-'.join(BISMARK_ALIGN.split('/'))}.diff"
# Check that a patch file with the correct name has been created
assert set(os.listdir(module_path)) == {"main.nf", "meta.yml", "environment.yml", patch_fn}
assert patch_fn in set(os.listdir(module_path))

# Check the 'modules.json' contains a patch file for the module
modules_json_obj = nf_core.modules.modules_json.ModulesJson(self.pipeline_dir)
Expand All @@ -254,7 +254,7 @@ def test_create_patch_update_success(self):
assert update_obj.update(BISMARK_ALIGN)

# Check that a patch file with the correct name has been created
assert set(os.listdir(module_path)) == {"main.nf", "meta.yml", "environment.yml", patch_fn}
assert patch_fn in set(os.listdir(module_path))

# Check the 'modules.json' contains a patch file for the module
modules_json_obj = nf_core.modules.modules_json.ModulesJson(self.pipeline_dir)
Expand Down Expand Up @@ -295,7 +295,7 @@ def test_create_patch_update_fail(self):

patch_fn = f"{'-'.join(BISMARK_ALIGN.split('/'))}.diff"
# Check that a patch file with the correct name has been created
assert set(os.listdir(module_path)) == {"main.nf", "meta.yml", "environment.yml", patch_fn}
assert patch_fn in set(os.listdir(module_path))

# Check the 'modules.json' contains a patch file for the module
modules_json_obj = nf_core.modules.modules_json.ModulesJson(self.pipeline_dir)
Expand Down Expand Up @@ -349,7 +349,7 @@ def test_remove_patch(self):

# Check that a patch file with the correct name has been created
patch_fn = f"{'-'.join(BISMARK_ALIGN.split('/'))}.diff"
assert set(os.listdir(module_path)) == {"main.nf", "meta.yml", "environment.yml", patch_fn}
assert patch_fn in set(os.listdir(module_path))

# Check the 'modules.json' contains a patch file for the module
modules_json_obj = nf_core.modules.modules_json.ModulesJson(self.pipeline_dir)
Expand All @@ -361,7 +361,7 @@ def test_remove_patch(self):
mock_questionary.unsafe_ask.return_value = True
patch_obj.remove(BISMARK_ALIGN)
# Check that the diff file has been removed
assert set(os.listdir(module_path)) == {"main.nf", "meta.yml", "environment.yml"}
assert patch_fn not in set(os.listdir(module_path))

# Check that the 'modules.json' entry has been removed
modules_json_obj = nf_core.modules.modules_json.ModulesJson(self.pipeline_dir)
Expand Down
20 changes: 10 additions & 10 deletions tests/subworkflows/test_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def test_create_patch_no_change(self):
subworkflow_path = Path(self.pipeline_dir, "subworkflows", GITLAB_REPO, "bam_sort_stats_samtools")

# Check that no patch file has been added to the directory
assert set(os.listdir(subworkflow_path)) == {"main.nf", "meta.yml"}
assert "bam_sort_stats_samtools.diff" not in set(os.listdir(subworkflow_path))

def test_create_patch_change(self):
"""Test creating a patch when there is no change to the subworkflow"""
Expand All @@ -79,7 +79,7 @@ def test_create_patch_change(self):
subworkflow_path = Path(self.pipeline_dir, "subworkflows", GITLAB_REPO, "bam_sort_stats_samtools")

# Check that a patch file with the correct name has been created
assert set(os.listdir(subworkflow_path)) == {"main.nf", "meta.yml", "bam_sort_stats_samtools.diff"}
assert "bam_sort_stats_samtools.diff" in set(os.listdir(subworkflow_path))

# Check that the correct lines are in the patch file
with open(subworkflow_path / "bam_sort_stats_samtools.diff") as fh:
Expand All @@ -101,7 +101,7 @@ def test_create_patch_try_apply_successful(self):
patch_obj.patch("bam_sort_stats_samtools")

# Check that a patch file with the correct name has been created
assert set(os.listdir(subworkflow_path)) == {"main.nf", "meta.yml", "bam_sort_stats_samtools.diff"}
assert "bam_sort_stats_samtools.diff" in set(os.listdir(subworkflow_path))

update_obj = nf_core.subworkflows.SubworkflowUpdate(
self.pipeline_dir, sha=OLD_SHA, remote_url=GITLAB_URL, branch=GITLAB_SUBWORKFLOWS_BRANCH
Expand All @@ -125,7 +125,7 @@ def test_create_patch_try_apply_successful(self):
update_obj.move_files_from_tmp_dir("bam_sort_stats_samtools", install_dir, GITLAB_REPO, OLD_SHA)

# Check that a patch file with the correct name has been created
assert set(os.listdir(subworkflow_path)) == {"main.nf", "meta.yml", "bam_sort_stats_samtools.diff"}
assert "bam_sort_stats_samtools.diff" in set(os.listdir(subworkflow_path))

# Check that the correct lines are in the patch file
with open(subworkflow_path / "bam_sort_stats_samtools.diff") as fh:
Expand All @@ -152,7 +152,7 @@ def test_create_patch_try_apply_failed(self):
patch_obj.patch("bam_sort_stats_samtools")

# Check that a patch file with the correct name has been created
assert set(os.listdir(subworkflow_path)) == {"main.nf", "meta.yml", "bam_sort_stats_samtools.diff"}
assert "bam_sort_stats_samtools.diff" in set(os.listdir(subworkflow_path))

update_obj = nf_core.subworkflows.SubworkflowUpdate(
self.pipeline_dir, remote_url=GITLAB_URL, branch=GITLAB_SUBWORKFLOWS_BRANCH
Expand Down Expand Up @@ -188,7 +188,7 @@ def test_create_patch_update_success(self):

patch_fn = "bam_sort_stats_samtools.diff"
# Check that a patch file with the correct name has been created
assert set(os.listdir(swf_path)) == {"main.nf", "meta.yml", patch_fn}
assert patch_fn in set(os.listdir(swf_path))

# Check the 'modules.json' contains a patch file for the subworkflow
modules_json_obj = nf_core.modules.modules_json.ModulesJson(self.pipeline_dir)
Expand All @@ -208,7 +208,7 @@ def test_create_patch_update_success(self):
assert update_obj.update("bam_sort_stats_samtools")

# Check that a patch file with the correct name has been created
assert set(os.listdir(swf_path)) == {"main.nf", "meta.yml", patch_fn}
assert patch_fn in set(os.listdir(swf_path))

# Check the 'modules.json' contains a patch file for the subworkflow
modules_json_obj = nf_core.modules.modules_json.ModulesJson(self.pipeline_dir)
Expand Down Expand Up @@ -245,7 +245,7 @@ def test_create_patch_update_fail(self):

patch_fn = "bam_sort_stats_samtools.diff"
# Check that a patch file with the correct name has been created
assert set(os.listdir(swf_path)) == {"main.nf", "meta.yml", patch_fn}
assert patch_fn in set(os.listdir(swf_path))

# Check the 'modules.json' contains a patch file for the subworkflow
modules_json_obj = nf_core.modules.modules_json.ModulesJson(self.pipeline_dir)
Expand Down Expand Up @@ -298,10 +298,10 @@ def test_remove_patch(self):
subworkflow_path = Path(self.pipeline_dir, "subworkflows", GITLAB_REPO, "bam_sort_stats_samtools")

# Check that a patch file with the correct name has been created
assert set(os.listdir(subworkflow_path)) == {"main.nf", "meta.yml", "bam_sort_stats_samtools.diff"}
assert "bam_sort_stats_samtools.diff" in set(os.listdir(subworkflow_path))

with mock.patch.object(nf_core.components.patch.questionary, "confirm") as mock_questionary:
mock_questionary.unsafe_ask.return_value = True
patch_obj.remove("bam_sort_stats_samtools")
# Check that the diff file has been removed
assert set(os.listdir(subworkflow_path)) == {"main.nf", "meta.yml"}
assert "bam_sort_stats_samtools.diff" not in set(os.listdir(subworkflow_path))
Loading