-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6a48b29
commit 8a16c62
Showing
2 changed files
with
106 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,88 @@ | ||
"""This module contains a linting function for a tool's command description. | ||
"""This module contains linters for a tool's command description. | ||
A command description describes how to build the command-line to execute | ||
from supplied inputs. | ||
""" | ||
from typing import TYPE_CHECKING | ||
|
||
from galaxy.tool_util.lint import Linter | ||
|
||
def lint_command(tool_xml, lint_ctx): | ||
"""Ensure tool contains exactly one command and check attributes.""" | ||
root = tool_xml.find("./command") | ||
if root is None: | ||
root = tool_xml.getroot() | ||
|
||
commands = tool_xml.findall("./command") | ||
if len(commands) > 1: | ||
lint_ctx.error("More than one command tag found, behavior undefined.", node=commands[1]) | ||
return | ||
|
||
if len(commands) == 0: | ||
lint_ctx.error("No command tag found, must specify a command template to execute.", node=root) | ||
return | ||
|
||
command = get_command(tool_xml) | ||
if command.text is None: | ||
lint_ctx.error("Command is empty.", node=root) | ||
elif "TODO" in command.text: | ||
lint_ctx.warn("Command template contains TODO text.", node=command) | ||
|
||
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(f"Unknown detect_errors attribute [{detect_errors}]", node=command) | ||
|
||
interpreter_info = "" | ||
if interpreter_type: | ||
interpreter_info = f" with interpreter of type [{interpreter_type}]" | ||
if interpreter_type: | ||
lint_ctx.warn("Command uses deprecated 'interpreter' attribute.", node=command) | ||
lint_ctx.info(f"Tool contains a command{interpreter_info}.", node=command) | ||
|
||
|
||
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 | ||
if TYPE_CHECKING: | ||
from galaxy.tool_util.lint import LintContext | ||
from galaxy.tool_util.parser.interface import ToolSource | ||
|
||
|
||
class CommandMultiple(Linter): | ||
@classmethod | ||
def lint(cls, tool_source: "ToolSource", lint_ctx: "LintContext"): | ||
tool_xml = getattr(tool_source, "xml_tree", None) | ||
if not tool_xml: | ||
return | ||
commands = tool_xml.findall("./command") | ||
if len(commands) > 1: | ||
lint_ctx.error("More than one command tag found, behavior undefined.", node=commands[1]) | ||
|
||
|
||
class CommandMissing(Linter): | ||
@classmethod | ||
def lint(cls, tool_source: "ToolSource", lint_ctx: "LintContext"): | ||
tool_xml = getattr(tool_source, "xml_tree", None) | ||
if not tool_xml: | ||
return | ||
root = tool_xml.find("./command") or tool_xml.getroot() | ||
command = tool_xml.find("./command") | ||
if command is None: | ||
lint_ctx.error("No command tag found, must specify a command template to execute.", node=root) | ||
|
||
|
||
class CommandEmpty(Linter): | ||
@classmethod | ||
def lint(cls, tool_source: "ToolSource", lint_ctx: "LintContext"): | ||
tool_xml = getattr(tool_source, "xml_tree", None) | ||
if not tool_xml: | ||
return | ||
root = tool_xml.find("./command") or tool_xml.getroot() | ||
command = tool_xml.find("./command") | ||
if command is not None and command.text is None: | ||
lint_ctx.error("Command is empty.", node=root) | ||
|
||
|
||
class CommandTODO(Linter): | ||
@classmethod | ||
def lint(cls, tool_source: "ToolSource", lint_ctx: "LintContext"): | ||
tool_xml = getattr(tool_source, "xml_tree", None) | ||
if not tool_xml: | ||
return | ||
command = tool_xml.find("./command") | ||
if command is not None and command.text is not None and "TODO" in command.text: | ||
lint_ctx.warn("Command template contains TODO text.", node=command) | ||
|
||
|
||
class CommandInterpreterDeprecated(Linter): | ||
@classmethod | ||
def lint(cls, tool_source: "ToolSource", lint_ctx: "LintContext"): | ||
tool_xml = getattr(tool_source, "xml_tree", None) | ||
if not tool_xml: | ||
return | ||
command = tool_xml.find("./command") | ||
if command is None: | ||
return | ||
interpreter_type = command.attrib.get("interpreter", None) | ||
if interpreter_type is not None: | ||
lint_ctx.warn("Command uses deprecated 'interpreter' attribute.", node=command) | ||
|
||
|
||
class CommandInfo(Linter): | ||
@classmethod | ||
def lint(cls, tool_source: "ToolSource", lint_ctx: "LintContext"): | ||
tool_xml = getattr(tool_source, "xml_tree", None) | ||
if not tool_xml: | ||
return | ||
command = tool_xml.find("./command") | ||
if command is None: | ||
return | ||
interpreter_type = command.attrib.get("interpreter", None) | ||
interpreter_info = "" | ||
if interpreter_type: | ||
interpreter_info = f" with interpreter of type [{interpreter_type}]" | ||
lint_ctx.info(f"Tool contains a command{interpreter_info}.", node=command) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters