Skip to content

Commit

Permalink
Merge pull request #17655 from bernt-matthias/topic/lint-bio.tools
Browse files Browse the repository at this point in the history
tool linter: check for valid bio.tools entries
  • Loading branch information
jmchilton authored Mar 12, 2024
2 parents 63cbae8 + 3dae54a commit 0a3e222
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
14 changes: 14 additions & 0 deletions lib/galaxy/tool_util/linters/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from packaging.version import Version

from galaxy.tool_util.biotools.source import ApiBiotoolsMetadataSource
from galaxy.tool_util.lint import Linter
from galaxy.tool_util.version import (
LegacyVersion,
Expand Down Expand Up @@ -227,3 +228,16 @@ def lint(cls, tool_source: "ToolSource", lint_ctx: "LintContext"):
lint_ctx.warn(
"Expressions in resource requirement not supported yet", linter=cls.name(), node=tool_node
)


class BioToolsValid(Linter):
@classmethod
def lint(cls, tool_source: "ToolSource", lint_ctx: "LintContext"):
_, tool_node = _tool_xml_and_root(tool_source)
xrefs = tool_source.parse_xrefs()
for xref in xrefs:
if xref["reftype"] != "bio.tools":
continue
metadata_source = ApiBiotoolsMetadataSource()
if not metadata_source.get_biotools_metadata(xref["value"]):
lint_ctx.warn(f'No entry {xref["value"]} in bio.tools.', linter=cls.name(), node=tool_node)
23 changes: 22 additions & 1 deletion test/unit/tool_util/test_tool_linters.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
ElementTree,
parse_xml,
)
from galaxy.util.unittest_utils import skip_if_site_down
from galaxy.util.xml_macros import load_with_references

# TODO tests tool xml for general linter
Expand Down Expand Up @@ -118,6 +119,15 @@
</tool>
"""

GENERAL_VALID_BIOTOOLS = """
<tool name="valid name" id="valid_id" version="1.0+galaxy1" profile="23.0">
<xrefs>
<xref type="bio.tools">bwa</xref>
<xref type="bio.tools">johnscoolbowtie</xref>
</xrefs>
</tool>
"""

# test tool xml for help linter
HELP_MULTIPLE = """
<tool id="id" name="name">
Expand Down Expand Up @@ -1081,6 +1091,17 @@ def test_general_valid_new_profile_fmt(lint_ctx):
assert not lint_ctx.error_messages


@skip_if_site_down("https://bio.tools/")
def test_general_valid_biotools(lint_ctx):
tool_source = get_xml_tool_source(GENERAL_VALID_BIOTOOLS)
run_lint_module(lint_ctx, general, tool_source)
assert "No entry johnscoolbowtie in bio.tools." in lint_ctx.warn_messages
assert not lint_ctx.info_messages
assert len(lint_ctx.valid_messages) == 4
assert len(lint_ctx.warn_messages) == 1
assert not lint_ctx.error_messages


def test_help_multiple(lint_ctx):
tool_source = get_xml_tool_source(HELP_MULTIPLE)
run_lint_module(lint_ctx, help, tool_source)
Expand Down Expand Up @@ -2078,7 +2099,7 @@ def test_xml_comments_are_ignored(lint_ctx: LintContext):
def test_list_linters():
linter_names = Linter.list_listers()
# make sure to add/remove a test for new/removed linters if this number changes
assert len(linter_names) == 130
assert len(linter_names) == 131
assert "Linter" not in linter_names
# make sure that linters from all modules are available
for prefix in [
Expand Down

0 comments on commit 0a3e222

Please sign in to comment.