diff env/lib/python3.9/site-packages/galaxy/tool_util/linters/general.py @ 0:4f3585e2f14b draft default tip

"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author shellac
date Mon, 22 Mar 2021 18:12:50 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/env/lib/python3.9/site-packages/galaxy/tool_util/linters/general.py	Mon Mar 22 18:12:50 2021 +0000
@@ -0,0 +1,57 @@
+"""This module contains a linting functions for general aspects of the tool."""
+import re
+
+import packaging.version
+
+ERROR_VERSION_MSG = "Tool version is missing or empty."
+WARN_VERSION_MSG = "Tool version [%s] is not compliant with PEP 440."
+VALID_VERSION_MSG = "Tool defines a version [%s]."
+
+ERROR_NAME_MSG = "Tool name is missing or empty."
+VALID_NAME_MSG = "Tool defines a name [%s]."
+
+ERROR_ID_MSG = "Tool does not define an id attribute."
+VALID_ID_MSG = "Tool defines an id [%s]."
+
+PROFILE_PATTERN = re.compile(r"^[1,2]\d\.[0,1]\d$")
+PROFILE_INFO_DEFAULT_MSG = "Tool targets 16.01 Galaxy profile."
+PROFILE_INFO_SPECIFIED_MSG = "Tool specifies profile version [%s]."
+PROFILE_INVALID_MSG = "Tool specifies an invalid profile version [%s]."
+
+lint_tool_types = ["*"]
+
+
+def lint_general(tool_source, lint_ctx):
+    """Check tool version, name, and id."""
+    version = tool_source.parse_version() or ''
+    parsed_version = packaging.version.parse(version)
+    if not version:
+        lint_ctx.error(ERROR_VERSION_MSG)
+    elif isinstance(parsed_version, packaging.version.LegacyVersion):
+        lint_ctx.warn(WARN_VERSION_MSG % version)
+    else:
+        lint_ctx.valid(VALID_VERSION_MSG % version)
+
+    name = tool_source.parse_name()
+    if not name:
+        lint_ctx.error(ERROR_NAME_MSG)
+    else:
+        lint_ctx.valid(VALID_NAME_MSG % name)
+
+    tool_id = tool_source.parse_id()
+    if not tool_id:
+        lint_ctx.error(ERROR_ID_MSG)
+    else:
+        lint_ctx.valid(VALID_ID_MSG % tool_id)
+
+    profile = tool_source.parse_profile()
+    profile_valid = PROFILE_PATTERN.match(profile) is not None
+    if not profile_valid:
+        lint_ctx.warn(PROFILE_INVALID_MSG)
+    elif profile == "16.01":
+        lint_ctx.valid(PROFILE_INFO_DEFAULT_MSG)
+    else:
+        lint_ctx.valid(PROFILE_INFO_SPECIFIED_MSG % profile)
+
+    if re.search(r"\s", tool_id):
+        lint_ctx.warn("Tool id contains a space - this is discouraged.")