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

Lint the modules.json for uninstalled modules #1149

Merged
merged 6 commits into from
Jul 5, 2021
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
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 entires of modules that are not actually installed in the pipeline [[#1141]](https://github.com/nf-core/tools/issues/1141)
KevinMenden marked this conversation as resolved.
Show resolved Hide resolved

#### 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.remove import ModuleRemove
KevinMenden marked this conversation as resolved.
Show resolved Hide resolved


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
module_remove = ModuleRemove(self.wf_path)
modules_json = module_remove.load_modules_json()

if modules_json:
module_remove.get_pipeline_modules()

all_modules_passed = True

for key in modules_json["modules"].keys():
if not key in module_remove.module_names:
failed.append(f"Entry for`{key}` found in `modules.json` but module is not installed in pipeline.")
KevinMenden marked this conversation as resolved.
Show resolved Hide resolved
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.")
KevinMenden marked this conversation as resolved.
Show resolved Hide resolved

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