From 39314ff6baa7fdf005b5aa2c32f07d80304e9f7d Mon Sep 17 00:00:00 2001 From: Erik Danielsson Date: Fri, 16 Jul 2021 12:03:28 +0200 Subject: [PATCH 1/3] Fix lint test filters --- nf_core/lint/__init__.py | 41 ++++++++++++++++++++++++-------- nf_core/modules/lint/__init__.py | 7 ++++-- 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/nf_core/lint/__init__.py b/nf_core/lint/__init__.py index 53ecaaffa9..cf0b94bd0b 100644 --- a/nf_core/lint/__init__.py +++ b/nf_core/lint/__init__.py @@ -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 None + + lint_obj = PipelineLint(pipeline_dir, release_mode, fix, pipeline_keys, fail_ignored) # Load the various pipeline configs lint_obj._load_lint_config() @@ -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 @@ -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", @@ -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""" @@ -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 diff --git a/nf_core/modules/lint/__init__.py b/nf_core/modules/lint/__init__.py index 433735034f..f9de48a304 100644 --- a/nf_core/modules/lint/__init__.py +++ b/nf_core/modules/lint/__init__.py @@ -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() @@ -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 From 830926b42863ebb615d468f8213337fc739faf7d Mon Sep 17 00:00:00 2001 From: Erik Danielsson Date: Fri, 16 Jul 2021 12:07:16 +0200 Subject: [PATCH 2/3] Fix failing test --- nf_core/lint/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nf_core/lint/__init__.py b/nf_core/lint/__init__.py index cf0b94bd0b..47f638897d 100644 --- a/nf_core/lint/__init__.py +++ b/nf_core/lint/__init__.py @@ -56,7 +56,7 @@ def run_linting( log.info("Only running tests: '{}'".format("', '".join(key))) # Create the lint object - pipeline_keys = list(set(key).intersection(set(PipelineLint._get_all_lint_tests(release_mode)))) if key else None + 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) From 437467fe4a6338ad84bbc6c4b4aa3c8cd23162bb Mon Sep 17 00:00:00 2001 From: Erik Danielsson Date: Fri, 16 Jul 2021 12:08:47 +0200 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 86f1d5a88e..886808f6e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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]