Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -20,6 +20,8 @@

### Subworkflows

- Linting of patched subworkflows ([#3755](https://github.com/nf-core/tools/pull/3755))

### General

- don't read param expressions with spaces as params ([#3674](https://github.com/nf-core/tools/pull/3674))
Expand Down
2 changes: 1 addition & 1 deletion nf_core/components/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def get_component_info(self):
self.meta = self.get_remote_yaml()

# Could not find the meta
if self.meta is False:
if self.meta is None:
raise UserWarning(f"Could not find {self.component_type[:-1]} '{self.component}'")

return self.generate_component_info_help()
Expand Down
8 changes: 7 additions & 1 deletion nf_core/subworkflows/lint/subworkflow_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ def subworkflow_changes(subworkflow_lint_object, subworkflow):
with open(tempdir / file, "w") as fh:
fh.writelines(lines)
except LookupError:
# This error is already reported by subworkflow_patch, so just return
subworkflow.failed.append(
(
"subworkflow_patch",
"Subworkflow patch cannot be cleanly applied",
f"{subworkflow.component_dir}",
)
)
return
else:
tempdir = subworkflow.component_dir
Expand Down
54 changes: 54 additions & 0 deletions tests/subworkflows/test_lint.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import shutil
import subprocess
from pathlib import Path

import nf_core.subworkflows
Expand Down Expand Up @@ -434,3 +435,56 @@ def test_subworkflows_lint_local_old_format(self):
assert len(subworkflow_lint.failed) == 0, f"Linting failed with {[x.__dict__ for x in subworkflow_lint.failed]}"
assert len(subworkflow_lint.passed) > 0
assert len(subworkflow_lint.warned) >= 0


class TestSubworkflowsLintPatch(TestSubworkflows):
def setUp(self) -> None:
super().setUp()

# Install the subworkflow bam_sort_stats_samtools
self.subworkflow_install.install("bam_sort_stats_samtools")

# Modify the subworkflow by inserting a new input channel
new_line = " ch_dummy // channel: [ path ]\n"

subworkflow_path = Path(self.pipeline_dir, "subworkflows", "nf-core", "bam_sort_stats_samtools", "main.nf")

with open(subworkflow_path) as fh:
lines = fh.readlines()
for line_index in range(len(lines)):
if "take:" in lines[line_index]:
lines.insert(line_index + 1, new_line)
with open(subworkflow_path, "w") as fh:
fh.writelines(lines)

# Create a patch file
self.patch_obj = nf_core.subworkflows.SubworkflowPatch(self.pipeline_dir)
self.patch_obj.patch("bam_sort_stats_samtools")

def test_lint_clean_patch(self):
"""Test linting a patched subworkflow"""

subworkflow_lint = nf_core.subworkflows.SubworkflowLint(directory=self.pipeline_dir)
subworkflow_lint.lint(print_results=False, subworkflow="bam_sort_stats_samtools")

assert len(subworkflow_lint.failed) == 0, f"Linting failed with {[x.__dict__ for x in subworkflow_lint.failed]}"
assert len(subworkflow_lint.passed) > 0
assert len(subworkflow_lint.warned) == 0, f"Linting warned with {[x.__dict__ for x in subworkflow_lint.warned]}"

def test_lint_broken_patch(self):
"""Test linting a patched subworkflow when the patch is broken"""

# Now modify the diff
diff_file = Path(
self.pipeline_dir, "subworkflows", "nf-core", "bam_sort_stats_samtools", "bam_sort_stats_samtools.diff"
)
subprocess.check_call(["sed", "-i''", "s/...$//", str(diff_file)])

subworkflow_lint = nf_core.subworkflows.SubworkflowLint(directory=self.pipeline_dir)
subworkflow_lint.lint(print_results=False, subworkflow="bam_sort_stats_samtools")

assert len(subworkflow_lint.failed) == 1, f"Linting failed with {[x.__dict__ for x in subworkflow_lint.failed]}"
errors = [x.message for x in subworkflow_lint.failed]
assert "Subworkflow patch cannot be cleanly applied" in errors
assert len(subworkflow_lint.passed) > 0
assert len(subworkflow_lint.warned) == 0, f"Linting warned with {[x.__dict__ for x in subworkflow_lint.warned]}"
4 changes: 2 additions & 2 deletions tests/subworkflows/test_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def setup_patch(self, pipeline_dir, modify_subworkflow):
self.modify_main_nf(subworkflow_path / "main.nf")

def test_create_patch_no_change(self):
"""Test creating a patch when there is a change to the module"""
"""Test creating a patch when there is no change to the subworkflow"""
self.setup_patch(self.pipeline_dir, False)

# Try creating a patch file
Expand All @@ -69,7 +69,7 @@ def test_create_patch_no_change(self):
assert not (subworkflow_path / "bam_sort_stats_samtools.diff").exists()

def test_create_patch_change(self):
"""Test creating a patch when there is no change to the subworkflow"""
"""Test creating a patch when there is a change to the subworkflow"""
self.setup_patch(self.pipeline_dir, True)

# Try creating a patch file
Expand Down