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

obtain module suggestions from installed modules #1624

Merged
merged 22 commits into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from 6 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 @@ -21,6 +21,7 @@

- Add `--fix-version` flag to `nf-core modules lint` command to update modules to the latest version ([#1588](https://github.com/nf-core/tools/pull/1588))
- Fix a bug in the regex extracting the version from biocontainers URLs [#1598](https://github.com/nf-core/tools/pull/1598)
- Command `nf-core modules test` obtains module name suggestions from installed modules [#1624](https://github.com/nf-core/tools/pull/1624)

## [v2.4.1 - Cobolt Koala Patch](https://github.com/nf-core/tools/releases/tag/2.4) - [2022-05-16]

Expand Down
25 changes: 20 additions & 5 deletions nf_core/modules/module_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
import questionary
import rich

import nf_core.modules.module_utils
import nf_core.utils

from .modules_repo import ModulesRepo

log = logging.getLogger(__name__)


Expand All @@ -34,6 +33,10 @@ class ModulesTest(object):
flat indicating if prompts are used
pytest_args : tuple
additional arguments passed to pytest command
all_local_modules: list
List of all installed local modules
all_nfcore_modules: list
List of all installed nf-core modules

Methods
-------
Expand All @@ -56,6 +59,8 @@ def __init__(
self.module_name = module_name
self.no_prompts = no_prompts
self.pytest_args = pytest_args
self.all_local_modules = ""
self.all_nfcore_modules = ""
mirpedrol marked this conversation as resolved.
Show resolved Hide resolved
mirpedrol marked this conversation as resolved.
Show resolved Hide resolved

def run(self):
"""Run test steps"""
Expand All @@ -71,17 +76,27 @@ def run(self):
def _check_inputs(self):
"""Do more complex checks about supplied flags."""

# Get installed modules
self.all_local_modules, self.all_nfcore_modules = nf_core.modules.module_utils.get_installed_modules(
mirpedrol marked this conversation as resolved.
Show resolved Hide resolved
".", "modules"
)

# Get the tool name if not specified
if self.module_name is None:
if self.no_prompts:
raise UserWarning(
"Tool name not provided and prompts deactivated. Please provide the tool name as TOOL/SUBTOOL or TOOL."
)
modules_repo = ModulesRepo()
modules_repo.get_modules_file_tree()
all_installed_modules = [m.module_name for m in self.all_nfcore_modules]
mirpedrol marked this conversation as resolved.
Show resolved Hide resolved
if len(all_installed_modules) == 0:
raise UserWarning(
"No installed modules were found.\n"
"Are you running the tests inside the nf-core/modules main directory?\n"
"Otherwise, make sure that the directory structure is modules/TOOL/SUBTOOL/ and tests/modules/TOOLS/SUBTOOL/"
)
self.module_name = questionary.autocomplete(
"Tool name:",
choices=modules_repo.modules_avail_module_names,
choices=all_installed_modules,
style=nf_core.utils.nfcore_question_style,
).ask()
module_dir = Path("modules") / self.module_name
Expand Down
10 changes: 10 additions & 0 deletions tests/modules/module_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,13 @@ def test_modules_test_no_name_no_prompts(self):
meta_builder._check_inputs()
os.chdir(cwd)
assert "Tool name not provided and prompts deactivated." in str(excinfo.value)


def test_modules_test_no_installed_modules(self):
"""Test the check_inputs() function - raise UserWarning because installed modules were not found"""
cwd = os.getcwd()
meta_builder = nf_core.modules.ModulesTest(None, False, "")
with pytest.raises(UserWarning) as excinfo:
meta_builder._check_inputs()
os.chdir(cwd)
assert "No installed modules were found." in str(excinfo.value)
1 change: 1 addition & 0 deletions tests/test_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def test_modulesrepo_class(self):
)
from .modules.module_test import (
test_modules_test_check_inputs,
test_modules_test_no_installed_modules,
test_modules_test_no_name_no_prompts,
)
from .modules.remove import (
Expand Down