From ccced2f6e1b5114a6d66a0155579bda2d2f39441 Mon Sep 17 00:00:00 2001 From: Matthias Bernt Date: Mon, 15 Jan 2024 22:35:08 +0100 Subject: [PATCH] add function to list available linters --- lib/galaxy/tool_util/lint.py | 17 +++++++++++++++-- test/unit/tool_util/test_tool_linters.py | 21 +++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/lib/galaxy/tool_util/lint.py b/lib/galaxy/tool_util/lint.py index 4608ddba3014..f85e92d2e20a 100644 --- a/lib/galaxy/tool_util/lint.py +++ b/lib/galaxy/tool_util/lint.py @@ -60,6 +60,7 @@ Union, ) +import galaxy.tool_util.linters from galaxy.tool_util.parser import get_tool_source from galaxy.util import ( etree, @@ -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) @@ -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 @@ -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 diff --git a/test/unit/tool_util/test_tool_linters.py b/test/unit/tool_util/test_tool_linters.py index 53a284ac6db4..a6d1ca395db0 100644 --- a/test/unit/tool_util/test_tool_linters.py +++ b/test/unit/tool_util/test_tool_linters.py @@ -8,6 +8,7 @@ lint_tool_source_with_modules, lint_xml_with, LintContext, + list_linters, XMLLintMessageLine, XMLLintMessageXPath, ) @@ -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)])