comparison env/lib/python3.9/site-packages/galaxy/tool_util/linters/stdio.py @ 0:4f3585e2f14b draft default tip

"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author shellac
date Mon, 22 Mar 2021 18:12:50 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4f3585e2f14b
1 """This module contains a linting functions for tool error detection."""
2 from .command import get_command
3
4
5 def lint_stdio(tool_source, lint_ctx):
6 tool_xml = getattr(tool_source, "xml_tree", None)
7 stdios = tool_xml.findall("./stdio") if tool_xml else []
8
9 if not stdios:
10 command = get_command(tool_xml) if tool_xml else None
11 if command is None or not command.get("detect_errors"):
12 if tool_source.parse_profile() <= "16.01":
13 lint_ctx.info("No stdio definition found, tool indicates error conditions with output written to stderr.")
14 else:
15 lint_ctx.info("No stdio definition found, tool indicates error conditions with non-zero exit codes.")
16 return
17
18 if len(stdios) > 1:
19 lint_ctx.error("More than one stdio tag found, behavior undefined.")
20 return
21
22 stdio = stdios[0]
23 for child in list(stdio):
24 if child.tag == "regex":
25 _lint_regex(child, lint_ctx)
26 elif child.tag == "exit_code":
27 _lint_exit_code(child, lint_ctx)
28 else:
29 message = "Unknown stdio child tag discovered [%s]. "
30 message += "Valid options are exit_code and regex."
31 lint_ctx.warn(message % child.tag)
32
33
34 def _lint_exit_code(child, lint_ctx):
35 for key in child.attrib.keys():
36 if key not in ["description", "level", "range"]:
37 lint_ctx.warn("Unknown attribute [%s] encountered on exit_code tag." % key)
38
39
40 def _lint_regex(child, lint_ctx):
41 for key in child.attrib.keys():
42 if key not in ["description", "level", "match", "source"]:
43 lint_ctx.warn("Unknown attribute [%s] encountered on regex tag." % key)