Mercurial > repos > shellac > sam_consensus_v3
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/env/lib/python3.9/site-packages/galaxy/tool_util/linters/command.py Mon Mar 22 18:12:50 2021 +0000 @@ -0,0 +1,49 @@ +"""This module contains a linting function for a tool's command description. + +A command description describes how to build the command-line to execute +from supplied inputs. +""" + + +def lint_command(tool_xml, lint_ctx): + """Ensure tool contains exactly one command and check attributes.""" + root = tool_xml.getroot() + commands = root.findall("command") + if len(commands) > 1: + lint_ctx.error("More than one command tag found, behavior undefined.") + return + + if len(commands) == 0: + lint_ctx.error("No command tag found, must specify a command template to execute.") + return + + command = get_command(tool_xml) + if "TODO" in command: + lint_ctx.warn("Command template contains TODO text.") + + command_attrib = command.attrib + interpreter_type = None + for key, value in command_attrib.items(): + if key == "interpreter": + interpreter_type = value + elif key == "detect_errors": + detect_errors = value + if detect_errors not in ["default", "exit_code", "aggressive"]: + lint_ctx.warn("Unknown detect_errors attribute [%s]" % detect_errors) + + interpreter_info = "" + if interpreter_type: + interpreter_info = " with interpreter of type [%s]" % interpreter_type + if interpreter_type: + lint_ctx.info("Command uses deprecated 'interpreter' attribute.") + lint_ctx.info("Tool contains a command%s." % interpreter_info) + + +def get_command(tool_xml): + """Get command XML element from supplied XML root.""" + root = tool_xml.getroot() + commands = root.findall("command") + command = None + if len(commands) == 1: + command = commands[0] + return command