Skip to content

Commit

Permalink
Merge pull request nf-core#2976 from itrujnara/fix_deps_lint_nf_schema
Browse files Browse the repository at this point in the history
Fix linting fail on nfcore_external_java_deps if nf_schema is used
  • Loading branch information
itrujnara authored May 13, 2024
2 parents 1ae28bc + c3e2844 commit a157cb1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
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

0 comments on commit a157cb1

Please sign in to comment.