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

Linting: linting a pipeline also lints the installed subworkflows #2677

Merged
merged 7 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -15,6 +15,8 @@

### Linting

- linting a pipeline also lints the installed subworkflows ([#2677](https://github.com/nf-core/tools/pull/2677))

### Modules

- Fix linting of a pipeline with patched custom module ([#2669](https://github.com/nf-core/tools/pull/2669))
Expand Down
4 changes: 2 additions & 2 deletions nf_core/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ def lint(

# Run the lint tests!
try:
lint_obj, module_lint_obj = run_linting(
lint_obj, module_lint_obj, subworkflow_lint_obj = run_linting(
dir,
release,
fix,
Expand All @@ -613,7 +613,7 @@ def lint(
json,
ctx.obj["hide_progress"],
)
if len(lint_obj.failed) + len(module_lint_obj.failed) > 0:
if len(lint_obj.failed) + len(module_lint_obj.failed) + len(subworkflow_lint_obj.failed) > 0:
sys.exit(1)
except AssertionError as e:
log.critical(e)
Expand Down
4 changes: 1 addition & 3 deletions nf_core/components/lint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ def __init__(
)
)
if not self.all_remote_components:
raise LookupError(
f"No {self.component_type} from {self.modules_repo.remote_url} installed in pipeline."
)
log.warning(f"No {self.component_type} from {self.modules_repo.remote_url} installed in pipeline.")
local_component_dir = Path(self.dir, self.component_type, "local")
self.all_local_components = []
if local_component_dir.exists():
Expand Down
23 changes: 21 additions & 2 deletions nf_core/lint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import nf_core.lint_utils
import nf_core.modules.lint
import nf_core.subworkflows.lint
import nf_core.utils
from nf_core import __version__
from nf_core.lint_utils import console
Expand Down Expand Up @@ -53,6 +54,8 @@ def run_linting(

Returns:
An object of type :class:`PipelineLint` that contains all the linting results.
An object of type :class:`ComponentLint` that contains all the linting results for the modules.
An object of type :class:`ComponentLint` that contains all the linting results for the subworkflows.
"""

# Verify that the requested tests exist
Expand Down Expand Up @@ -87,6 +90,8 @@ def run_linting(

# Create the modules lint object
module_lint_obj = nf_core.modules.lint.ModuleLint(pipeline_dir, hide_progress=hide_progress)
# Create the subworkflows lint object
subworkflow_lint_obj = nf_core.subworkflows.lint.SubworkflowLint(pipeline_dir, hide_progress=hide_progress)

# Verify that the pipeline is correctly configured and has a modules.json file
module_lint_obj.has_valid_directory()
Expand All @@ -98,10 +103,18 @@ def run_linting(
module_lint_tests = list(
set(key).intersection(set(nf_core.modules.lint.ModuleLint.get_all_module_lint_tests(is_pipeline=True)))
)
# Select only the subworkflow lint tests
subworkflow_lint_tests = list(
set(key).intersection(
set(nf_core.subworkflows.lint.SubworkflowLint.get_all_subworkflow_lint_tests(is_pipeline=True))
)
)
else:
# If no key is supplied, run the default modules tests
module_lint_tests = ("module_changes", "module_version")
subworkflow_lint_tests = ("subworkflow_changes", "subworkflow_version")
module_lint_obj.filter_tests_by_key(module_lint_tests)
subworkflow_lint_obj.filter_tests_by_key(subworkflow_lint_tests)

# Set up files for modules linting test
module_lint_obj.set_up_pipeline_files()
Expand All @@ -119,11 +132,17 @@ def run_linting(
module_lint_obj.lint_modules(module_lint_obj.all_local_components, local=True)
if len(module_lint_obj.all_remote_components) > 0:
module_lint_obj.lint_modules(module_lint_obj.all_remote_components, local=False)
# Run the subworkflows lint tests
if len(subworkflow_lint_obj.all_local_components) > 0:
subworkflow_lint_obj.lint_subworkflows(subworkflow_lint_obj.all_local_components, local=True)
if len(subworkflow_lint_obj.all_remote_components) > 0:
subworkflow_lint_obj.lint_subworkflows(subworkflow_lint_obj.all_remote_components, local=False)

# Print the results
lint_obj._print_results(show_passed)
module_lint_obj._print_results(show_passed, sort_by=sort_by)
nf_core.lint_utils.print_joint_summary(lint_obj, module_lint_obj)
subworkflow_lint_obj._print_results(show_passed, sort_by=sort_by)
nf_core.lint_utils.print_joint_summary(lint_obj, module_lint_obj, subworkflow_lint_obj)
nf_core.lint_utils.print_fixes(lint_obj)

# Save results to Markdown file
Expand All @@ -142,7 +161,7 @@ def run_linting(
if release_mode:
log.info("Reminder: Lint tests were run in --release mode.")

return lint_obj, module_lint_obj
return lint_obj, module_lint_obj, subworkflow_lint_obj


class PipelineLint(nf_core.utils.Pipeline):
Expand Down
10 changes: 5 additions & 5 deletions nf_core/lint_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
console = Console(force_terminal=nf_core.utils.rich_force_colors())


def print_joint_summary(lint_obj, module_lint_obj):
"""Print a joint summary of the general pipe lint tests and the module lint tests"""
nbr_passed = len(lint_obj.passed) + len(module_lint_obj.passed)
def print_joint_summary(lint_obj, module_lint_obj, subworkflow_lint_obj):
"""Print a joint summary of the general pipe lint tests and the module and subworkflow lint tests"""
nbr_passed = len(lint_obj.passed) + len(module_lint_obj.passed) + len(subworkflow_lint_obj.passed)
nbr_ignored = len(lint_obj.ignored)
nbr_fixed = len(lint_obj.fixed)
nbr_warned = len(lint_obj.warned) + len(module_lint_obj.warned)
nbr_failed = len(lint_obj.failed) + len(module_lint_obj.failed)
nbr_warned = len(lint_obj.warned) + len(module_lint_obj.warned) + len(subworkflow_lint_obj.warned)
nbr_failed = len(lint_obj.failed) + len(module_lint_obj.failed) + len(subworkflow_lint_obj.failed)

summary_colour = "red" if nbr_failed > 0 else "green"
table = Table(box=rich.box.ROUNDED, style=summary_colour)
Expand Down
Loading