Skip to content

Commit

Permalink
add lxml based xml schema check
Browse files Browse the repository at this point in the history
and remove some linters that are obviously redundant with the schema
check
  • Loading branch information
bernt-matthias committed Dec 7, 2023
1 parent 6d5c1e7 commit 68a7a0a
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 144 deletions.
112 changes: 0 additions & 112 deletions lib/galaxy/tool_util/linters/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,6 @@

lint_tool_types = ["*"]

FILTER_TYPES = [
"data_meta",
"param_value",
"static_value",
"regexp",
"unique_value",
"multiple_splitter",
"attribute_value_splitter",
"add_value",
"remove_value",
"sort_by",
]

ATTRIB_VALIDATOR_COMPATIBILITY = {
"check": ["metadata"],
"expression": ["substitute_value_in_message"],
Expand Down Expand Up @@ -289,37 +276,6 @@ def lint(cls, tool_source: "ToolSource", lint_ctx: "LintContext"):
lint_ctx.warn(f"Param input [{param_name}] is not a valid Cheetah placeholder.", node=param)


# TODO xsd
class InputsType(Linter):
"""
Lint params define a type
"""

@classmethod
def lint(cls, tool_source: "ToolSource", lint_ctx: "LintContext"):
tool_xml = getattr(tool_source, "xml_tree", None)
if not tool_xml:
return
for param, param_name in _iter_param(tool_xml):
if "type" not in param.attrib:
lint_ctx.error(f"Param input [{param_name}] input with no type specified.", node=param)


class InputsTypeEmpty(Linter):
"""
Lint params define a type
"""

@classmethod
def lint(cls, tool_source: "ToolSource", lint_ctx: "LintContext"):
tool_xml = getattr(tool_source, "xml_tree", None)
if not tool_xml:
return
for param, param_name in _iter_param(tool_xml):
if "type" in param.attrib and param.attrib["type"] == "":
lint_ctx.error(f"Param input [{param_name}] with empty type specified.", node=param)


def _param_path(param: "Element", param_name: str) -> str:
path = [param_name]
parent = param
Expand Down Expand Up @@ -707,48 +663,6 @@ def lint(cls, tool_source: "ToolSource", lint_ctx: "LintContext"):
lint_ctx.error(f"Select parameter [{param_name}] contains multiple options elements.", node=options[1])


# TODO xsd
class InputsSelectOptionsFilterTypeMissing(Linter):
"""
Lint dynamic options select for filters wo type
"""

@classmethod
def lint(cls, tool_source: "ToolSource", lint_ctx: "LintContext"):
tool_xml = getattr(tool_source, "xml_tree", None)
if not tool_xml:
return
for param, param_name, param_type in _iter_param_type(tool_xml):
if param_type != "select":
continue
for filter in param.findall("./options/filter"):
ftype = filter.get("type", None)
if ftype is None:
lint_ctx.error(f"Select parameter [{param_name}] contains filter without type.", node=filter)
continue


class InputsSelectOptionsFilterValidType(Linter):
"""
Lint dynamic options select for filters with invalid type
"""

@classmethod
def lint(cls, tool_source: "ToolSource", lint_ctx: "LintContext"):
tool_xml = getattr(tool_source, "xml_tree", None)
if not tool_xml:
return
for param, param_name, param_type in _iter_param_type(tool_xml):
if param_type != "select":
continue
for filter in param.findall("./options/filter"):
ftype = filter.get("type", None)
if ftype and ftype not in FILTER_TYPES:
lint_ctx.error(
f"Select parameter [{param_name}] contains filter with unknown type '{ftype}'.", node=filter
)


class InputsSelectOptionsDefinesOptions(Linter):
"""
Lint dynamic options select for the potential to defile options
Expand Down Expand Up @@ -1402,29 +1316,3 @@ def lint(cls, tool_source: "ToolSource", lint_ctx: "LintContext"):
f"Conditional [{conditional_name}] no truevalue/falsevalue found for when block '{when_id}'",
node=conditional,
)


# TODO xsd
class RepeatName(Linter):
@classmethod
def lint(cls, tool_source: "ToolSource", lint_ctx: "LintContext"):
tool_xml = getattr(tool_source, "xml_tree", None)
if not tool_xml:
return
repeats = tool_xml.findall("./inputs//repeat")
for repeat in repeats:
if "name" not in repeat.attrib:
lint_ctx.error("Repeat does not specify name attribute.", node=repeat)


# TODO xsd
class RepeatTitle(Linter):
@classmethod
def lint(cls, tool_source: "ToolSource", lint_ctx: "LintContext"):
tool_xml = getattr(tool_source, "xml_tree", None)
if not tool_xml:
return
repeats = tool_xml.findall("./inputs//repeat")
for repeat in repeats:
if "title" not in repeat.attrib:
lint_ctx.error("Repeat does not specify title attribute.", node=repeat)
11 changes: 11 additions & 0 deletions lib/galaxy/tool_util/linters/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ def lint(cls, tool_source: "ToolSource", lint_ctx: "LintContext"):
lint_ctx.warn("Tool contains multiple output sections, behavior undefined.", node=outputs[1])


class OutputsOutput(Linter):
@classmethod
def lint(cls, tool_source: "ToolSource", lint_ctx: "LintContext"):
tool_xml = getattr(tool_source, "xml_tree", None)
if not tool_xml:
return
output = tool_xml.find("./outputs/output")
if output is not None:
lint_ctx.warn("Avoid the use of 'output' and replace by 'data' or 'collection'", node=output)


class OutputsNameMissing(Linter):
@classmethod
def lint(cls, tool_source: "ToolSource", lint_ctx: "LintContext"):
Expand Down
Loading

0 comments on commit 68a7a0a

Please sign in to comment.