-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Split linters in separate classes #17081
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mvdbeek
merged 34 commits into
galaxyproject:dev
from
bernt-matthias:topic/linter-overhaul
Feb 16, 2024
Merged
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
8eb0ef0
split stdio linters in separate classes
bernt-matthias 0fbe617
remove linter code and fixes
bernt-matthias 8d43947
split general and citations linter
bernt-matthias dd2a388
split command linter
bernt-matthias 7b3d38c
make xml_order a Linter
bernt-matthias 350a439
split help linters
bernt-matthias bf340a5
started with test linters
bernt-matthias 3bccffc
split test linters
bernt-matthias 5ae6594
split output linters
bernt-matthias d357ad0
split input linters
bernt-matthias ca364d1
add lxml based xml schema check
bernt-matthias 5ef5651
do not print linter info
bernt-matthias 7817fe1
run xsd linter in all linter unit tests
bernt-matthias c3a93e5
some fixes for xsd
bernt-matthias aac06ac
Fix unit test assertion
mvdbeek 1a25ef6
skip validation of upload tool
bernt-matthias 3d09584
remove fix method from linters
bernt-matthias 212acf3
do not lint with ABC
bernt-matthias 7e0b77c
some fixes
bernt-matthias 6da7809
fix: allow options/column in data parameters
bernt-matthias c74f066
remove InputsSelectOptionTextMissing
bernt-matthias 12f69be
allow macro
bernt-matthias 584464e
add linter to lint context output
bernt-matthias 0bb8c72
split cwl linters
bernt-matthias 62adedb
allow options element in tool
bernt-matthias 555fe5f
try source_path() instead of _source_path
bernt-matthias ccced2f
add function to list available linters
bernt-matthias 3a98a3a
implement listing of linters
bernt-matthias 2428b9d
Merge branch 'dev' into topic/linter-overhaul
bernt-matthias 46ff3f2
use types-lxml instead of lxml-stubs
bernt-matthias 368f3e8
Revert "use types-lxml instead of lxml-stubs"
bernt-matthias ed8eb6e
Add type ignore
bernt-matthias a0b25b5
new lines
bernt-matthias 101a8a9
Merge branch 'topic/linter-overhaul' of https://github.com/bernt-matt…
bernt-matthias File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.