-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rewrite tool linters defined in planemo
- Loading branch information
1 parent
251776c
commit a6ff9cb
Showing
9 changed files
with
294 additions
and
163 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
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,37 +1,62 @@ | ||
"""Ensure requirements are matched in best practice conda channels.""" | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
from galaxy.tool_util.deps.conda_util import requirement_to_conda_targets | ||
from galaxy.tool_util.lint import Linter | ||
|
||
from planemo.conda import ( | ||
BEST_PRACTICE_CHANNELS, | ||
best_practice_search, | ||
tool_source_conda_targets, | ||
) | ||
|
||
if TYPE_CHECKING: | ||
from galaxy.tool_util.lint import LintContext | ||
from galaxy.tool_util.parser.interface import ToolSource | ||
|
||
lint_tool_types = ["*"] | ||
|
||
|
||
def lint_requirements_in_conda(tool_source, lint_ctx): | ||
"""Check requirements of tool source against best practice Conda channels.""" | ||
conda_targets = tool_source_conda_targets(tool_source) | ||
if not conda_targets: | ||
lint_ctx.warn("No valid package requirement tags found to check against Conda.") | ||
return | ||
|
||
for conda_target in conda_targets: | ||
(best_hit, exact) = best_practice_search(conda_target) | ||
conda_target_str = conda_target.package | ||
if conda_target.version: | ||
conda_target_str += "@%s" % (conda_target.version) | ||
if best_hit and exact: | ||
template = "Requirement [%s] matches target in best practice Conda channel [%s]." | ||
message = template % (conda_target_str, best_hit.get("channel")) | ||
lint_ctx.info(message) | ||
elif best_hit: | ||
template = ( | ||
"Requirement [%s] doesn't exactly match available version [%s] in best practice Conda channel [%s]." | ||
) | ||
message = template % (conda_target_str, best_hit["version"], best_hit.get("channel")) | ||
lint_ctx.warn(message) | ||
else: | ||
template = "Requirement [%s] doesn't match any recipe in a best practice conda channel [%s]." | ||
message = template % (conda_target_str, BEST_PRACTICE_CHANNELS) | ||
lint_ctx.warn(message) | ||
class CondaRequirementValid(Linter): | ||
@classmethod | ||
def lint(cls, tool_source: "ToolSource", lint_ctx: "LintContext"): | ||
for conda_target, requirement in _requirements_conda_targets(tool_source): | ||
(best_hit, exact) = best_practice_search(conda_target) | ||
conda_target_str = conda_target.package | ||
if conda_target.version: | ||
conda_target_str += "@%s" % (conda_target.version) | ||
if best_hit and exact: | ||
message = f"Requirement [{conda_target_str}] matches target in best practice Conda channel [{best_hit.get('channel')}]." | ||
lint_ctx.info(message, linter=cls.name(), node=requirement) | ||
|
||
|
||
class CondaRequirementInexact(Linter): | ||
@classmethod | ||
def lint(cls, tool_source: "ToolSource", lint_ctx: "LintContext"): | ||
for conda_target, requirement in _requirements_conda_targets(tool_source): | ||
(best_hit, exact) = best_practice_search(conda_target) | ||
conda_target_str = conda_target.package | ||
if conda_target.version: | ||
conda_target_str += "@%s" % (conda_target.version) | ||
if best_hit and not exact: | ||
message = f"Requirement [{conda_target_str}] doesn't exactly match available version [{best_hit['version']}] in best practice Conda channel [{best_hit.get('channel')}]." | ||
lint_ctx.warn(message, linter=cls.name(), node=requirement) | ||
|
||
|
||
class CondaRequirementMissing(Linter): | ||
@classmethod | ||
def lint(cls, tool_source: "ToolSource", lint_ctx: "LintContext"): | ||
for conda_target, requirement in _requirements_conda_targets(tool_source): | ||
(best_hit, exact) = best_practice_search(conda_target) | ||
conda_target_str = conda_target.package | ||
if conda_target.version: | ||
conda_target_str += "@%s" % (conda_target.version) | ||
if best_hit and not exact: | ||
message = f"Requirement [{conda_target_str}] doesn't match any recipe in a best practice conda channel ['{BEST_PRACTICE_CHANNELS}']." | ||
lint_ctx.warn(message, linter=cls.name(), node=requirement) | ||
|
||
|
||
def _requirements_conda_targets(tool_source): | ||
requirements, *_ = tool_source.parse_requirements_and_containers() | ||
for requirement in requirements: | ||
yield requirement_to_conda_targets(requirement), requirement |
Oops, something went wrong.