Skip to content

Commit

Permalink
Merge pull request #1676 from ErikDanielsson/lint-for-mimetype
Browse files Browse the repository at this point in the history
Add lint for input mimetype
  • Loading branch information
ErikDanielsson authored Jul 19, 2022
2 parents f59e600 + adc4df6 commit cc1ab61
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- Update `readme.py` nf version badge validation regexp to accept any signs before version number ([#1613](https://github.com/nf-core/tools/issues/1613))
- Add isort configuration and GitHub workflow ([#1538](https://github.com/nf-core/tools/pull/1538))
- Use black also to format python files in workflows ([#1563](https://github.com/nf-core/tools/pull/1563))
- Add check for mimetype in the `input` parameter. ([#1647](https://github.com/nf-core/tools/issues/1647))

### General

Expand Down
12 changes: 12 additions & 0 deletions nf_core/lint/schema_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def schema_lint(self):
* ``$id``: URL to the raw schema file, eg. ``https://raw.githubusercontent.com/YOURPIPELINE/master/nextflow_schema.json``
* ``title``: ``YOURPIPELINE pipeline parameters``
* ``description``: The pipeline config ``manifest.description``
* That the ``input`` property is defined and has a mimetype. A list of common mimetypes can be found `here <https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types>`_.
For example, an *extremely* minimal schema could look like this:
Expand Down Expand Up @@ -88,4 +89,15 @@ def schema_lint(self):
except AssertionError as e:
warned.append(str(e))

# Check for mimetype in the 'input' parameter, warn if missing
if self.schema_obj.schema is not None:
try:
has_valid_mimetype = self.schema_obj.check_for_input_mimetype()
if has_valid_mimetype is not None:
passed.append(f"Input mimetype lint passed: '{has_valid_mimetype}'")
else:
warned.append("Input mimetype is missing or empty")
except LookupError as e:
warned.append(str(e))

return {"passed": passed, "warned": warned, "failed": failed}
27 changes: 27 additions & 0 deletions nf_core/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,33 @@ def validate_schema_title_description(self, schema=None):
self.schema["description"] == desc_attr
), f"Schema 'description' should be '{desc_attr}'\n Found: '{self.schema['description']}'"

def check_for_input_mimetype(self):
"""
Check that the input parameter has a mimetype
Common mime types: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
Returns:
mimetype (str): The mimetype of the input parameter
Raises:
LookupError: If the input parameter is not found or defined in the correct place
"""

# Check that the input parameter is defined
if "input" not in self.schema_params:
raise LookupError(f"Parameter `input` not found in schema")
# Check that the input parameter is defined in the right place
if "input" not in self.schema.get("definitions", {}).get("input_output_options", {}).get("properties", {}):
raise LookupError(f"Parameter `input` is not defined in the correct subschema (input_output_options)")
input_entry = self.schema["definitions"]["input_output_options"]["properties"]["input"]
if "mimetype" not in input_entry:
return None
mimetype = input_entry["mimetype"]
if mimetype == "" or mimetype is None:
return None
return mimetype

def print_documentation(
self,
output_fn=None,
Expand Down

0 comments on commit cc1ab61

Please sign in to comment.