Skip to content

Commit

Permalink
feat(1929): allow missing files when linting local modules
Browse files Browse the repository at this point in the history
  • Loading branch information
awgymer committed Oct 29, 2024
1 parent 2308e3b commit 31cffdd
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 9 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@
### Modules

- add a panel around diff previews when updating ([#3246](https://github.com/nf-core/tools/pull/3246))
- Modules created in pipelines "local" dir now use the full template ([#3256](https://github.com/nf-core/tools/pull/3256))

### Subworkflows

- Subworkflows created in pipelines "local" dir now use the full template ([#3256](https://github.com/nf-core/tools/pull/3256))

### General

- Include .nf-core.yml in `nf-core pipelines bump-version` ([#3220](https://github.com/nf-core/tools/pull/3220))
Expand All @@ -33,7 +36,6 @@
- Update GitHub Actions ([#3237](https://github.com/nf-core/tools/pull/3237))
- add `--dir/-d` option to schema commands ([#3247](https://github.com/nf-core/tools/pull/3247))
- Update pre-commit hook astral-sh/ruff-pre-commit to v0.7.1 ([#3250](https://github.com/nf-core/tools/pull/3250))
- fix(1929): more type-gating ([#3256](https://github.com/nf-core/tools/pull/3256))

## [v3.0.2 - Titanium Tapir Patch](https://github.com/nf-core/tools/releases/tag/3.0.2) - [2024-10-11]

Expand Down
4 changes: 4 additions & 0 deletions nf_core/components/lint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ def _set_registry(self, registry) -> None:
self.registry = registry
log.debug(f"Registry set to {self.registry}")

@property
def local_module_exclude_tests(self):
return ["module_version", "module_changes", "modules_patch"]

@staticmethod
def get_all_module_lint_tests(is_pipeline):
if is_pipeline:
Expand Down
18 changes: 18 additions & 0 deletions nf_core/modules/lint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,31 @@ def lint_module(
# TODO: consider unifying modules and subworkflows lint_module() function and add it to the ComponentLint class
# Only check the main script in case of a local module
if local:
mod.get_inputs_from_main_nf()
mod.get_outputs_from_main_nf()
# Update meta.yml file if requested
if self.fix and mod.meta_yml is not None:
self.update_meta_yml_file(mod)

for test_name in self.lint_tests:
if test_name in self.local_module_exclude_tests:
continue
if test_name == "main_nf":
getattr(self, test_name)(mod, fix_version, self.registry, progress_bar)
elif test_name in ["meta_yml", "environment_yml"]:
# Allow files to be missing for local
getattr(self, test_name)(mod, allow_missing=True)
"""
self.main_nf(mod, fix_version, self.registry, progress_bar)
"""

self.passed += [LintResult(mod, *m) for m in mod.passed]
warned = [LintResult(mod, *m) for m in (mod.warned + mod.failed)]
if not self.fail_warned:
self.warned += warned
else:
self.failed += warned
self.failed += [LintResult(mod, *m) for m in mod.failed]

# Otherwise run all the lint tests
else:
Expand Down
11 changes: 10 additions & 1 deletion nf_core/modules/lint/environment_yml.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
log = logging.getLogger(__name__)


def environment_yml(module_lint_object: ComponentLint, module: NFCoreComponent) -> None:
def environment_yml(module_lint_object: ComponentLint, module: NFCoreComponent, allow_missing: bool = False) -> None:
"""
Lint an ``environment.yml`` file.
Expand All @@ -23,6 +23,15 @@ def environment_yml(module_lint_object: ComponentLint, module: NFCoreComponent)
env_yml = None
# load the environment.yml file
if module.environment_yml is None:
if allow_missing:
module.warned.append(
(
"environment_yml_exists",
"Module's `environment.yml` does not exist",
Path(module.component_dir, "environment.yml"),
),
)
return
raise LintExceptionError("Module does not have an `environment.yml` file")
try:
with open(module.environment_yml) as fh:
Expand Down
12 changes: 8 additions & 4 deletions nf_core/modules/lint/meta_yml.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
log = logging.getLogger(__name__)


def meta_yml(module_lint_object: ComponentLint, module: NFCoreComponent) -> None:
def meta_yml(module_lint_object: ComponentLint, module: NFCoreComponent, allow_missing: bool = False) -> None:
"""
Lint a ``meta.yml`` file
Expand Down Expand Up @@ -42,7 +42,13 @@ def meta_yml(module_lint_object: ComponentLint, module: NFCoreComponent) -> None
module (NFCoreComponent): The module to lint
"""

if module.meta_yml is None:
if allow_missing:
module.warned.append(
("meta_yml_exists", "Module `meta.yml` does not exist", Path(module.component_dir, "meta.yml"))
)
return
raise LintExceptionError("Module does not have a `meta.yml` file")
# Check if we have a patch file, get original file in that case
meta_yaml = read_meta_yml(module_lint_object, module)
if module.is_patched and module_lint_object.modules_repo.repo_path is not None:
Expand All @@ -56,8 +62,6 @@ def meta_yml(module_lint_object: ComponentLint, module: NFCoreComponent) -> None
if lines is not None:
yaml = ruamel.yaml.YAML()
meta_yaml = yaml.safe_load("".join(lines))
if module.meta_yml is None:
raise LintExceptionError("Module does not have a `meta.yml` file")
if meta_yaml is None:
module.failed.append(("meta_yml_exists", "Module `meta.yml` does not exist", module.meta_yml))
return
Expand Down
29 changes: 26 additions & 3 deletions nf_core/modules/lint/module_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,44 @@

import yaml

from nf_core.components.lint import LintExceptionError
from nf_core.components.nfcore_component import NFCoreComponent

log = logging.getLogger(__name__)


def module_tests(_, module: NFCoreComponent):
def module_tests(_, module: NFCoreComponent, allow_missing: bool = False):
"""
Lint the tests of a module in ``nf-core/modules``
It verifies that the test directory exists
and contains a ``main.nf.test`` and a ``main.nf.test.snap``
"""
if module.nftest_testdir is None or module.nftest_main_nf is None:
raise ValueError()
if module.nftest_testdir is None:
if allow_missing:
module.warned.append(
(
"test_dir_exists",
"nf-test directory is missing",
Path(module.component_dir, "tests"),
)
)
return
raise LintExceptionError("Module does not have a `tests` dir")

if module.nftest_main_nf is None:
if allow_missing:
module.warned.append(
(
"test_main_nf_exists",
"test `main.nf.test` does not exist",
Path(module.component_dir, "tests", "main.nf.test"),
)
)
return
raise LintExceptionError("Module does not have a `tests` dir")

repo_dir = module.component_dir.parts[: module.component_dir.parts.index(module.component_name.split("/")[0])][-1]
test_dir = Path(module.base_dir, "tests", "modules", repo_dir, module.component_name)
pytest_main_nf = Path(test_dir, "main.nf")
Expand Down

0 comments on commit 31cffdd

Please sign in to comment.