Skip to content

Commit

Permalink
implement listing of linters
Browse files Browse the repository at this point in the history
using `__subclasses__`
  • Loading branch information
bernt-matthias committed Jan 17, 2024
1 parent ccced2f commit 2021ffb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
21 changes: 7 additions & 14 deletions lib/galaxy/tool_util/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ def name(cls) -> str:
"""
return cls.__name__

@classmethod
def list_listers(cls) -> List[str]:
"""
list the names of all linter derived from Linter
"""
return [s.__name__ for s in cls.__subclasses__()]


class LintMessage:
"""
Expand Down Expand Up @@ -375,17 +382,3 @@ 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
8 changes: 4 additions & 4 deletions test/unit/tool_util/test_tool_linters.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
lint_tool_source_with_modules,
lint_xml_with,
LintContext,
list_linters,
Linter,
XMLLintMessageLine,
XMLLintMessageXPath,
)
Expand Down Expand Up @@ -2074,8 +2074,8 @@ def test_xml_comments_are_ignored(lint_ctx: LintContext):


def test_list_linters():
linters = list_linters()
assert len(linters) >= 129
linter_names = Linter.list_listers()
assert len(linter_names) >= 129
# make sure that linters from all modules are available
for prefix in [
"Citations",
Expand All @@ -2090,4 +2090,4 @@ def test_list_linters():
"XMLOrder",
"XSD",
]:
assert len([x for x in linters if x.startswith(prefix)])
assert len([x for x in linter_names if x.startswith(prefix)])

0 comments on commit 2021ffb

Please sign in to comment.