From bf7ec67bbc7465525c4f502c31b9c0c2a73676d6 Mon Sep 17 00:00:00 2001 From: kevinmenden Date: Mon, 3 May 2021 13:33:54 +0200 Subject: [PATCH 1/6] added check for parameter description --- nf_core/lint/__init__.py | 2 ++ nf_core/lint/schema_description.py | 41 ++++++++++++++++++++++++++++++ nf_core/lint/schema_params.py | 3 ++- 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 nf_core/lint/schema_description.py diff --git a/nf_core/lint/__init__.py b/nf_core/lint/__init__.py index 82c4d57ddd..b553cf5b7a 100644 --- a/nf_core/lint/__init__.py +++ b/nf_core/lint/__init__.py @@ -113,6 +113,7 @@ class PipelineLint(nf_core.utils.Pipeline): from .readme import readme from .schema_lint import schema_lint from .schema_params import schema_params + from .schema_description import schema_description from .template_strings import template_strings from .version_consistency import version_consistency @@ -147,6 +148,7 @@ def __init__(self, wf_path, release_mode=False, fix=(), key=(), fail_ignored=Fal "template_strings", "schema_lint", "schema_params", + "schema_description", "actions_schema_validation", "merge_markers", ] diff --git a/nf_core/lint/schema_description.py b/nf_core/lint/schema_description.py new file mode 100644 index 0000000000..b46cfeec70 --- /dev/null +++ b/nf_core/lint/schema_description.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python + +from logging import warn +import nf_core.schema + + +def schema_description(self): + """Check that the schema describes all flat params in the pipeline. + + The ``nextflow_schema.json`` pipeline schema should describe every flat parameter + returned from the ``nextflow config`` command (params that are objects or more complex structures are ignored). + + * Failure: If parameters are found in ``nextflow_schema.json`` that are not in ``nextflow_schema.json`` + * Warning: If parameters are found in ``nextflow_schema.json`` that are not in ``nextflow_schema.json`` + """ + passed = [] + warned = [] + failed = [] + + # First, get the top-level config options for the pipeline + # Schema object already created in the `schema_lint` test + self.schema_obj = nf_core.schema.PipelineSchema() + self.schema_obj.get_schema_path(self.wf_path) + self.schema_obj.get_wf_params() + self.schema_obj.no_prompts = True + self.schema_obj.load_lint_schema() + + # Get ungrouped params + ungrouped_params = self.schema_obj.schema["properties"].keys() + for up in ungrouped_params: + warned.append(f"Ungrouped param in schema {up}") + + # Iterate over groups and add warning for parameters without a description + for group_key in self.schema_obj.schema["definitions"].keys(): + group = self.schema_obj.schema["definitions"][group_key] + for param_key in group["properties"].keys(): + param = group["properties"][param_key] + if not "description" in param.keys(): + warned.append(f"No description provided in schema for parameter '{param_key}'") + + return {"passed": passed, "warned": warned, "failed": failed} diff --git a/nf_core/lint/schema_params.py b/nf_core/lint/schema_params.py index 580e9129d8..20c962c226 100644 --- a/nf_core/lint/schema_params.py +++ b/nf_core/lint/schema_params.py @@ -17,10 +17,11 @@ def schema_params(self): failed = [] # First, get the top-level config options for the pipeline - # Schema object already created in the `schema_lint` test + self.schema_obj = nf_core.schema.PipelineSchema() self.schema_obj.get_schema_path(self.wf_path) self.schema_obj.get_wf_params() self.schema_obj.no_prompts = True + self.schema_obj.load_lint_schema() # Remove any schema params not found in the config removed_params = self.schema_obj.remove_schema_notfound_configs() From 74b8f10baf610899bd52b7a5ee46e9500b2e1917 Mon Sep 17 00:00:00 2001 From: kevinmenden Date: Mon, 3 May 2021 13:37:27 +0200 Subject: [PATCH 2/6] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ada9702873..6635774a02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ * Ignore permission errors for setting up requests cache directories to allow starting with an invalid or read-only HOME directory * New lint test to check if params in `nextflow config` are mentioned in `main.nf` [[#1038](https://github.com/nf-core/tools/issues/1038)] * New modules lint test comparing the `functions.nf` file to the template version +* Added lint checks for missing parameter description and parameters outside of groups [[#1017](https://github.com/nf-core/tools/issues/1017)] ### Template From 4ed2c31b12e7ec2dd317c54ed66a20c29a76b6ce Mon Sep 17 00:00:00 2001 From: kevinmenden Date: Mon, 3 May 2021 14:31:09 +0200 Subject: [PATCH 3/6] fixed missing things/tests --- .../pipeline_lint_tests/schema_description.rst | 4 ++++ nf_core/lint/schema_description.py | 15 ++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) create mode 100644 docs/api/_src/pipeline_lint_tests/schema_description.rst diff --git a/docs/api/_src/pipeline_lint_tests/schema_description.rst b/docs/api/_src/pipeline_lint_tests/schema_description.rst new file mode 100644 index 0000000000..8733e203e5 --- /dev/null +++ b/docs/api/_src/pipeline_lint_tests/schema_description.rst @@ -0,0 +1,4 @@ +schema_description +=========== + +.. automethod:: nf_core.lint.PipelineLint.schema_description diff --git a/nf_core/lint/schema_description.py b/nf_core/lint/schema_description.py index b46cfeec70..19b4a1b242 100644 --- a/nf_core/lint/schema_description.py +++ b/nf_core/lint/schema_description.py @@ -5,13 +5,13 @@ def schema_description(self): - """Check that the schema describes all flat params in the pipeline. + """Check that every parameter in the schema has a description The ``nextflow_schema.json`` pipeline schema should describe every flat parameter - returned from the ``nextflow config`` command (params that are objects or more complex structures are ignored). + Furthermore warns about parameters outside of groups - * Failure: If parameters are found in ``nextflow_schema.json`` that are not in ``nextflow_schema.json`` - * Warning: If parameters are found in ``nextflow_schema.json`` that are not in ``nextflow_schema.json`` + * Warning: Parameters in ``nextflow_schema.json`` without a description + * Warning: Parameters in ``nextflow_schema.json`` that are defined outside of a group """ passed = [] warned = [] @@ -26,9 +26,10 @@ def schema_description(self): self.schema_obj.load_lint_schema() # Get ungrouped params - ungrouped_params = self.schema_obj.schema["properties"].keys() - for up in ungrouped_params: - warned.append(f"Ungrouped param in schema {up}") + if "properties" in self.schema_obj.schema.keys(): + ungrouped_params = self.schema_obj.schema["properties"].keys() + for up in ungrouped_params: + warned.append(f"Ungrouped param in schema {up}") # Iterate over groups and add warning for parameters without a description for group_key in self.schema_obj.schema["definitions"].keys(): From 5178790a6017b932b3babb1a0c616a0b31213f12 Mon Sep 17 00:00:00 2001 From: Kevin Menden Date: Tue, 4 May 2021 08:19:59 +0200 Subject: [PATCH 4/6] Apply suggestions from code review Co-authored-by: Phil Ewels --- nf_core/lint/schema_description.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/nf_core/lint/schema_description.py b/nf_core/lint/schema_description.py index 19b4a1b242..0e517e5c71 100644 --- a/nf_core/lint/schema_description.py +++ b/nf_core/lint/schema_description.py @@ -29,14 +29,13 @@ def schema_description(self): if "properties" in self.schema_obj.schema.keys(): ungrouped_params = self.schema_obj.schema["properties"].keys() for up in ungrouped_params: - warned.append(f"Ungrouped param in schema {up}") + warned.append(f"Ungrouped param in schema: `{up}`") # Iterate over groups and add warning for parameters without a description for group_key in self.schema_obj.schema["definitions"].keys(): group = self.schema_obj.schema["definitions"][group_key] - for param_key in group["properties"].keys(): - param = group["properties"][param_key] - if not "description" in param.keys(): - warned.append(f"No description provided in schema for parameter '{param_key}'") + for param_key, param in group["properties"].items(): + if "description" not in param.keys(): + warned.append(f"No description provided in schema for parameter: `{param_key}`") return {"passed": passed, "warned": warned, "failed": failed} From 2dff23ba19deb7407740843e028da0869ae07888 Mon Sep 17 00:00:00 2001 From: kevinmenden Date: Tue, 4 May 2021 09:05:13 +0200 Subject: [PATCH 5/6] add support for ignoring params --- nf_core/lint/schema_description.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/nf_core/lint/schema_description.py b/nf_core/lint/schema_description.py index 0e517e5c71..429a77a0c9 100644 --- a/nf_core/lint/schema_description.py +++ b/nf_core/lint/schema_description.py @@ -16,6 +16,7 @@ def schema_description(self): passed = [] warned = [] failed = [] + ignored = [] # First, get the top-level config options for the pipeline # Schema object already created in the `schema_lint` test @@ -25,17 +26,27 @@ def schema_description(self): self.schema_obj.no_prompts = True self.schema_obj.load_lint_schema() + # Get parameters that should be ignored according to the linting config + ignore_params = self.lint_config.get("schema_description", []) + # Get ungrouped params if "properties" in self.schema_obj.schema.keys(): ungrouped_params = self.schema_obj.schema["properties"].keys() for up in ungrouped_params: + if up in ignore_params: + continue warned.append(f"Ungrouped param in schema: `{up}`") # Iterate over groups and add warning for parameters without a description for group_key in self.schema_obj.schema["definitions"].keys(): group = self.schema_obj.schema["definitions"][group_key] for param_key, param in group["properties"].items(): + if param_key in ignore_params: + continue if "description" not in param.keys(): warned.append(f"No description provided in schema for parameter: `{param_key}`") + for ip in ignore_params: + ignored.append(f"Parameter is ignored: `{ip}`") + return {"passed": passed, "warned": warned, "failed": failed} From 4f75b6a9e669ad3625ce51120205628447037883 Mon Sep 17 00:00:00 2001 From: Kevin Menden Date: Wed, 5 May 2021 13:55:20 +0200 Subject: [PATCH 6/6] Apply suggestions from code review Co-authored-by: Phil Ewels --- nf_core/lint/schema_description.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/nf_core/lint/schema_description.py b/nf_core/lint/schema_description.py index 429a77a0c9..f1377053e2 100644 --- a/nf_core/lint/schema_description.py +++ b/nf_core/lint/schema_description.py @@ -15,7 +15,6 @@ def schema_description(self): """ passed = [] warned = [] - failed = [] ignored = [] # First, get the top-level config options for the pipeline @@ -34,14 +33,16 @@ def schema_description(self): ungrouped_params = self.schema_obj.schema["properties"].keys() for up in ungrouped_params: if up in ignore_params: - continue - warned.append(f"Ungrouped param in schema: `{up}`") + ignored.append(f"Ignored ungrouped param in schema: `{up}`") + else: + warned.append(f"Ungrouped param in schema: `{up}`") # Iterate over groups and add warning for parameters without a description for group_key in self.schema_obj.schema["definitions"].keys(): group = self.schema_obj.schema["definitions"][group_key] for param_key, param in group["properties"].items(): if param_key in ignore_params: + ignored.append(f"Ignoring description check for param in schema: `{param_key}`") continue if "description" not in param.keys(): warned.append(f"No description provided in schema for parameter: `{param_key}`") @@ -49,4 +50,4 @@ def schema_description(self): for ip in ignore_params: ignored.append(f"Parameter is ignored: `{ip}`") - return {"passed": passed, "warned": warned, "failed": failed} + return {"passed": passed, "warned": warned, "ignored": ignored}