comparison env/lib/python3.9/site-packages/galaxy/tool_util/linters/command.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 function for a tool's command description.
2
3 A command description describes how to build the command-line to execute
4 from supplied inputs.
5 """
6
7
8 def lint_command(tool_xml, lint_ctx):
9 """Ensure tool contains exactly one command and check attributes."""
10 root = tool_xml.getroot()
11 commands = root.findall("command")
12 if len(commands) > 1:
13 lint_ctx.error("More than one command tag found, behavior undefined.")
14 return
15
16 if len(commands) == 0:
17 lint_ctx.error("No command tag found, must specify a command template to execute.")
18 return
19
20 command = get_command(tool_xml)
21 if "TODO" in command:
22 lint_ctx.warn("Command template contains TODO text.")
23
24 command_attrib = command.attrib
25 interpreter_type = None
26 for key, value in command_attrib.items():
27 if key == "interpreter":
28 interpreter_type = value
29 elif key == "detect_errors":
30 detect_errors = value
31 if detect_errors not in ["default", "exit_code", "aggressive"]:
32 lint_ctx.warn("Unknown detect_errors attribute [%s]" % detect_errors)
33
34 interpreter_info = ""
35 if interpreter_type:
36 interpreter_info = " with interpreter of type [%s]" % interpreter_type
37 if interpreter_type:
38 lint_ctx.info("Command uses deprecated 'interpreter' attribute.")
39 lint_ctx.info("Tool contains a command%s." % interpreter_info)
40
41
42 def get_command(tool_xml):
43 """Get command XML element from supplied XML root."""
44 root = tool_xml.getroot()
45 commands = root.findall("command")
46 command = None
47 if len(commands) == 1:
48 command = commands[0]
49 return command