Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
5 changes: 5 additions & 0 deletions nf_core/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,11 @@ def lint(schema_path):
try:
schema_obj.get_schema_path(schema_path)
schema_obj.load_lint_schema()
# Validate title and description - just warnings as schema should still work fine
try:
schema_obj.validate_schema_title_description()
except AssertionError as e:
log.warn(e)
except AssertionError as e:
sys.exit(1)

Expand Down
8 changes: 8 additions & 0 deletions nf_core/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -1237,6 +1237,14 @@ def check_schema_lint(self):
except AssertionError as e:
self.failed.append((14, "Schema lint failed: {}".format(e)))

# Check the title and description - gives warnings instead of fail
if self.schema_obj.schema is not None:
try:
self.schema_obj.validate_schema_title_description()
self.passed.append((14, "Schema title + description lint passed"))
except AssertionError as e:
self.warned.append((14, e))

def check_schema_params(self):
""" Check that the schema describes all flat params in the pipeline """

Expand Down
23 changes: 10 additions & 13 deletions nf_core/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,11 @@ def validate_schema(self, schema=None):
for allOf in schema["allOf"]:
if allOf["$ref"] == "#/definitions/{}".format(d_key):
in_allOf = True
assert in_allOf, "Definition subschema '{}' not included in schema 'allOf'".format(d_key)
assert in_allOf, "Definition subschema `{}` not included in schema `allOf`".format(d_key)

for d_param_id in d_schema.get("properties", {}):
# Check that we don't have any duplicate parameter IDs in different definitions
assert d_param_id not in param_keys, "Duplicate parameter found in schema 'definitions': '{}'".format(
assert d_param_id not in param_keys, "Duplicate parameter found in schema `definitions`: `{}`".format(
d_param_id
)
param_keys.append(d_param_id)
Expand All @@ -204,16 +204,13 @@ def validate_schema(self, schema=None):
for allOf in schema.get("allOf", []):
assert "definitions" in schema, "Schema has allOf, but no definitions"
def_key = allOf["$ref"][14:]
assert def_key in schema["definitions"], "Subschema '{}' found in 'allOf' but not 'definitions'".format(
assert def_key in schema["definitions"], "Subschema `{}` found in `allOf` but not `definitions`".format(
def_key
)

# Check that the schema describes at least one parameter
assert num_params > 0, "No parameters found in schema"

# Validate title and description
self.validate_schema_title_description(schema)

return num_params

def validate_schema_title_description(self, schema=None):
Expand All @@ -227,30 +224,30 @@ def validate_schema_title_description(self, schema=None):
log.debug("Pipeline schema not set - skipping validation of top-level attributes")
return None

assert "$schema" in self.schema, "Schema missing top-level '$schema' attribute"
assert "$schema" in self.schema, "Schema missing top-level `$schema` attribute"
schema_attr = "https://json-schema.org/draft-07/schema"
assert self.schema["$schema"] == schema_attr, "Schema '$schema' should be '{}'\n Found '{}'".format(
assert self.schema["$schema"] == schema_attr, "Schema `$schema` should be `{}`\n Found `{}`".format(
schema_attr, self.schema["$schema"]
)

if self.pipeline_manifest == {}:
self.get_wf_params()

if "name" not in self.pipeline_manifest:
log.debug("Pipeline manifest 'name' not known - skipping validation of schema id and title")
log.debug("Pipeline manifest `name` not known - skipping validation of schema id and title")
else:
assert "$id" in self.schema, "Schema missing top-level '$id' attribute"
assert "title" in self.schema, "Schema missing top-level 'title' attribute"
assert "$id" in self.schema, "Schema missing top-level `$id` attribute"
assert "title" in self.schema, "Schema missing top-level `title` attribute"
# Validate that id, title and description match the pipeline manifest
id_attr = "https://raw.githubusercontent.com/{}/master/nextflow_schema.json".format(
self.pipeline_manifest["name"].strip("\"'")
)
assert self.schema["$id"] == id_attr, "Schema '$id' should be '{}'\n Found '{}'".format(
assert self.schema["$id"] == id_attr, "Schema `$id` should be `{}`\n Found `{}`".format(
id_attr, self.schema["$id"]
)

title_attr = "{} pipeline parameters".format(self.pipeline_manifest["name"].strip("\"'"))
assert self.schema["title"] == title_attr, "Schema 'title' should be '{}'\n Found: '{}'".format(
assert self.schema["title"] == title_attr, "Schema `title` should be `{}`\n Found: `{}`".format(
title_attr, self.schema["title"]
)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def pf(wd, path):
]

# The maximum sum of passed tests currently possible
MAX_PASS_CHECKS = 83
MAX_PASS_CHECKS = 84
# The additional tests passed for releases
ADD_PASS_RELEASE = 1

Expand Down
6 changes: 3 additions & 3 deletions tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def test_validate_schema_fail_duplicate_ids(self):
self.schema_obj.validate_schema(self.schema_obj.schema)
raise UserWarning("Expected AssertionError")
except AssertionError as e:
assert e.args[0] == "Duplicate parameter found in schema 'definitions': 'foo'"
assert e.args[0] == "Duplicate parameter found in schema `definitions`: `foo`"

def test_validate_schema_fail_missing_def(self):
"""
Expand All @@ -175,7 +175,7 @@ def test_validate_schema_fail_missing_def(self):
self.schema_obj.validate_schema(self.schema_obj.schema)
raise UserWarning("Expected AssertionError")
except AssertionError as e:
assert e.args[0] == "Definition subschema 'groupTwo' not included in schema 'allOf'"
assert e.args[0] == "Definition subschema `groupTwo` not included in schema `allOf`"

def test_validate_schema_fail_unexpected_allof(self):
"""
Expand All @@ -193,7 +193,7 @@ def test_validate_schema_fail_unexpected_allof(self):
self.schema_obj.validate_schema(self.schema_obj.schema)
raise UserWarning("Expected AssertionError")
except AssertionError as e:
assert e.args[0] == "Subschema 'groupThree' found in 'allOf' but not 'definitions'"
assert e.args[0] == "Subschema `groupThree` found in `allOf` but not `definitions`"

def test_make_skeleton_schema(self):
""" Test making a new schema skeleton """
Expand Down