|
19 | 19 | from typing import ( |
20 | 20 | Any, |
21 | 21 | Dict, |
22 | | - Iterable, |
23 | 22 | List, |
24 | 23 | Optional, |
25 | 24 | Set, |
26 | 25 | TYPE_CHECKING, |
27 | 26 | ) |
28 | 27 |
|
| 28 | +from gxjobconfinit.generate import ( |
| 29 | + build_job_config, |
| 30 | + ConfigArgs, |
| 31 | + create_docker_volumes, |
| 32 | +) |
| 33 | +from gxjobconfinit.generate import DevelopmentContext |
| 34 | + |
29 | 35 | from galaxy.tool_util.deps import docker_util |
30 | | -from galaxy.tool_util.deps.container_volumes import DockerVolume |
31 | 36 | from galaxy.util.commands import argv_to_str |
32 | 37 | from packaging.version import parse as parse_version |
33 | 38 |
|
|
122 | 127 | </tool_sheds> |
123 | 128 | """ |
124 | 129 |
|
125 | | -JOB_CONFIG_LOCAL = """<job_conf> |
126 | | - <plugins> |
127 | | - <plugin id="planemo_runner" type="runner" load="galaxy.jobs.runners.local:LocalJobRunner" workers="4"/> |
128 | | - </plugins> |
129 | | - <handlers> |
130 | | - </handlers> |
131 | | - <destinations default="planemo_dest"> |
132 | | - <destination id="planemo_dest" runner="planemo_runner"> |
133 | | - <param id="require_container">${require_container}</param> |
134 | | - <param id="docker_enabled">${docker_enable}</param> |
135 | | - <param id="docker_sudo">${docker_sudo}</param> |
136 | | - <param id="docker_sudo_cmd">${docker_sudo_cmd}</param> |
137 | | - <param id="docker_cmd">${docker_cmd}</param> |
138 | | - <param id="docker_volumes">${docker_volumes}</param> |
139 | | - <param id="docker_run_extra_arguments"><![CDATA[${docker_run_extra_arguments}]]></param> |
140 | | - ${docker_host_param} |
141 | | - </destination> |
142 | | - <destination id="upload_dest" runner="planemo_runner"> |
143 | | - <param id="docker_enabled">false</param> |
144 | | - </destination> |
145 | | - </destinations> |
146 | | - <tools> |
147 | | - <tool id="upload1" destination="upload_dest" /> |
148 | | - </tools> |
149 | | -</job_conf> |
150 | | -""" |
151 | | - |
152 | 130 | REFGENIE_CONFIG_TEMPLATE = """ |
153 | 131 | config_version: %s |
154 | 132 | genome_folder: '%s' |
@@ -216,22 +194,6 @@ def read_log(ctx, log_path, e: threading.Event): |
216 | 194 | log_fh.close() |
217 | 195 |
|
218 | 196 |
|
219 | | -def create_docker_volumes(paths: Iterable[str]) -> Iterable[DockerVolume]: |
220 | | - """ |
221 | | - Creates string of the format "host_path:target_path:mode" and deduplicates overlapping mounts. |
222 | | - """ |
223 | | - docker_volumes: Dict[str, DockerVolume] = {} |
224 | | - for path in paths: |
225 | | - docker_volume = DockerVolume.from_str(path) |
226 | | - if docker_volume.path in docker_volumes: |
227 | | - # volume has been specified already, make sure we use "rw" if any of the modes are "rw" |
228 | | - if docker_volume.mode == "rw" or docker_volumes[docker_volume.path].mode == "rw": |
229 | | - docker_volumes[docker_volume.path].mode = "rw" |
230 | | - else: |
231 | | - docker_volumes[docker_volume.path] = docker_volume |
232 | | - return docker_volumes.values() |
233 | | - |
234 | | - |
235 | 197 | @contextlib.contextmanager |
236 | 198 | def docker_galaxy_config(ctx, runnables, for_tests=False, **kwds): |
237 | 199 | """Set up a ``GalaxyConfig`` for Docker container.""" |
@@ -572,6 +534,12 @@ def get_refgenie_config(galaxy_root, refgenie_dir): |
572 | 534 | return REFGENIE_CONFIG_TEMPLATE % (config_version, refgenie_dir) |
573 | 535 |
|
574 | 536 |
|
| 537 | +def get_all_tool_path_from_kwds(runnables: List["Runnable"], **kwds) -> Set[str]: |
| 538 | + galaxy_root = kwds.get("galaxy_root") |
| 539 | + extra_tools = kwds.get("extra_tools") |
| 540 | + return _all_tool_paths(runnables, galaxy_root, extra_tools) |
| 541 | + |
| 542 | + |
575 | 543 | def _all_tool_paths( |
576 | 544 | runnables: List["Runnable"], galaxy_root: Optional[str] = None, extra_tools: Optional[List[str]] = None |
577 | 545 | ) -> Set[str]: |
@@ -1378,40 +1346,15 @@ def _handle_job_config_file( |
1378 | 1346 | ): |
1379 | 1347 | job_config_file = kwds.get("job_config_file", None) |
1380 | 1348 | if not job_config_file: |
1381 | | - template_str = JOB_CONFIG_LOCAL |
| 1349 | + dev_context = DevelopmentContext( |
| 1350 | + test_data_dir, |
| 1351 | + all_tool_paths, |
| 1352 | + ) |
| 1353 | + init_config = ConfigArgs.from_dict(**kwds) |
| 1354 | + conf_contents = build_job_config(init_config, dev_context) |
1382 | 1355 | job_config_file = os.path.join( |
1383 | 1356 | config_directory, |
1384 | | - "job_conf.xml", |
1385 | | - ) |
1386 | | - docker_enable = str(kwds.get("docker", False)) |
1387 | | - docker_host = kwds.get("docker_host", docker_util.DEFAULT_HOST) |
1388 | | - docker_host_param = "" |
1389 | | - if docker_host: |
1390 | | - docker_host_param = f"""<param id="docker_host">{docker_host}</param>""" |
1391 | | - |
1392 | | - volumes = list(kwds.get("docker_extra_volume") or []) |
1393 | | - if test_data_dir: |
1394 | | - volumes.append(f"{test_data_dir}:ro") |
1395 | | - |
1396 | | - docker_volumes_str = "$defaults" |
1397 | | - if volumes: |
1398 | | - # exclude tool directories, these are mounted :ro by $defaults |
1399 | | - all_tool_dirs = {os.path.dirname(tool_path) for tool_path in all_tool_paths} |
1400 | | - extra_volumes_str = ",".join(str(v) for v in create_docker_volumes(volumes) if v.path not in all_tool_dirs) |
1401 | | - docker_volumes_str = f"{docker_volumes_str},{extra_volumes_str}" |
1402 | | - |
1403 | | - conf_contents = Template(template_str).safe_substitute( |
1404 | | - { |
1405 | | - "server_name": server_name, |
1406 | | - "docker_enable": docker_enable, |
1407 | | - "require_container": "false", |
1408 | | - "docker_sudo": str(kwds.get("docker_sudo", False)), |
1409 | | - "docker_sudo_cmd": str(kwds.get("docker_sudo_cmd", docker_util.DEFAULT_SUDO_COMMAND)), |
1410 | | - "docker_cmd": str(kwds.get("docker_cmd", docker_util.DEFAULT_DOCKER_COMMAND)), |
1411 | | - "docker_host_param": docker_host_param, |
1412 | | - "docker_volumes": docker_volumes_str, |
1413 | | - "docker_run_extra_arguments": kwds.get("docker_run_extra_arguments", ""), |
1414 | | - } |
| 1357 | + "job_conf.yml", |
1415 | 1358 | ) |
1416 | 1359 | write_file(job_config_file, conf_contents) |
1417 | 1360 | kwds["job_config_file"] = job_config_file |
|
0 commit comments