-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17081 from bernt-matthias/topic/linter-overhaul
Split linters in separate classes
- Loading branch information
Showing
15 changed files
with
2,840 additions
and
1,147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,73 @@ | ||
"""This module contains a citation lint function. | ||
"""This module contains citation linters. | ||
Citations describe references that should be used when consumers | ||
of the tool publish results. | ||
""" | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
def lint_citations(tool_xml, lint_ctx): | ||
"""Ensure tool contains at least one valid citation.""" | ||
root = tool_xml.find("./citations") | ||
if root is None: | ||
root = tool_xml.getroot() | ||
|
||
citations = tool_xml.findall("citations") | ||
if len(citations) > 1: | ||
lint_ctx.error("More than one citation section found, behavior undefined.", node=citations[1]) | ||
return | ||
|
||
if len(citations) == 0: | ||
lint_ctx.warn("No citations found, consider adding citations to your tool.", node=root) | ||
return | ||
|
||
valid_citations = 0 | ||
for citation in citations[0]: | ||
if citation.tag != "citation": | ||
lint_ctx.warn( | ||
f"Unknown tag discovered in citations block [{citation.tag}], will be ignored.", node=citation | ||
) | ||
continue | ||
citation_type = citation.attrib.get("type") | ||
if citation_type not in ("bibtex", "doi"): | ||
lint_ctx.warn(f"Unknown citation type discovered [{citation_type}], will be ignored.", node=citation) | ||
continue | ||
if citation.text is None or not citation.text.strip(): | ||
lint_ctx.error(f"Empty {citation_type} citation.", node=citation) | ||
continue | ||
valid_citations += 1 | ||
|
||
if valid_citations > 0: | ||
lint_ctx.valid(f"Found {valid_citations} likely valid citations.", node=root) | ||
else: | ||
lint_ctx.warn("Found no valid citations.", node=root) | ||
from galaxy.tool_util.lint import Linter | ||
|
||
if TYPE_CHECKING: | ||
from galaxy.tool_util.lint import LintContext | ||
from galaxy.tool_util.parser.interface import ToolSource | ||
|
||
|
||
class CitationsMissing(Linter): | ||
@classmethod | ||
def lint(cls, tool_source: "ToolSource", lint_ctx: "LintContext"): | ||
tool_xml = getattr(tool_source, "xml_tree", None) | ||
if not tool_xml: | ||
return | ||
root = tool_xml.find("./citations") | ||
if root is None: | ||
root = tool_xml.getroot() | ||
citations = tool_xml.findall("citations") | ||
if len(citations) == 0: | ||
lint_ctx.warn("No citations found, consider adding citations to your tool.", linter=cls.name(), node=root) | ||
|
||
|
||
class CitationsNoText(Linter): | ||
@classmethod | ||
def lint(cls, tool_source: "ToolSource", lint_ctx: "LintContext"): | ||
tool_xml = getattr(tool_source, "xml_tree", None) | ||
if not tool_xml: | ||
return | ||
citations = tool_xml.find("citations") | ||
if citations is None: | ||
return | ||
for citation in citations: | ||
citation_type = citation.attrib.get("type") | ||
if citation_type in ["doi", "bibtex"] and (citation.text is None or not citation.text.strip()): | ||
lint_ctx.error(f"Empty {citation_type} citation.", linter=cls.name(), node=citation) | ||
|
||
|
||
class CitationsFound(Linter): | ||
@classmethod | ||
def lint(cls, tool_source: "ToolSource", lint_ctx: "LintContext"): | ||
tool_xml = getattr(tool_source, "xml_tree", None) | ||
if not tool_xml: | ||
return | ||
root = tool_xml.find("./citations") | ||
if root is None: | ||
root = tool_xml.getroot() | ||
citations = tool_xml.find("citations") | ||
|
||
if citations is not None and len(citations) > 0: | ||
lint_ctx.valid(f"Found {len(citations)} citations.", linter=cls.name(), node=root) | ||
|
||
|
||
class CitationsNoValid(Linter): | ||
@classmethod | ||
def lint(cls, tool_source: "ToolSource", lint_ctx: "LintContext"): | ||
tool_xml = getattr(tool_source, "xml_tree", None) | ||
if not tool_xml: | ||
return | ||
root = tool_xml.find("./citations") | ||
if root is None: | ||
root = tool_xml.getroot() | ||
citations = tool_xml.findall("citations") | ||
if len(citations) != 1: | ||
return | ||
if len(citations[0]) == 0: | ||
lint_ctx.warn("Found no valid citations.", linter=cls.name(), node=root) |
Oops, something went wrong.