Mercurial > repos > guerler > springsuite
comparison planemo/lib/python3.7/site-packages/galaxy/tool_util/linters/outputs.py @ 1:56ad4e20f292 draft
"planemo upload commit 6eee67778febed82ddd413c3ca40b3183a3898f1"
| author | guerler |
|---|---|
| date | Fri, 31 Jul 2020 00:32:28 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 0:d30785e31577 | 1:56ad4e20f292 |
|---|---|
| 1 """This module contains a linting functions for tool outputs.""" | |
| 2 from ._util import is_valid_cheetah_placeholder | |
| 3 | |
| 4 | |
| 5 def lint_output(tool_xml, lint_ctx): | |
| 6 """Check output elements, ensure there is at least one and check attributes.""" | |
| 7 outputs = tool_xml.findall("./outputs") | |
| 8 if len(outputs) == 0: | |
| 9 lint_ctx.warn("Tool contains no outputs section, most tools should produce outputs.") | |
| 10 if len(outputs) > 1: | |
| 11 lint_ctx.warn("Tool contains multiple output sections, behavior undefined.") | |
| 12 | |
| 13 num_outputs = 0 | |
| 14 if len(outputs) == 0: | |
| 15 lint_ctx.warn("No outputs found") | |
| 16 return | |
| 17 | |
| 18 for output in list(outputs[0]): | |
| 19 if output.tag not in ["data", "collection"]: | |
| 20 lint_ctx.warn("Unknown element found in outputs [%s]" % output.tag) | |
| 21 continue | |
| 22 num_outputs += 1 | |
| 23 if "name" not in output.attrib: | |
| 24 lint_ctx.warn("Tool output doesn't define a name - this is likely a problem.") | |
| 25 else: | |
| 26 if not is_valid_cheetah_placeholder(output.attrib["name"]): | |
| 27 lint_ctx.warn("Tool output name [%s] is not a valid Cheetah placeholder.", output.attrib["name"]) | |
| 28 | |
| 29 format_set = False | |
| 30 if output.tag == "data": | |
| 31 if __check_format(output, lint_ctx): | |
| 32 format_set = True | |
| 33 elif "auto_format" in output.attrib and output.attrib["auto_format"]: | |
| 34 format_set = True | |
| 35 | |
| 36 elif output.tag == "collection": | |
| 37 if "type" not in output.attrib: | |
| 38 lint_ctx.warn("Collection output with undefined 'type' found.") | |
| 39 if "structured_like" in output.attrib and "inherit_format" in output.attrib: | |
| 40 format_set = True | |
| 41 if "format_source" in output.attrib: | |
| 42 format_set = True | |
| 43 for sub in output: | |
| 44 if __check_pattern(sub): | |
| 45 format_set = True | |
| 46 elif __check_format(sub, lint_ctx): | |
| 47 format_set = True | |
| 48 | |
| 49 if not format_set: | |
| 50 lint_ctx.warn("Tool %s output %s doesn't define an output format." % (output.tag, output.attrib.get("name", "with missing name"))) | |
| 51 | |
| 52 lint_ctx.info("%d outputs found.", num_outputs) | |
| 53 | |
| 54 | |
| 55 def __check_format(node, lint_ctx): | |
| 56 """ | |
| 57 check if format/ext attribute is set in a given node | |
| 58 issue a warning if the value is input | |
| 59 return true (node defines format/ext) / false (else) | |
| 60 """ | |
| 61 fmt = node.attrib.get("format", node.attrib.get("ext", None)) | |
| 62 if fmt == "input": | |
| 63 lint_ctx.warn("Using format='input' on %s, format_source attribute is less ambiguous and should be used instead." % node.tag) | |
| 64 return fmt is not None | |
| 65 | |
| 66 | |
| 67 def __check_pattern(node): | |
| 68 """ | |
| 69 check if pattern attribute is set and defines the extension | |
| 70 """ | |
| 71 if node.tag != "discover_datasets": | |
| 72 return False | |
| 73 if "pattern" not in node.attrib: | |
| 74 return False | |
| 75 if node.attrib["pattern"] == "__default__": | |
| 76 return True | |
| 77 if "ext" in node.attrib["pattern"] and node.attrib["pattern"].startswith("__") and node.attrib["pattern"].endswith("__"): | |
| 78 return True |
