Skip to content

Commit

Permalink
Merge pull request #1149 from KevinMenden/lint-modules-json
Browse files Browse the repository at this point in the history
Lint the `modules.json` for uninstalled modules
  • Loading branch information
KevinMenden authored Jul 5, 2021
2 parents 7b8ae3f + 47b83ba commit ec7b5e8
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
* Updated `nf-core modules remove` to remove module entry in `modules.json` if module directory is missing
* Create extra tempdir as work directory for `nf-core modules create-test-yml` to avoid adding the temporary files to the `test.yml`
* Refactored passing of command line arguments to `nf-core` commands and subcommands ([#1139](https://github.com/nf-core/tools/issues/1139), [#1140](https://github.com/nf-core/tools/issues/1140))
* Check for `modules.json` for entries of modules that are not actually installed in the pipeline [[#1141](https://github.com/nf-core/tools/issues/1141)]
* Added `<keywords>` argument to `nf-core modules list` for filtering the listed modules. ([#1139](https://github.com/nf-core/tools/issues/1139)

#### Sync
Expand Down
4 changes: 4 additions & 0 deletions docs/api/_src/pipeline_lint_tests/modules_json.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
nextflow_config
===============

.. automethod:: nf_core.lint.PipelineLint.modules_json
2 changes: 2 additions & 0 deletions nf_core/lint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class PipelineLint(nf_core.utils.Pipeline):
from .files_exist import files_exist
from .files_unchanged import files_unchanged
from .merge_markers import merge_markers
from .modules_json import modules_json
from .nextflow_config import nextflow_config
from .params_used import params_used
from .pipeline_name_conventions import pipeline_name_conventions
Expand Down Expand Up @@ -154,6 +155,7 @@ def __init__(self, wf_path, release_mode=False, fix=(), key=(), fail_ignored=Fal
"schema_description",
"actions_schema_validation",
"merge_markers",
"modules_json",
]
if self.release_mode:
self.lint_tests.extend(["version_consistency"])
Expand Down
38 changes: 38 additions & 0 deletions nf_core/lint/modules_json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env python

from logging import warn
from nf_core.modules.modules_command import ModuleCommand


def modules_json(self):
"""Make sure all modules described in the ``modules.json`` file are actually installed
Every module installed from ``nf-core/modules`` must have an entry in the ``modules.json`` file
with an associated version git_sha hash.
* Failure: If module entries are found in ``modules.json`` for modules that are not installed
"""
passed = []
warned = []
failed = []

# Load pipeline modules and modules.json
modules_command = ModuleCommand(self.wf_path)
modules_json = modules_command.load_modules_json()

if modules_json:
modules_command.get_pipeline_modules()

all_modules_passed = True

for key in modules_json["modules"].keys():
if not key in modules_command.module_names:
failed.append(f"Entry for `{key}` found in `modules.json` but module is not installed in pipeline.")
all_modules_passed = False

if all_modules_passed:
passed.append("Only installed modules found in `modules.json`")
else:
warned.append("Could not open `modules.json` file.")

return {"passed": passed, "warned": warned, "failed": failed}
9 changes: 9 additions & 0 deletions tests/lint/modules_json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import nf_core.lint


def test_modules_json_fail(self):
self.lint_obj._load()
results = self.lint_obj.modules_json()
assert len(results.get("warned", [])) == 0
assert len(results.get("failed", [])) == 0
assert len(results.get("passed", [])) == 1
2 changes: 2 additions & 0 deletions tests/test_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ def test_sphinx_rst_files(self):

from lint.version_consistency import test_version_consistency

from lint.modules_json import test_modules_json_fail


# TODO nf-core: Assess and strip out if no longer required for DSL2

Expand Down

0 comments on commit ec7b5e8

Please sign in to comment.