Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/planemo/tool_lint.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 from __future__ import absolute_import | |
| 2 | |
| 3 from os.path import basename | |
| 4 | |
| 5 from galaxy.tool_util.lint import lint_tool_source | |
| 6 | |
| 7 import planemo.linters.biocontainer_registered | |
| 8 import planemo.linters.conda_requirements | |
| 9 import planemo.linters.doi | |
| 10 import planemo.linters.urls | |
| 11 import planemo.linters.xsd | |
| 12 from planemo.exit_codes import ( | |
| 13 EXIT_CODE_GENERIC_FAILURE, | |
| 14 EXIT_CODE_OK, | |
| 15 ) | |
| 16 from planemo.io import ( | |
| 17 coalesce_return_codes, | |
| 18 error, | |
| 19 info, | |
| 20 ) | |
| 21 from planemo.lint import build_lint_args | |
| 22 from planemo.tools import ( | |
| 23 is_tool_load_error, | |
| 24 yield_tool_sources_on_paths, | |
| 25 ) | |
| 26 | |
| 27 LINTING_TOOL_MESSAGE = "Linting tool %s" | |
| 28 | |
| 29 | |
| 30 def build_tool_lint_args(ctx, **kwds): | |
| 31 lint_args = build_lint_args(ctx, **kwds) | |
| 32 extra_modules = _lint_extra_modules(**kwds) | |
| 33 lint_args["extra_modules"] = extra_modules | |
| 34 return lint_args | |
| 35 | |
| 36 | |
| 37 def lint_tools_on_path(ctx, paths, lint_args, **kwds): | |
| 38 assert_tools = kwds.get("assert_tools", True) | |
| 39 recursive = kwds.get("recursive", False) | |
| 40 exit_codes = [] | |
| 41 for (tool_path, tool_xml) in yield_tool_sources_on_paths(ctx, paths, recursive): | |
| 42 if handle_tool_load_error(tool_path, tool_xml): | |
| 43 exit_codes.append(EXIT_CODE_GENERIC_FAILURE) | |
| 44 continue | |
| 45 info("Linting tool %s" % tool_path) | |
| 46 if not lint_tool_source(tool_xml, name=basename(tool_path), **lint_args): | |
| 47 error("Failed linting") | |
| 48 exit_codes.append(EXIT_CODE_GENERIC_FAILURE) | |
| 49 else: | |
| 50 exit_codes.append(EXIT_CODE_OK) | |
| 51 return coalesce_return_codes(exit_codes, assert_at_least_one=assert_tools) | |
| 52 | |
| 53 | |
| 54 def _lint_extra_modules(**kwds): | |
| 55 linters = [] | |
| 56 if kwds.get("xsd", True): | |
| 57 linters.append(planemo.linters.xsd) | |
| 58 | |
| 59 if kwds.get("doi", False): | |
| 60 linters.append(planemo.linters.doi) | |
| 61 | |
| 62 if kwds.get("urls", False): | |
| 63 linters.append(planemo.linters.urls) | |
| 64 | |
| 65 if kwds.get("conda_requirements", False): | |
| 66 linters.append(planemo.linters.conda_requirements) | |
| 67 | |
| 68 if kwds.get("biocontainer", False): | |
| 69 linters.append(planemo.linters.biocontainer_registered) | |
| 70 | |
| 71 return linters | |
| 72 | |
| 73 | |
| 74 def handle_tool_load_error(tool_path, tool_xml): | |
| 75 """ Return True if tool_xml is tool load error (invalid XML), and | |
| 76 print a helpful error message. | |
| 77 """ | |
| 78 is_error = False | |
| 79 if is_tool_load_error(tool_xml): | |
| 80 info("Could not lint %s due to malformed xml." % tool_path) | |
| 81 is_error = True | |
| 82 return is_error |
