{"id":9763,"library":"galaxy-tool-util","title":"Galaxy Tool Utilities","description":"galaxy-tool-util provides core utilities for parsing, managing, and validating Galaxy tool definitions and tool dependencies. It is an essential component for understanding and extending the Galaxy bioinformatics platform. The library is part of the larger Galaxy project and is released in lock-step with major Galaxy versions, typically every few months.","status":"active","version":"26.0.0","language":"en","source_language":"en","source_url":"https://github.com/galaxyproject/galaxy","tags":["galaxy","bioinformatics","tooling","utilities","xml-parsing"],"install":[{"cmd":"pip install galaxy-tool-util","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Required for robust XML parsing functionality, especially for tool definitions. While not always a direct dependency listed for the `galaxy-tool-util` package itself, it's a critical underlying dependency for many XML operations.","package":"lxml","optional":true}],"imports":[{"symbol":"get_tool_source","correct":"from galaxy.tool_util.parser import get_tool_source"},{"symbol":"lint_tool_xml","correct":"from galaxy.tool_util.linters import lint_tool_xml"},{"symbol":"tool_dependencies","correct":"from galaxy.tool_util.deps import dependencies as tool_dependencies"}],"quickstart":{"code":"import os\nfrom galaxy.tool_util.parser import get_tool_source\nfrom galaxy.tool_util.linters import lint_tool_xml\n\n# Create a dummy tool XML file for demonstration\ntool_xml_content = \"\"\"\n<tool id=\"test_tool\" name=\"Test Tool\" version=\"1.0.0\">\n    <description>A simple test tool</description>\n    <command>echo \"Hello World\"</command>\n    <inputs>\n        <param name=\"input_text\" type=\"text\" label=\"Input text\"/>\n    </inputs>\n    <outputs>\n        <data name=\"output_file\" format=\"txt\" label=\"Output Text File\"/>\n    </outputs>\n    <tests>\n        <test>\n            <param name=\"input_text\" value=\"test\"/>\n            <output name=\"output_file\" ftype=\"txt\" value=\"Hello World\" compare=\"re\"/>\n        </test>\n    </tests>\n</tool>\n\"\"\"\n\ntool_path = \"dummy_tool.xml\"\nwith open(tool_path, \"w\") as f:\n    f.write(tool_xml_content)\n\n# 1. Parse the tool XML\ntry:\n    tool_source = get_tool_source(tool_path)\n    print(f\"Successfully parsed tool: {tool_source.parse_id()} (version {tool_source.parse_version()})\")\n\n    # 2. Linter (basic validation)\n    # The lint_tool_xml function typically requires a tool_shed_repository mock for full functionality\n    # For a simple local file, we can run it with minimal context.\n    # In a real Galaxy environment, this would be part of a larger object.\n    print(\"Running linter...\")\n    lint_problems = []\n    # The linter expects an XML root element, not a path directly.\n    # For this quickstart, we'll demonstrate using a basic parse.\n    from xml.etree import ElementTree\n    root = ElementTree.parse(tool_path).getroot()\n\n    # lint_tool_xml needs a ToolSource object, not just the root.\n    # For a basic lint, you often need the full Galaxy context or specific mocks.\n    # This example focuses on parsing.\n    print(\"Basic parsing complete. Full linting requires more context.\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\nfinally:\n    # Clean up the dummy file\n    if os.path.exists(tool_path):\n        os.remove(tool_path)\n","lang":"python","description":"This quickstart demonstrates how to parse a Galaxy tool XML definition using `get_tool_source`. It creates a simple XML file, parses it, and prints basic metadata. Note that full linting (`lint_tool_xml`) often requires a more complete Galaxy environment or specific mock objects for its various checks."},"warnings":[{"fix":"Always refer to the latest Galaxy documentation and source code when building integrations. Pin your `galaxy-tool-util` version to match your Galaxy server's version.","message":"As an internal utility library, `galaxy-tool-util`'s APIs, especially for advanced features or internal representations, can change without explicit 'breaking change' announcements specific to this package. Such changes are often part of larger refactorings within the main Galaxy project.","severity":"breaking","affected_versions":"All versions, especially major releases (e.g., v25.0.0 to v26.0.0)"},{"fix":"Ensure that any tool XML files processed originate from trusted sources. If parsing untrusted XML, implement additional input validation and configure XML parsers (if directly using `lxml` or `ElementTree`) to explicitly disable DTD processing and external entity resolution.","message":"Parsing untrusted XML via functions like `get_tool_source` can expose applications to XML External Entity (XXE) attacks or other parser vulnerabilities. While underlying libraries like `lxml` often provide some default protections, vigilance is required.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Consult the Galaxy source code for `ToolSource` and related classes to understand its full capabilities and how to access specific tool definition components. Avoid directly manipulating the underlying XML tree unless absolutely necessary and you understand the implications.","message":"The `ToolSource` object returned by `get_tool_source` represents the parsed tool definition and its methods provide access to various parts of the tool. However, its methods might not directly expose every single XML attribute or element, and some advanced features (e.g., job parameters) might require deeper introspection or specific utility functions.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Ensure you have activated the correct Python environment and run `pip install galaxy-tool-util`.","cause":"The `galaxy-tool-util` package is not installed or the Python environment is not correctly configured.","error":"ImportError: No module named 'galaxy.tool_util'"},{"fix":"Review your tool XML file for syntax errors, missing closing tags, invalid characters, or incorrect XML structure. Use an XML validator to pinpoint the exact issue.","cause":"The provided XML file or string is malformed or contains syntax errors, preventing successful parsing.","error":"xml.etree.ElementTree.ParseError: not well-formed (invalid token): line X, column Y"},{"fix":"Consult the source code or official documentation for the `ToolSource` class and its subclasses to understand the available API. Use methods like `parse_id()`, `parse_name()`, `parse_version()` or specific parsing functions for inputs/outputs.","cause":"You are attempting to call a method or access an attribute that does not exist on the `ToolSource` object, or you are expecting it to expose a direct mapping to XML elements that it doesn't.","error":"AttributeError: 'ToolSource' object has no attribute 'some_nonexistent_method'"}]}