|
1 | 1 | import logging
|
2 | 2 | from pathlib import Path
|
3 |
| -from typing import Union |
| 3 | +from typing import Dict, List, Tuple, Union |
| 4 | + |
| 5 | +from nf_core.lint import PipelineLint |
4 | 6 |
|
5 | 7 | log = logging.getLogger(__name__)
|
6 | 8 |
|
7 | 9 |
|
8 |
| -def files_exist(self): |
| 10 | +def files_exist(self: PipelineLint) -> dict[str, Union[List[str], bool]]: |
9 | 11 | """Checks a given pipeline directory for required files.
|
10 | 12 |
|
11 | 13 | Iterates through the pipeline's directory content and checks that specified
|
@@ -129,19 +131,19 @@ def files_exist(self):
|
129 | 131 | short_name = self.nf_config["manifest.name"].strip("\"'").split("/")
|
130 | 132 |
|
131 | 133 | files_fail = [
|
132 |
| - [".gitattributes"], |
133 |
| - [".gitignore"], |
134 |
| - [".nf-core.yml"], |
135 |
| - [".editorconfig"], |
136 |
| - [".prettierignore"], |
137 |
| - [".prettierrc.yml"], |
138 |
| - ["CHANGELOG.md"], |
139 |
| - ["CITATIONS.md"], |
140 |
| - ["CODE_OF_CONDUCT.md"], |
141 |
| - ["LICENSE", "LICENSE.md", "LICENCE", "LICENCE.md"], # NB: British / American spelling |
142 |
| - ["nextflow_schema.json"], |
143 |
| - ["nextflow.config"], |
144 |
| - ["README.md"], |
| 134 | + [Path(".gitattributes")], |
| 135 | + [Path(".gitignore")], |
| 136 | + [Path(".nf-core.yml")], |
| 137 | + [Path(".editorconfig")], |
| 138 | + [Path(".prettierignore")], |
| 139 | + [Path(".prettierrc.yml")], |
| 140 | + [Path("CHANGELOG.md")], |
| 141 | + [Path("CITATIONS.md")], |
| 142 | + [Path("CODE_OF_CONDUCT.md")], |
| 143 | + [Path("LICENSE", "LICENSE.md", "LICENCE", "LICENCE.md")], # NB: British / American spelling |
| 144 | + [Path("nextflow_schema.json")], |
| 145 | + [Path("nextflow.config")], |
| 146 | + [Path("README.md")], |
145 | 147 | [Path(".github", ".dockstore.yml")],
|
146 | 148 | [Path(".github", "CONTRIBUTING.md")],
|
147 | 149 | [Path(".github", "ISSUE_TEMPLATE", "bug_report.yml")],
|
@@ -171,37 +173,39 @@ def files_exist(self):
|
171 | 173 | ]
|
172 | 174 |
|
173 | 175 | files_warn = [
|
174 |
| - ["main.nf"], |
| 176 | + [Path("main.nf")], |
175 | 177 | [Path("assets", "multiqc_config.yml")],
|
176 | 178 | [Path("conf", "base.config")],
|
177 | 179 | [Path("conf", "igenomes.config")],
|
178 | 180 | [Path(".github", "workflows", "awstest.yml")],
|
179 | 181 | [Path(".github", "workflows", "awsfulltest.yml")],
|
180 | 182 | [Path("lib", f"Workflow{short_name[0].upper()}{short_name[1:]}.groovy")],
|
181 |
| - ["modules.json"], |
182 |
| - ["pyproject.toml"], |
| 183 | + [Path("modules.json")], |
| 184 | + [Path("pyproject.toml")], |
183 | 185 | ]
|
184 | 186 |
|
185 | 187 | # List of strings. Fails / warns if any of the strings exist.
|
186 | 188 | files_fail_ifexists = [
|
187 |
| - "Singularity", |
188 |
| - "parameters.settings.json", |
189 |
| - "pipeline_template.yml", # saving information in .nf-core.yml |
190 |
| - ".nf-core.yaml", # yml not yaml |
| 189 | + Path("Singularity"), |
| 190 | + Path("parameters.settings.json"), |
| 191 | + Path("pipeline_template.yml"), # saving information in .nf-core.yml |
| 192 | + Path(".nf-core.yaml"), # yml not yaml |
191 | 193 | Path("bin", "markdown_to_html.r"),
|
192 | 194 | Path("conf", "aws.config"),
|
193 | 195 | Path(".github", "workflows", "push_dockerhub.yml"),
|
194 | 196 | Path(".github", "ISSUE_TEMPLATE", "bug_report.md"),
|
195 | 197 | Path(".github", "ISSUE_TEMPLATE", "feature_request.md"),
|
196 | 198 | Path("docs", "images", f"nf-core-{short_name}_logo.png"),
|
197 |
| - ".markdownlint.yml", |
198 |
| - ".yamllint.yml", |
| 199 | + Path(".markdownlint.yml"), |
| 200 | + Path(".yamllint.yml"), |
199 | 201 | Path("lib", "Checks.groovy"),
|
200 | 202 | Path("lib", "Completion.groovy"),
|
201 | 203 | Path("lib", "Workflow.groovy"),
|
202 | 204 | ]
|
203 |
| - files_warn_ifexists = [".travis.yml"] |
204 |
| - files_fail_ifinconfig = [[Path("lib", "nfcore_external_java_deps.jar"), "nf-validation"]] |
| 205 | + files_warn_ifexists = [Path(".travis.yml")] |
| 206 | + files_fail_ifinconfig: List[Tuple[Path, Dict[str, str]]] = [ |
| 207 | + (Path("lib", "nfcore_external_java_deps.jar"), {"plugins": "nf_validation"}), |
| 208 | + ] |
205 | 209 |
|
206 | 210 | # Remove files that should be ignored according to the linting config
|
207 | 211 | ignore_files = self.lint_config.get("files_exist", [])
|
@@ -242,22 +246,21 @@ def pf(file_path: Union[str, Path]) -> Path:
|
242 | 246 | else:
|
243 | 247 | passed.append(f"File not found check: {self._wrap_quotes(file)}")
|
244 | 248 | # Files that cause an error if they exists together with a certain entry in nextflow.config
|
245 |
| - for file in files_fail_ifinconfig: |
246 |
| - if str(file[0]) in ignore_files: |
| 249 | + for file_cond in files_fail_ifinconfig: |
| 250 | + if str(file_cond[0]) in ignore_files: |
247 | 251 | continue
|
248 |
| - nextflow_config = pf("nextflow.config") |
249 | 252 | in_config = False
|
250 |
| - with open(nextflow_config) as f: |
251 |
| - if file[1] in f.read(): |
252 |
| - in_config = True |
253 |
| - if pf(file[0]).is_file() and in_config: |
254 |
| - failed.append(f"File must be removed: {self._wrap_quotes(file[0])}") |
255 |
| - elif pf(file[0]).is_file() and not in_config: |
256 |
| - passed.append(f"File found check: {self._wrap_quotes(file[0])}") |
257 |
| - elif not pf(file[0]).is_file() and not in_config: |
258 |
| - failed.append(f"File not found check: {self._wrap_quotes(file[0])}") |
259 |
| - elif not pf(file[0]).is_file() and in_config: |
260 |
| - passed.append(f"File not found check: {self._wrap_quotes(file[0])}") |
| 253 | + config_key, config_value = list(file_cond[1].items())[0] |
| 254 | + if config_key in self.nf_config and self.nf_config[config_key] == config_value: |
| 255 | + in_config = True |
| 256 | + if pf(file_cond[0]).is_file() and in_config: |
| 257 | + failed.append(f"File must be removed: {self._wrap_quotes(file_cond[0])}") |
| 258 | + elif pf(file_cond[0]).is_file() and not in_config: |
| 259 | + passed.append(f"File found check: {self._wrap_quotes(file_cond[0])}") |
| 260 | + elif not pf(file_cond[0]).is_file() and not in_config: |
| 261 | + failed.append(f"File not found check: {self._wrap_quotes(file_cond[0])}") |
| 262 | + elif not pf(file_cond[0]).is_file() and in_config: |
| 263 | + passed.append(f"File not found check: {self._wrap_quotes(file_cond[0])}") |
261 | 264 | # Files that cause a warning if they exist
|
262 | 265 | for file in files_warn_ifexists:
|
263 | 266 | if file in ignore_files:
|
|
0 commit comments