|
8 | 8 | Tuple, |
9 | 9 | ) |
10 | 10 |
|
| 11 | +from pydantic import BaseModel |
| 12 | + |
11 | 13 | from galaxy import exceptions |
12 | 14 | from galaxy.exceptions import ( |
13 | 15 | InternalServerError, |
|
21 | 23 | ) |
22 | 24 | from galaxy.tool_util.parameters import ( |
23 | 25 | input_models_for_tool_source, |
24 | | - tool_parameter_bundle_from_json, |
25 | | - ToolParameterBundleModel, |
| 26 | + ToolParameterT, |
26 | 27 | ) |
27 | 28 | from galaxy.tool_util.parser import ( |
28 | 29 | get_tool_source, |
29 | 30 | ToolSource, |
30 | 31 | ) |
| 32 | +from galaxy.tool_util.parser.interface import ( |
| 33 | + Citation, |
| 34 | + XrefDict, |
| 35 | +) |
31 | 36 | from galaxy.tools.stock import stock_tool_sources |
32 | 37 | from tool_shed.context import ( |
33 | 38 | ProvidesRepositoriesContext, |
|
41 | 46 | STOCK_TOOL_SOURCES: Optional[Dict[str, Dict[str, ToolSource]]] = None |
42 | 47 |
|
43 | 48 |
|
| 49 | +# parse the tool source with galaxy.util abstractions to provide a bit richer |
| 50 | +# information about the tool than older tool shed abstractions. |
| 51 | +class ParsedTool(BaseModel): |
| 52 | + id: str |
| 53 | + version: Optional[str] |
| 54 | + name: str |
| 55 | + description: Optional[str] |
| 56 | + inputs: List[ToolParameterT] |
| 57 | + citations: List[Citation] |
| 58 | + license: Optional[str] |
| 59 | + profile: Optional[str] |
| 60 | + edam_operations: List[str] |
| 61 | + edam_topics: List[str] |
| 62 | + xrefs: List[XrefDict] |
| 63 | + help: Optional[str] |
| 64 | + |
| 65 | + |
| 66 | +def _parse_tool(tool_source: ToolSource) -> ParsedTool: |
| 67 | + id = tool_source.parse_id() |
| 68 | + version = tool_source.parse_version() |
| 69 | + name = tool_source.parse_name() |
| 70 | + description = tool_source.parse_description() |
| 71 | + inputs = input_models_for_tool_source(tool_source).input_models |
| 72 | + citations = tool_source.parse_citations() |
| 73 | + license = tool_source.parse_license() |
| 74 | + profile = tool_source.parse_profile() |
| 75 | + edam_operations = tool_source.parse_edam_operations() |
| 76 | + edam_topics = tool_source.parse_edam_topics() |
| 77 | + xrefs = tool_source.parse_xrefs() |
| 78 | + help = tool_source.parse_help() |
| 79 | + |
| 80 | + return ParsedTool( |
| 81 | + id=id, |
| 82 | + version=version, |
| 83 | + name=name, |
| 84 | + description=description, |
| 85 | + profile=profile, |
| 86 | + inputs=inputs, |
| 87 | + license=license, |
| 88 | + citations=citations, |
| 89 | + edam_operations=edam_operations, |
| 90 | + edam_topics=edam_topics, |
| 91 | + xrefs=xrefs, |
| 92 | + help=help, |
| 93 | + ) |
| 94 | + |
| 95 | + |
44 | 96 | def search(trans: SessionRequestContext, q: str, page: int = 1, page_size: int = 10) -> dict: |
45 | 97 | """ |
46 | 98 | Perform the search over TS tools index. |
@@ -97,23 +149,23 @@ def get_repository_metadata_tool_dict( |
97 | 149 | raise ObjectNotFound() |
98 | 150 |
|
99 | 151 |
|
100 | | -def tool_input_models_cached_for( |
| 152 | +def parsed_tool_model_cached_for( |
101 | 153 | trans: ProvidesRepositoriesContext, trs_tool_id: str, tool_version: str, repository_clone_url: Optional[str] = None |
102 | | -) -> ToolParameterBundleModel: |
103 | | - tool_state_cache = trans.app.tool_state_cache |
104 | | - raw_json = tool_state_cache.get_cache_entry_for(trs_tool_id, tool_version) |
105 | | - if raw_json is not None: |
106 | | - return tool_parameter_bundle_from_json(raw_json) |
107 | | - bundle = tool_input_models_for(trans, trs_tool_id, tool_version, repository_clone_url=repository_clone_url) |
108 | | - tool_state_cache.insert_cache_entry_for(trs_tool_id, tool_version, bundle.dict()) |
109 | | - return bundle |
| 154 | +) -> ParsedTool: |
| 155 | + model_cache = trans.app.model_cache |
| 156 | + parsed_tool = model_cache.get_cache_entry_for(ParsedTool, trs_tool_id, tool_version) |
| 157 | + if parsed_tool is not None: |
| 158 | + return parsed_tool |
| 159 | + parsed_tool = parsed_tool_model_for(trans, trs_tool_id, tool_version, repository_clone_url=repository_clone_url) |
| 160 | + model_cache.insert_cache_entry_for(parsed_tool, trs_tool_id, tool_version) |
| 161 | + return parsed_tool |
110 | 162 |
|
111 | 163 |
|
112 | | -def tool_input_models_for( |
| 164 | +def parsed_tool_model_for( |
113 | 165 | trans: ProvidesRepositoriesContext, trs_tool_id: str, tool_version: str, repository_clone_url: Optional[str] = None |
114 | | -) -> ToolParameterBundleModel: |
| 166 | +) -> ParsedTool: |
115 | 167 | tool_source = tool_source_for(trans, trs_tool_id, tool_version, repository_clone_url=repository_clone_url) |
116 | | - return input_models_for_tool_source(tool_source) |
| 168 | + return _parse_tool(tool_source) |
117 | 169 |
|
118 | 170 |
|
119 | 171 | def tool_source_for( |
|
0 commit comments