diff env/lib/python3.7/site-packages/planemo/linters/conda_requirements.py @ 2:6af9afd405e9 draft

"planemo upload commit 0a63dd5f4d38a1f6944587f52a8cd79874177fc1"
author shellac
date Thu, 14 May 2020 14:56:58 -0400
parents 26e78fe6e8c4
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/env/lib/python3.7/site-packages/planemo/linters/conda_requirements.py	Thu May 14 14:56:58 2020 -0400
@@ -0,0 +1,35 @@
+"""Ensure requirements are matched in best practice conda channels."""
+
+from planemo.conda import (
+    BEST_PRACTICE_CHANNELS,
+    best_practice_search,
+    tool_source_conda_targets,
+)
+
+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)