Mercurial > repos > shellac > sam_consensus_v3
comparison 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 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:4f3585e2f14b |
|---|---|
| 1 """This module contains a linting functions for general aspects of the tool.""" | |
| 2 import re | |
| 3 | |
| 4 import packaging.version | |
| 5 | |
| 6 ERROR_VERSION_MSG = "Tool version is missing or empty." | |
| 7 WARN_VERSION_MSG = "Tool version [%s] is not compliant with PEP 440." | |
| 8 VALID_VERSION_MSG = "Tool defines a version [%s]." | |
| 9 | |
| 10 ERROR_NAME_MSG = "Tool name is missing or empty." | |
| 11 VALID_NAME_MSG = "Tool defines a name [%s]." | |
| 12 | |
| 13 ERROR_ID_MSG = "Tool does not define an id attribute." | |
| 14 VALID_ID_MSG = "Tool defines an id [%s]." | |
| 15 | |
| 16 PROFILE_PATTERN = re.compile(r"^[1,2]\d\.[0,1]\d$") | |
| 17 PROFILE_INFO_DEFAULT_MSG = "Tool targets 16.01 Galaxy profile." | |
| 18 PROFILE_INFO_SPECIFIED_MSG = "Tool specifies profile version [%s]." | |
| 19 PROFILE_INVALID_MSG = "Tool specifies an invalid profile version [%s]." | |
| 20 | |
| 21 lint_tool_types = ["*"] | |
| 22 | |
| 23 | |
| 24 def lint_general(tool_source, lint_ctx): | |
| 25 """Check tool version, name, and id.""" | |
| 26 version = tool_source.parse_version() or '' | |
| 27 parsed_version = packaging.version.parse(version) | |
| 28 if not version: | |
| 29 lint_ctx.error(ERROR_VERSION_MSG) | |
| 30 elif isinstance(parsed_version, packaging.version.LegacyVersion): | |
| 31 lint_ctx.warn(WARN_VERSION_MSG % version) | |
| 32 else: | |
| 33 lint_ctx.valid(VALID_VERSION_MSG % version) | |
| 34 | |
| 35 name = tool_source.parse_name() | |
| 36 if not name: | |
| 37 lint_ctx.error(ERROR_NAME_MSG) | |
| 38 else: | |
| 39 lint_ctx.valid(VALID_NAME_MSG % name) | |
| 40 | |
| 41 tool_id = tool_source.parse_id() | |
| 42 if not tool_id: | |
| 43 lint_ctx.error(ERROR_ID_MSG) | |
| 44 else: | |
| 45 lint_ctx.valid(VALID_ID_MSG % tool_id) | |
| 46 | |
| 47 profile = tool_source.parse_profile() | |
| 48 profile_valid = PROFILE_PATTERN.match(profile) is not None | |
| 49 if not profile_valid: | |
| 50 lint_ctx.warn(PROFILE_INVALID_MSG) | |
| 51 elif profile == "16.01": | |
| 52 lint_ctx.valid(PROFILE_INFO_DEFAULT_MSG) | |
| 53 else: | |
| 54 lint_ctx.valid(PROFILE_INFO_SPECIFIED_MSG % profile) | |
| 55 | |
| 56 if re.search(r"\s", tool_id): | |
| 57 lint_ctx.warn("Tool id contains a space - this is discouraged.") |
