mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
Merge pull request #14845 from davelopez/fix_linter_with_comments
Fix tool linting with comments
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
"""This module contains a linting functions for tool outputs."""
|
||||
from galaxy.util import string_as_bool
|
||||
from galaxy.util import (
|
||||
etree,
|
||||
string_as_bool,
|
||||
)
|
||||
from ._util import is_valid_cheetah_placeholder
|
||||
from ..parser.output_collection_def import NAMED_PATTERNS
|
||||
|
||||
@@ -20,6 +23,8 @@ def lint_output(tool_xml, lint_ctx):
|
||||
labels = set()
|
||||
names = set()
|
||||
for output in list(outputs[0]):
|
||||
if output.tag is etree.Comment:
|
||||
continue
|
||||
if output.tag not in ["data", "collection"]:
|
||||
lint_ctx.warn(f"Unknown element found in outputs [{output.tag}]", node=output)
|
||||
continue
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"""This module contains a linting functions for tool error detection."""
|
||||
import re
|
||||
|
||||
from galaxy.util import etree
|
||||
from .command import get_command
|
||||
|
||||
|
||||
@@ -37,6 +38,8 @@ def lint_stdio(tool_source, lint_ctx):
|
||||
|
||||
stdio = stdios[0]
|
||||
for child in list(stdio):
|
||||
if child.tag is etree.Comment:
|
||||
continue
|
||||
if child.tag == "regex":
|
||||
_lint_regex(tool_xml, child, lint_ctx)
|
||||
elif child.tag == "exit_code":
|
||||
|
||||
@@ -5,6 +5,7 @@ import pytest
|
||||
|
||||
from galaxy.tool_util.lint import (
|
||||
lint_tool_source_with,
|
||||
lint_xml_with,
|
||||
LintContext,
|
||||
XMLLintMessageLine,
|
||||
XMLLintMessageXPath,
|
||||
@@ -22,6 +23,7 @@ from galaxy.tool_util.linters import (
|
||||
)
|
||||
from galaxy.tool_util.loader_directory import load_tool_sources_from_path
|
||||
from galaxy.tool_util.parser.xml import XmlToolSource
|
||||
from galaxy.util import parse_xml
|
||||
from galaxy.util.xml_macros import load_with_references
|
||||
|
||||
# TODO tests tool xml for general linter
|
||||
@@ -755,6 +757,17 @@ XML_ORDER = """
|
||||
</tool>
|
||||
"""
|
||||
|
||||
TOOL_WITH_COMMENTS = """
|
||||
<tool>
|
||||
<stdio>
|
||||
<!-- This is a comment -->
|
||||
</stdio>
|
||||
<outputs>
|
||||
<!-- This is a comment -->
|
||||
</outputs>
|
||||
</tool>
|
||||
"""
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def lint_ctx():
|
||||
@@ -774,6 +787,15 @@ def get_xml_tool_source(xml_string):
|
||||
return load_with_references(tool_path)[0]
|
||||
|
||||
|
||||
def get_tool_xml_exact(xml_string):
|
||||
"""Returns the tool XML as it is, without stripping comments or anything else."""
|
||||
with tempfile.NamedTemporaryFile(mode="w", suffix="tool.xml") as tmp:
|
||||
tmp.write(xml_string)
|
||||
tmp.flush()
|
||||
tool_path = tmp.name
|
||||
return parse_xml(tool_path, strip_whitespace=False, remove_comments=False)
|
||||
|
||||
|
||||
def failed_assert_print(lint_ctx):
|
||||
return (
|
||||
f"Valid: {lint_ctx.valid_messages}\n"
|
||||
@@ -1716,3 +1738,10 @@ def test_linting_cwl_tool(lint_ctx):
|
||||
assert len(lint_ctx.valid_messages) == 4
|
||||
assert len(lint_ctx.warn_messages) == 2
|
||||
assert not lint_ctx.error_messages
|
||||
|
||||
|
||||
def test_xml_comments_are_ignored(lint_ctx: LintContext):
|
||||
tool_xml = get_tool_xml_exact(TOOL_WITH_COMMENTS)
|
||||
lint_xml_with(lint_ctx, tool_xml)
|
||||
for lint_message in lint_ctx.message_list:
|
||||
assert "Comment" not in lint_message.message
|
||||
|
||||
Reference in New Issue
Block a user