Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/galaxy/tool_util/deps/container_resolvers/explicit.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 describes the :class:`ExplicitContainerResolver` ContainerResolver plugin.""" | |
2 import logging | |
3 | |
4 from ..container_resolvers import ( | |
5 ContainerResolver, | |
6 ) | |
7 from ..requirements import ContainerDescription | |
8 | |
9 log = logging.getLogger(__name__) | |
10 | |
11 DEFAULT_SHELL = "/bin/bash" | |
12 | |
13 | |
14 class ExplicitContainerResolver(ContainerResolver): | |
15 """Find explicit containers referenced in the tool description (e.g. tool XML file) if present.""" | |
16 | |
17 resolver_type = "explicit" | |
18 | |
19 def resolve(self, enabled_container_types, tool_info, **kwds): | |
20 """Find a container explicitly mentioned in tool description. | |
21 | |
22 This ignores the tool requirements and assumes the tool author crafted | |
23 a correct container. | |
24 """ | |
25 for container_description in tool_info.container_descriptions: | |
26 if self._container_type_enabled(container_description, enabled_container_types): | |
27 container_description.explicit = True | |
28 return container_description | |
29 | |
30 return None | |
31 | |
32 | |
33 class ExplicitSingularityContainerResolver(ExplicitContainerResolver): | |
34 | |
35 resolver_type = 'explicit_singularity' | |
36 container_type = 'singularity' | |
37 | |
38 def resolve(self, enabled_container_types, tool_info, **kwds): | |
39 """Find a container explicitly mentioned in tool description. | |
40 | |
41 This ignores the tool requirements and assumes the tool author crafted | |
42 a correct container. We use singularity here to fetch docker containers, | |
43 hence the container_description hack here. | |
44 """ | |
45 for container_description in tool_info.container_descriptions: | |
46 if container_description.type == 'docker': | |
47 desc_dict = container_description.to_dict() | |
48 desc_dict['type'] = self.container_type | |
49 desc_dict['identifier'] = "docker://%s" % container_description.identifier | |
50 container_description = container_description.from_dict(desc_dict) | |
51 if self._container_type_enabled(container_description, enabled_container_types): | |
52 return container_description | |
53 | |
54 return None | |
55 | |
56 | |
57 class BaseAdminConfiguredContainerResolver(ContainerResolver): | |
58 | |
59 def __init__(self, app_info=None, shell=DEFAULT_SHELL, **kwds): | |
60 super().__init__(app_info, **kwds) | |
61 self.shell = shell | |
62 | |
63 def _container_description(self, identifier, container_type): | |
64 container_description = ContainerDescription( | |
65 identifier, | |
66 type=container_type, | |
67 shell=self.shell, | |
68 ) | |
69 return container_description | |
70 | |
71 | |
72 class FallbackContainerResolver(BaseAdminConfiguredContainerResolver): | |
73 """Specify an explicit, identified container as a Docker container resolver.""" | |
74 | |
75 resolver_type = "fallback" | |
76 container_type = 'docker' | |
77 | |
78 def __init__(self, app_info=None, identifier="", **kwds): | |
79 super().__init__(app_info, **kwds) | |
80 assert identifier, "fallback container resolver must be specified with non-empty identifier" | |
81 self.identifier = identifier | |
82 | |
83 def _match(self, enabled_container_types, tool_info, container_description): | |
84 if self._container_type_enabled(container_description, enabled_container_types): | |
85 return True | |
86 return False | |
87 | |
88 def resolve(self, enabled_container_types, tool_info, **kwds): | |
89 container_description = self._container_description(self.identifier, self.container_type) | |
90 if self._match(enabled_container_types, tool_info, container_description): | |
91 return container_description | |
92 | |
93 | |
94 class FallbackSingularityContainerResolver(FallbackContainerResolver): | |
95 """Specify an explicit, identified container as a Singularity container resolver.""" | |
96 | |
97 resolver_type = "fallback_singularity" | |
98 container_type = 'singularity' | |
99 | |
100 | |
101 class FallbackNoRequirementsContainerResolver(FallbackContainerResolver): | |
102 | |
103 resolver_type = "fallback_no_requirements" | |
104 | |
105 def _match(self, enabled_container_types, tool_info, container_description): | |
106 type_matches = super()._match(enabled_container_types, tool_info, container_description) | |
107 return type_matches and (tool_info.requirements is None or len(tool_info.requirements) == 0) | |
108 | |
109 | |
110 class FallbackNoRequirementsSingularityContainerResolver(FallbackNoRequirementsContainerResolver): | |
111 | |
112 resolver_type = "fallback_no_requirements_singularity" | |
113 container_type = 'singularity' | |
114 | |
115 | |
116 class RequiresGalaxyEnvironmentContainerResolver(FallbackContainerResolver): | |
117 | |
118 resolver_type = "requires_galaxy_environment" | |
119 | |
120 def _match(self, enabled_container_types, tool_info, container_description): | |
121 type_matches = super()._match(enabled_container_types, tool_info, container_description) | |
122 return type_matches and tool_info.requires_galaxy_python_environment | |
123 | |
124 | |
125 class RequiresGalaxyEnvironmentSingularityContainerResolver(RequiresGalaxyEnvironmentContainerResolver): | |
126 | |
127 resolver_type = "requires_galaxy_environment_singularity" | |
128 container_type = 'singularity' | |
129 | |
130 | |
131 class MappingContainerResolver(BaseAdminConfiguredContainerResolver): | |
132 resolver_type = "mapping" | |
133 | |
134 def __init__(self, app_info=None, **kwds): | |
135 super().__init__(app_info, **kwds) | |
136 mappings = self.resolver_kwds["mappings"] | |
137 assert isinstance(mappings, list), "mapping container resolver must be specified with mapping list" | |
138 self.mappings = mappings | |
139 | |
140 def resolve(self, enabled_container_types, tool_info, **kwds): | |
141 tool_id = tool_info.tool_id | |
142 # If resolving against dependencies and not a specific tool, skip over this resolver | |
143 if not tool_id: | |
144 return | |
145 | |
146 tool_version = tool_info.tool_version | |
147 | |
148 for mapping in self.mappings: | |
149 if mapping.get("tool_id") != tool_id: | |
150 continue | |
151 | |
152 mapping_tool_version = mapping.get("tool_version") | |
153 if mapping_tool_version is not None and tool_version != mapping_tool_version: | |
154 continue | |
155 | |
156 container_description = self._container_description(mapping["identifier"], mapping.get("container_type")) | |
157 if not self._container_type_enabled(container_description, enabled_container_types): | |
158 continue | |
159 return container_description | |
160 | |
161 | |
162 __all__ = ( | |
163 "ExplicitContainerResolver", | |
164 "ExplicitSingularityContainerResolver", | |
165 "FallbackContainerResolver", | |
166 "FallbackSingularityContainerResolver", | |
167 "FallbackNoRequirementsContainerResolver", | |
168 "FallbackNoRequirementsSingularityContainerResolver", | |
169 "MappingContainerResolver", | |
170 "RequiresGalaxyEnvironmentContainerResolver", | |
171 "RequiresGalaxyEnvironmentSingularityContainerResolver", | |
172 ) |