Mercurial > repos > shellac > guppy_basecaller
comparison env/lib/python3.7/site-packages/planemo/tools.py @ 2:6af9afd405e9 draft
"planemo upload commit 0a63dd5f4d38a1f6944587f52a8cd79874177fc1"
| author | shellac |
|---|---|
| date | Thu, 14 May 2020 14:56:58 -0400 |
| parents | 26e78fe6e8c4 |
| children |
comparison
equal
deleted
inserted
replaced
| 1:75ca89e9b81c | 2:6af9afd405e9 |
|---|---|
| 1 """Planemo-specific wrappers around galaxy-tool-util tool functionality.""" | |
| 2 from __future__ import absolute_import | |
| 3 | |
| 4 import os | |
| 5 import sys | |
| 6 import traceback | |
| 7 | |
| 8 from galaxy.tool_util import loader_directory | |
| 9 from galaxy.tool_util.fetcher import ToolLocationFetcher | |
| 10 | |
| 11 from planemo.io import error, info | |
| 12 | |
| 13 is_tool_load_error = loader_directory.is_tool_load_error | |
| 14 SKIP_XML_MESSAGE = "Skipping XML file - does not appear to be a tool %s." | |
| 15 SHED_FILES = ["tool_dependencies.xml", "repository_dependencies.xml"] | |
| 16 LOAD_ERROR_MESSAGE = "Error loading tool with path %s" | |
| 17 | |
| 18 | |
| 19 def uri_to_path(ctx, uri): | |
| 20 fetcher = ToolLocationFetcher() | |
| 21 return fetcher.to_tool_path(uri) | |
| 22 | |
| 23 | |
| 24 def uris_to_paths(ctx, uris): | |
| 25 fetcher = ToolLocationFetcher() | |
| 26 paths = [] | |
| 27 for uri in uris: | |
| 28 path = fetcher.to_tool_path(uri) | |
| 29 paths.append(path) | |
| 30 return paths | |
| 31 | |
| 32 | |
| 33 def yield_tool_sources_on_paths(ctx, paths, recursive=False, yield_load_errors=True, exclude_deprecated=False): | |
| 34 for path in paths: | |
| 35 for (tool_path, tool_source) in yield_tool_sources(ctx, path, recursive, yield_load_errors): | |
| 36 if exclude_deprecated and 'deprecated' in tool_path: | |
| 37 continue | |
| 38 yield (tool_path, tool_source) | |
| 39 | |
| 40 | |
| 41 def yield_tool_sources(ctx, path, recursive=False, yield_load_errors=True): | |
| 42 tools = load_tool_sources_from_path( | |
| 43 path, | |
| 44 recursive, | |
| 45 register_load_errors=True, | |
| 46 ) | |
| 47 for (tool_path, tool_source) in tools: | |
| 48 if is_tool_load_error(tool_source): | |
| 49 if yield_load_errors: | |
| 50 yield (tool_path, tool_source) | |
| 51 else: | |
| 52 error(LOAD_ERROR_MESSAGE % tool_path) | |
| 53 continue | |
| 54 | |
| 55 if not _is_tool_source(ctx, tool_path, tool_source): | |
| 56 continue | |
| 57 yield (tool_path, tool_source) | |
| 58 | |
| 59 | |
| 60 def load_tool_sources_from_path(path, recursive, register_load_errors=False): | |
| 61 """Generator for tool sources on a path.""" | |
| 62 return loader_directory.load_tool_sources_from_path( | |
| 63 path, | |
| 64 _load_exception_handler, | |
| 65 recursive=recursive, | |
| 66 register_load_errors=register_load_errors, | |
| 67 ) | |
| 68 | |
| 69 | |
| 70 def _load_exception_handler(path, exc_info): | |
| 71 error(LOAD_ERROR_MESSAGE % path) | |
| 72 traceback.print_exception(*exc_info, limit=1, file=sys.stderr) | |
| 73 | |
| 74 | |
| 75 def _is_tool_source(ctx, tool_path, tool_source): | |
| 76 if os.path.basename(tool_path) in SHED_FILES: | |
| 77 return False | |
| 78 root = getattr(tool_source, "root", None) | |
| 79 if root is not None: | |
| 80 if root.tag != "tool": | |
| 81 if ctx.verbose: | |
| 82 info(SKIP_XML_MESSAGE % tool_path) | |
| 83 return False | |
| 84 return True | |
| 85 | |
| 86 | |
| 87 __all__ = ( | |
| 88 "is_tool_load_error", | |
| 89 "load_tool_sources_from_path", | |
| 90 "yield_tool_sources", | |
| 91 "yield_tool_sources_on_paths", | |
| 92 ) |
