Skip to content

Commit

Permalink
add function to list available linters
Browse files Browse the repository at this point in the history
  • Loading branch information
bernt-matthias committed Jan 16, 2024
1 parent 555fe5f commit ccced2f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lib/galaxy/tool_util/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
Union,
)

import galaxy.tool_util.linters
from galaxy.tool_util.parser import get_tool_source
from galaxy.util import (
etree,
Expand Down Expand Up @@ -336,7 +337,6 @@ def lint_xml(

def lint_tool_source_with(lint_context, tool_source, extra_modules=None) -> LintContext:
extra_modules = extra_modules or []
import galaxy.tool_util.linters

linter_modules = submodules.import_submodules(galaxy.tool_util.linters)
linter_modules.extend(extra_modules)
Expand All @@ -353,7 +353,6 @@ def lint_tool_source_with_modules(lint_context: LintContext, tool_source, linter
continue

for name, value in inspect.getmembers(module):
# print(name)
if callable(value) and name.startswith("lint_"):
# Look at the first argument to the linter to decide
# if we should lint the XML description or the abstract
Expand All @@ -376,3 +375,17 @@ def lint_xml_with(lint_context, tool_xml, extra_modules=None) -> LintContext:
extra_modules = extra_modules or []
tool_source = get_tool_source(xml_tree=tool_xml)
return lint_tool_source_with(lint_context, tool_source, extra_modules=extra_modules)


def list_linters(extra_modules: Optional[List[str]] = None) -> List[str]:
extra_modules = extra_modules or []
linter_modules = submodules.import_submodules(galaxy.tool_util.linters)
linter_modules.extend(extra_modules)
linters = list()
for module in linter_modules:
for name, value in inspect.getmembers(module):
if callable(value) and name.startswith("lint_"):
linters.append(name[5:])
elif inspect.isclass(value) and issubclass(value, Linter) and not inspect.isabstract(value):
linters.append(name)
return linters
21 changes: 21 additions & 0 deletions test/unit/tool_util/test_tool_linters.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
lint_tool_source_with_modules,
lint_xml_with,
LintContext,
list_linters,
XMLLintMessageLine,
XMLLintMessageXPath,
)
Expand Down Expand Up @@ -2070,3 +2071,23 @@ def test_xml_comments_are_ignored(lint_ctx: LintContext):
lint_xml_with(lint_ctx, tool_xml)
for lint_message in lint_ctx.message_list:
assert "Comment" not in lint_message.message


def test_list_linters():
linters = list_linters()
assert len(linters) >= 129
# make sure that linters from all modules are available
for prefix in [
"Citations",
"Command",
"CWL",
"ToolProfile",
"Help",
"Inputs",
"Outputs",
"StdIO",
"Tests",
"XMLOrder",
"XSD",
]:
assert len([x for x in linters if x.startswith(prefix)])

0 comments on commit ccced2f

Please sign in to comment.