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 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

### Linting

- linting a pipeline also lints the installed subworkflows ([#2677](https://github.com/nf-core/tools/pull/2677))
- environment.yml name must be lowercase ([#2676](https://github.com/nf-core/tools/pull/2676))

### Modules
Expand Down
7 changes: 5 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,10 @@ def lint(
json,
ctx.obj["hide_progress"],
)
if len(lint_obj.failed) + len(module_lint_obj.failed) > 0:
swf_failed = 0
if subworkflow_lint_obj is not None:
swf_failed = len(subworkflow_lint_obj.failed)
if len(lint_obj.failed) + len(module_lint_obj.failed) + swf_failed > 0:
sys.exit(1)
except AssertionError as e:
log.critical(e)
Expand Down
29 changes: 27 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,11 @@ 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
try:
subworkflow_lint_obj = nf_core.subworkflows.lint.SubworkflowLint(pipeline_dir, hide_progress=hide_progress)
except LookupError:
subworkflow_lint_obj = None

# Verify that the pipeline is correctly configured and has a modules.json file
module_lint_obj.has_valid_directory()
Expand All @@ -98,10 +106,19 @@ 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)
if subworkflow_lint_obj is not None:
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 +136,19 @@ 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 subworkflow_lint_obj is not None:
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)
if subworkflow_lint_obj is not None:
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 +167,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
17 changes: 12 additions & 5 deletions nf_core/lint_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,20 @@
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"""
swf_passed = 0
swf_warned = 0
swf_failed = 0
if subworkflow_lint_obj is not None:
swf_passed = len(subworkflow_lint_obj.passed)
swf_warned = len(subworkflow_lint_obj.warned)
swf_failed = len(subworkflow_lint_obj.failed)
nbr_passed = len(lint_obj.passed) + len(module_lint_obj.passed) + swf_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) + swf_warned
nbr_failed = len(lint_obj.failed) + len(module_lint_obj.failed) + swf_failed

summary_colour = "red" if nbr_failed > 0 else "green"
table = Table(box=rich.box.ROUNDED, style=summary_colour)
Expand Down
6 changes: 3 additions & 3 deletions nf_core/pipeline-template/modules.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
"nf-core": {
"custom/dumpsoftwareversions": {
"branch": "master",
"git_sha": "bba7e362e4afead70653f84d8700588ea28d0f9e",
"git_sha": "8ec825f465b9c17f9d83000022995b4f7de6fe93",
"installed_by": ["modules"]
},
"fastqc": {
"branch": "master",
"git_sha": "65ad3e0b9a4099592e1102e92e10455dc661cf53",
"git_sha": "c9488585ce7bd35ccd2a30faa2371454c8112fb9",
"installed_by": ["modules"]
},
"multiqc": {
"branch": "master",
"git_sha": "4ab13872435962dadc239979554d13709e20bf29",
"git_sha": "8ec825f465b9c17f9d83000022995b4f7de6fe93",
"installed_by": ["modules"]
}
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading