Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/galaxy/tool_util/parser/factory.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 """Constructors for concrete tool and input source objects.""" | |
2 | |
3 import logging | |
4 | |
5 from galaxy.tool_util.loader import load_tool_with_refereces | |
6 from galaxy.util.yaml_util import ordered_load | |
7 from .cwl import CwlToolSource | |
8 from .interface import InputSource | |
9 from .xml import XmlInputSource, XmlToolSource | |
10 from .yaml import YamlInputSource, YamlToolSource | |
11 from ..fetcher import ToolLocationFetcher | |
12 | |
13 log = logging.getLogger(__name__) | |
14 | |
15 | |
16 def get_tool_source(config_file=None, xml_tree=None, enable_beta_formats=True, tool_location_fetcher=None, macro_paths=None): | |
17 """Return a ToolSource object corresponding to supplied source. | |
18 | |
19 The supplied source may be specified as a file path (using the config_file | |
20 parameter) or as an XML object loaded with load_tool_with_refereces. | |
21 """ | |
22 if xml_tree is not None: | |
23 return XmlToolSource(xml_tree, source_path=config_file, macro_paths=macro_paths) | |
24 elif config_file is None: | |
25 raise ValueError("get_tool_source called with invalid config_file None.") | |
26 | |
27 if tool_location_fetcher is None: | |
28 tool_location_fetcher = ToolLocationFetcher() | |
29 | |
30 config_file = tool_location_fetcher.to_tool_path(config_file) | |
31 if not enable_beta_formats: | |
32 tree, macro_paths = load_tool_with_refereces(config_file) | |
33 return XmlToolSource(tree, source_path=config_file, macro_paths=macro_paths) | |
34 | |
35 if config_file.endswith(".yml"): | |
36 log.info("Loading tool from YAML - this is experimental - tool will not function in future.") | |
37 with open(config_file) as f: | |
38 as_dict = ordered_load(f) | |
39 return YamlToolSource(as_dict, source_path=config_file) | |
40 elif config_file.endswith(".json") or config_file.endswith(".cwl"): | |
41 log.info("Loading CWL tool - this is experimental - tool likely will not function in future at least in same way.") | |
42 return CwlToolSource(config_file) | |
43 else: | |
44 tree, macro_paths = load_tool_with_refereces(config_file) | |
45 return XmlToolSource(tree, source_path=config_file, macro_paths=macro_paths) | |
46 | |
47 | |
48 def get_tool_source_from_representation(tool_format, tool_representation): | |
49 # TODO: make sure whatever is consuming this method uses ordered load. | |
50 log.info("Loading dynamic tool - this is experimental - tool may not function in future.") | |
51 if tool_format == "GalaxyTool": | |
52 if "version" not in tool_representation: | |
53 tool_representation["version"] = "1.0.0" # Don't require version for embedded tools. | |
54 return YamlToolSource(tool_representation) | |
55 else: | |
56 raise Exception("Unknown tool representation format [%s]." % tool_format) | |
57 | |
58 | |
59 def get_input_source(content): | |
60 """Wrap dicts or XML elements as InputSource if needed. | |
61 | |
62 If the supplied content is already an InputSource object, | |
63 it is simply returned. This allow Galaxy to uniformly | |
64 consume using the tool input source interface. | |
65 """ | |
66 if not isinstance(content, InputSource): | |
67 if isinstance(content, dict): | |
68 content = YamlInputSource(content) | |
69 else: | |
70 content = XmlInputSource(content) | |
71 return content | |
72 | |
73 | |
74 __all__ = ("get_tool_source", "get_input_source") |