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

Fix linting fail on nfcore_external_java_deps if nf_schema is used #2976

Merged
merged 6 commits into from
May 13, 2024
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

### Linting

- Fix linting fail on nfcore_external_java_deps if nf_schema is used ([#2976](https://github.com/nf-core/tools/pull/2976))

### Download

### Components
Expand Down
13 changes: 7 additions & 6 deletions nf_core/lint/files_exist.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ def files_exist(self) -> Dict[str, Union[List[str], bool]]:
Path("Singularity"),
]
files_warn_ifexists = [Path(".travis.yml")]
files_fail_ifinconfig: List[Tuple[Path, Dict[str, str]]] = [
(Path("lib", "nfcore_external_java_deps.jar"), {"plugins": "nf-validation"}),
files_fail_ifinconfig: List[Tuple[Path, List[Dict[str, str]]]] = [
(Path("lib", "nfcore_external_java_deps.jar"), [{"plugins": "nf-validation"}, {"plugins": "nf-schema"}]),
]

# Remove files that should be ignored according to the linting config
Expand Down Expand Up @@ -246,10 +246,11 @@ def pf(file_path: Union[str, Path]) -> Path:
if str(file_cond[0]) in ignore_files:
continue
in_config = False
config_key, config_value = list(file_cond[1].items())[0]
if config_key in self.nf_config and config_value in self.nf_config[config_key]:
log.debug(f"Found {config_key} in nextflow.config with value {config_value}")
in_config = True
for condition in file_cond[1]:
config_key, config_value = list(condition.items())[0]
if config_key in self.nf_config and config_value in self.nf_config[config_key]:
log.debug(f"Found {config_key} in nextflow.config with value {config_value}")
in_config = True
if pf(file_cond[0]).is_file() and in_config:
failed.append(f"File must be removed: {self._wrap_quotes(file_cond[0])}")
elif pf(file_cond[0]).is_file() and not in_config:
Expand Down
17 changes: 17 additions & 0 deletions tests/lint/files_exist.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,20 @@ def test_files_exist_fail_conditional(self):
results = lint_obj.files_exist()
assert results["failed"] == ["File must be removed: `lib/nfcore_external_java_deps.jar`"]
assert results["ignored"] == []


def test_files_exist_pass_conditional_nfschema(self):
new_pipeline = self._make_pipeline_copy()
# replace nf-validation with nf-schema in nextflow.config
with open(Path(new_pipeline, "nextflow.config")) as f:
config = f.read()
config = config.replace("nf-validation", "nf-schema")
with open(Path(new_pipeline, "nextflow.config"), "w") as f:
f.write(config)

lint_obj = nf_core.lint.PipelineLint(new_pipeline)
lint_obj._load()
lint_obj.nf_config["manifest.schema"] = "nf-core"
results = lint_obj.files_exist()
assert results["failed"] == []
assert results["ignored"] == []
1 change: 1 addition & 0 deletions tests/test_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ def test_sphinx_md_files(self):
test_files_exist_missing_main,
test_files_exist_pass,
test_files_exist_pass_conditional,
test_files_exist_pass_conditional_nfschema,
)
from .lint.files_unchanged import ( # type: ignore[misc]
test_files_unchanged_fail,
Expand Down
Loading