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

Fix nf-core lint running unwanted modules test when using --key option #1209

Merged
merged 3 commits into from
Jul 16, 2021
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 @@ -9,6 +9,7 @@
### Modules

* Added consistency checks between installed modules and `modules.json` ([#1199](https://github.com/nf-core/tools/issues/1199))
* Fix `nf-core lint` not filtering modules test when run with `--key` ([#1203](https://github.com/nf-core/tools/issues/1203))

## [v2.0.1 - Palladium Platypus Junior](https://github.com/nf-core/tools/releases/tag/2.0.1) - [2021-07-13]

Expand Down
41 changes: 31 additions & 10 deletions nf_core/lint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,23 @@ def run_linting(
An object of type :class:`PipelineLint` that contains all the linting results.
"""

# Verify that the requested tests exist
if key:
all_tests = set(PipelineLint._get_all_lint_tests(release_mode)).union(set(ModuleLint._get_all_lint_tests()))
bad_keys = [k for k in key if k not in all_tests]
if len(bad_keys) > 0:
raise AssertionError(
"Test name{} not recognised: '{}'".format(
"s" if len(bad_keys) > 1 else "",
"', '".join(bad_keys),
)
)
log.info("Only running tests: '{}'".format("', '".join(key)))

# Create the lint object
lint_obj = PipelineLint(pipeline_dir, release_mode, fix, key, fail_ignored)
pipeline_keys = list(set(key).intersection(set(PipelineLint._get_all_lint_tests(release_mode)))) if key else []

lint_obj = PipelineLint(pipeline_dir, release_mode, fix, pipeline_keys, fail_ignored)

# Load the various pipeline configs
lint_obj._load_lint_config()
Expand All @@ -54,7 +69,12 @@ def run_linting(
module_lint_obj = ModuleLint(pipeline_dir)

# Run only the tests we want
module_lint_tests = ("module_changes", "module_version")
if key:
# Select only the module lint tests
module_lint_tests = list(set(key).intersection(set(ModuleLint._get_all_lint_tests())))
else:
# If no key is supplied, run the default modules tests
module_lint_tests = ("module_changes", "module_version")
module_lint_obj.filter_tests_by_key(module_lint_tests)

# Set up files for modules linting test
Expand Down Expand Up @@ -154,7 +174,14 @@ def __init__(self, wf_path, release_mode=False, fix=(), key=(), fail_ignored=Fal
self.passed = []
self.warned = []
self.could_fix = []
self.lint_tests = [
self.lint_tests = self._get_all_lint_tests(self.release_mode)
self.fix = fix
self.key = key
self.progress_bar = None

@staticmethod
def _get_all_lint_tests(release_mode):
return [
"files_exist",
"nextflow_config",
"files_unchanged",
Expand All @@ -171,12 +198,7 @@ def __init__(self, wf_path, release_mode=False, fix=(), key=(), fail_ignored=Fal
"actions_schema_validation",
"merge_markers",
"modules_json",
]
if self.release_mode:
self.lint_tests.extend(["version_consistency"])
self.fix = fix
self.key = key
self.progress_bar = None
] + (["version_consistency"] if release_mode else [])

def _load(self):
"""Load information about the pipeline into the PipelineLint object"""
Expand Down Expand Up @@ -234,7 +256,6 @@ def _lint_pipeline(self):

# If -k supplied, only run these tests
if self.key:
log.info("Only running tests: '{}'".format("', '".join(self.key)))
self.lint_tests = [k for k in self.lint_tests if k in self.key]

# Check that the pipeline_dir is a clean git repo
Expand Down
7 changes: 5 additions & 2 deletions nf_core/modules/lint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ def __init__(self, dir):
self.warned = []
self.failed = []
self.modules_repo = ModulesRepo()
self.lint_tests = ["main_nf", "functions_nf", "meta_yml", "module_changes", "module_todos"]

self.lint_tests = self._get_all_lint_tests()
# Get lists of modules install in directory
self.all_local_modules, self.all_nfcore_modules = self.get_installed_modules()

Expand All @@ -95,6 +94,10 @@ def __init__(self, dir):
# Add as first test to load git_sha before module_changes
self.lint_tests.insert(0, "module_version")

@staticmethod
def _get_all_lint_tests():
return ["main_nf", "functions_nf", "meta_yml", "module_changes", "module_todos"]

def lint(self, module=None, key=(), all_modules=False, print_results=True, show_passed=False, local=False):
"""
Lint all or one specific module
Expand Down