Warning

This document is for an in-development version of Galaxy. You can alternatively view this page in the latest release if it exists or view the top of the latest release's documentation.

Source code for galaxy.tool_util.linters.command

"""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

if TYPE_CHECKING:
    from galaxy.tool_util.lint import LintContext
    from galaxy.tool_util.parser.interface import ToolSource


[docs] class CommandMissing(Linter):
[docs] @classmethod def lint(cls, tool_source: "ToolSource", lint_ctx: "LintContext") -> None: tool_xml = getattr(tool_source, "xml_tree", None) if not tool_xml: return root = tool_xml.find("./command") if root is None: root = 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.", linter=cls.name(), node=root )
[docs] class CommandEmpty(Linter):
[docs] @classmethod def lint(cls, tool_source: "ToolSource", lint_ctx: "LintContext") -> None: tool_xml = getattr(tool_source, "xml_tree", None) if not tool_xml: return root = tool_xml.find("./command") if root is None: root = tool_xml.getroot() command = tool_xml.find("./command") if command is not None and command.text is None: lint_ctx.error("Command is empty.", linter=cls.name(), node=root)
[docs] class CommandTODO(Linter):
[docs] @classmethod def lint(cls, tool_source: "ToolSource", lint_ctx: "LintContext") -> None: 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.", linter=cls.name(), node=command)
[docs] class CommandInterpreterDeprecated(Linter):
[docs] @classmethod def lint(cls, tool_source: "ToolSource", lint_ctx: "LintContext") -> None: 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.", linter=cls.name(), node=command)
[docs] class CommandInfo(Linter):
[docs] @classmethod def lint(cls, tool_source: "ToolSource", lint_ctx: "LintContext") -> None: tool_xml = getattr(tool_source, "xml_tree", None) if not tool_xml: return command = tool_xml.find("./command") if command is None: return interpreter_info = "" if interpreter_type := command.attrib.get("interpreter", None): interpreter_info = f" with interpreter of type [{interpreter_type}]" lint_ctx.info(f"Tool contains a command{interpreter_info}.", linter=cls.name(), node=command)
def _wraps_external_software(tool_source: "ToolSource") -> bool: """Return True if the tool declares a package requirement or a container.""" requirements, containers, *_ = tool_source.parse_requirements() return any(r.type == "package" for r in requirements) or bool(containers)
[docs] class VersionCommandMissing(Linter):
[docs] @classmethod def lint(cls, tool_source: "ToolSource", lint_ctx: "LintContext") -> None: tool_xml = getattr(tool_source, "xml_tree", None) if not tool_xml: return if tool_xml.find("./version_command") is not None: return if not _wraps_external_software(tool_source): return lint_ctx.info( "No version_command found, tools wrapping packaged software should report its version.", linter=cls.name(), node=tool_xml.getroot(), )
[docs] class VersionCommandMissingNoRequirements(Linter):
[docs] @classmethod def lint(cls, tool_source: "ToolSource", lint_ctx: "LintContext") -> None: tool_xml = getattr(tool_source, "xml_tree", None) if not tool_xml: return if tool_xml.find("./version_command") is not None: return if _wraps_external_software(tool_source): return lint_ctx.info( "No version_command found, that should be OK for a tool without package requirements.", linter=cls.name(), node=tool_xml.getroot(), )