8000 linting: respect `skip_features` for `files_unchanged` tests by mashehu · Pull Request #4596 · nf-core/tools · GitHub
[go: up one dir, main page]

Skip to content
Merged
8000
Show file tree
Hide file tree
Changes from all 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 @@ -9,6 +9,7 @@
### Linting

- make pipelines linting, including ro-create also work offline ([#4585](https://github.com/nf-core/tools/pull/4585))
- respect `skip_features` for `files_unchanged` tests ([#4596](https://github.com/nf-core/tools/pull/4596))

### Modules

Expand Down
4 changes: 3 additions & 1 deletion nf_core/pipelines/lint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from nf_core import __version__
from nf_core.components.lint import ComponentLint
from nf_core.pipelines.lint_utils import console
from nf_core.utils import NFCoreYamlLintConfig, strip_ansi_codes
from nf_core.utils import NFCoreTemplateConfig, NFCoreYamlLintConfig, strip_ansi_codes
from nf_core.utils import plural_s as _s

from .actions_awsfulltest import actions_awsfulltest
Expand Down Expand Up @@ -123,6 +123,7 @@ def __init__(
super().__init__(wf_path)

self.lint_config: NFCoreYamlLintConfig | None = None
self.template_config: NFCoreTemplateConfig | None = None
self.release_mode = release_mode
self.fail_ignored = fail_ignored
self.fail_warned = fail_warned
Expand Down Expand Up @@ -189,6 +190,7 @@ def _load_lint_config(self) -> bool:
"""
_, tools_config = nf_core.utils.load_tools_config(self.wf_path)
self.lint_config = getattr(tools_config, "lint", None) or None
self.template_config = getattr(tools_config, "template", None)
is_correct = True
# Check if we have any keys that don't match lint test names
if self.lint_config is not None:
Expand Down
3 changes: 3 additions & 0 deletions nf_core/pipelines/lint/files_unchanged.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,14 @@ def files_unchanged(self) -> dict[str, list[str] | bool]:
names = ", ".join(c.get("name", "") for c in contributors if c.get("name"))
else:
names = manifest_config.get("author", "")
# Render the comparison with the pipeline's skipped features, so feature-dependent template content matches
skip_features = self.template_config.skip_features if self.template_config else None
template_yaml = {
"name": short_name,
"description": manifest_config.get("description", ""),
"author": names,
"org": prefix,
"skip_features": skip_features or [],
}

template_yaml_path = Path(tmp_dir, "template.yaml")
Expand Down
18 changes: 18 additions & 0 deletions tests/pipelines/lint/test_files_unchanged.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from pathlib import Path
from unittest import mock

import yaml

import nf_core.pipelines.lint

from ..test_lint import TestLint
Expand Down Expand Up @@ -30,3 +32,19 @@ def test_files_unchanged_fail(self):
assert len(results["failed"]) > 0
assert str(failing_file) in results["failed"][0]
assert results["could_fix"]

def test_files_unchanged_respects_skip_features(self):
"""The comparison copy is rendered with the pipeline's skip_features"""
new_pipeline = self._make_pipeline_copy()
config_fn = Path(new_pipeline, ".nf-core.yml")
config = yaml.safe_load(config_fn.read_text())
config["template"]["skip_features"] = ["rocrate"]
config_fn.write_text(yaml.safe_dump(config))
# Without rocrate, the template's .prettierignore has no ro-crate entry
prettierignore = Path(new_pipeline, ".prettierignore")
prettierignore.write_text(prettierignore.read_text().replace("ro-crate-metadata.json\n", ""))

lint_obj = nf_core.pipelines.lint.PipelineLint(new_pipeline)
lint_obj._load()
results = lint_obj.files_unchanged()
assert len(results.get("failed", [])) == 0
Loading
0