Permalink
Browse files

Implement ``--conda_requirements`` flag on lint.

```
Applying linter requirements_in_conda... WARNING
.. WARNING: Requirement [bwa@0.7.7] doesn't exactly match available version [0.7.15] in best practice Conda channel [bioconda].
.. INFO: Requirement [samtools@0.1.16] matches target in best practice Conda channel [bioconda].
```
  • Loading branch information...
jmchilton committed Oct 2, 2016
1 parent 19b2ee9 commit 9da8387fdd8c87625713c3b7029ccf2112fcd51f
Showing with 57 additions and 7 deletions.
  1. +6 −0 planemo/commands/cmd_lint.py
  2. +16 −5 planemo/conda.py
  3. +5 −1 planemo/lint.py
  4. +29 −0 planemo/linters/conda_requirements.py
  5. +1 −1 requirements.txt
@@ -27,6 +27,12 @@
default=False,
help="Check validity of DOIs in XML files",
)
@click.option(
"--conda_requirements",
is_flag=True,
default=False,
help="Check tool requirements for availability in best practice Conda channels.",
)
# @click.option(
# "--verify",
# is_flag=True,
@@ -7,8 +7,7 @@
import os

from galaxy.tools.deps import conda_util
from galaxy.tools.deps.requirements import parse_requirements_from_xml
from galaxy.tools.loader_directory import load_tool_elements_from_path
from galaxy.tools.loader_directory import load_tool_sources_from_path

from planemo.io import shell

@@ -33,9 +32,21 @@ def build_conda_context(ctx, **kwds):
def collect_conda_targets(path, found_tool_callback=None, conda_context=None):
"""Load CondaTarget objects from supplied artifact sources."""
conda_targets = []
for (tool_path, tool_xml) in load_tool_elements_from_path(path):
for (tool_path, tool_source) in load_tool_sources_from_path(path):
if found_tool_callback:
found_tool_callback(tool_path)
requirements, containers = parse_requirements_from_xml(tool_xml)
conda_targets.extend(conda_util.requirements_to_conda_targets(requirements))
conda_targets.extend(tool_source_conda_targets(tool_source))
return conda_targets


def tool_source_conda_targets(tool_source):
"""Load CondaTarget object from supplied abstract tool source."""
requirements, _ = tool_source.parse_requirements_and_containers()
return conda_util.requirements_to_conda_targets(requirements)


__all__ = [
"build_conda_context",
"collect_conda_targets",
"tool_source_conda_targets",
]
@@ -14,6 +14,7 @@
urlopen,
)

import planemo.linters.conda_requirements
import planemo.linters.doi
import planemo.linters.urls
import planemo.linters.xsd
@@ -55,6 +56,9 @@ def _lint_extra_modules(**kwds):
if kwds.get("urls", False):
linters.append(planemo.linters.urls)

if kwds.get("conda_requirements", False):
linters.append(planemo.linters.conda_requirements)

return linters


@@ -117,7 +121,7 @@ def lint_xsd(lint_ctx, schema_path, path):
msg = msg % (name, validation_result.output)
lint_ctx.error(msg)
else:
lint_ctx.info("%s found and appears to be valid XML" % name)
lint_ctx.info("File validates against XML schema.")


def lint_urls(root, lint_ctx):
@@ -0,0 +1,29 @@
"""Ensure requirements are matched in best practice conda channels."""

from galaxy.tools.deps.conda_util import best_search_result

from planemo.conda import tool_source_conda_targets

BEST_PRACTICE_CHANNELS = ["conda-forge", "anaconda", "r", "bioconda"]


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)
for conda_target in conda_targets:
(best_hit, exact) = best_search_result(conda_target, channels_override=BEST_PRACTICE_CHANNELS)
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)
@@ -10,6 +10,6 @@ virtualenv
lxml
gxformat2>=0.1.1
ephemeris>=0.2.0
galaxy-lib>=16.10.2
galaxy-lib>=16.10.3
html5lib>=0.9999999,!=0.99999999,!=0.999999999,!=1.0b10,!=1.0b09 ; python_version == '2.7'
cwltool==1.0.20160726135535 ; python_version == '2.7'

0 comments on commit 9da8387

Please sign in to comment.