From e09cba3d477150c72e53c4d0aa08552ab0ccc37d Mon Sep 17 00:00:00 2001 From: Matthias Bernt Date: Wed, 30 Oct 2024 14:02:42 +0100 Subject: [PATCH] restructure to make roundtrip testable The combination - preprocess_volumes which creates Volume objects and creates strings again in the end and - creation of DockerVolumes which are only temporary and are soon converted to str again confused me and needed testing IMO. Also code was redundant. --- .../tool_util/deps/container_classes.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/galaxy/tool_util/deps/container_classes.py b/lib/galaxy/tool_util/deps/container_classes.py index 5d597d1979ee..eefc3f7bf288 100644 --- a/lib/galaxy/tool_util/deps/container_classes.py +++ b/lib/galaxy/tool_util/deps/container_classes.py @@ -406,6 +406,18 @@ def add_var(name, value): return volumes_str +def _parse_volumes(volumes_raw: str, container_type: str) -> List[DockerVolume]: + """ + >>> volumes_raw = "$galaxy_root:ro,$tool_directory:ro,$job_directory:ro,$working_directory:z,$default_file_path:z" + >>> volumes = _parse_volumes(volumes_raw, "docker") + >>> [str(v) for v in volumes] + ['"$galaxy_root:$galaxy_root:ro"', '"$tool_directory:$tool_directory:ro"', '"$job_directory:$job_directory:ro"', '"$working_directory:$working_directory:z"', '"$default_file_path:$default_file_path:z"'] + """ + preprocessed_volumes_list = preprocess_volumes(volumes_raw, container_type) + # TODO: Remove redundant volumes... + return [DockerVolume.from_str(v) for v in preprocessed_volumes_list] + + class DockerContainer(Container, HasDockerLikeVolumes): container_type = DOCKER_CONTAINER_TYPE @@ -445,9 +457,7 @@ def containerize_command(self, command: str) -> str: raise Exception(f"Cannot containerize command [{working_directory}] without defined working directory.") volumes_raw = self._expand_volume_str(self.destination_info.get("docker_volumes", "$defaults")) - preprocessed_volumes_list = preprocess_volumes(volumes_raw, self.container_type) - # TODO: Remove redundant volumes... - volumes = [DockerVolume.from_str(v) for v in preprocessed_volumes_list] + volumes = _parse_volumes(volumes_raw, self.container_type) volumes_from = self.destination_info.get("docker_volumes_from", docker_util.DEFAULT_VOLUMES_FROM) docker_host_props = self.docker_host_props @@ -566,8 +576,7 @@ def containerize_command(self, command: str) -> str: raise Exception(f"Cannot containerize command [{working_directory}] without defined working directory.") volumes_raw = self._expand_volume_str(self.destination_info.get("singularity_volumes", "$defaults")) - preprocessed_volumes_list = preprocess_volumes(volumes_raw, self.container_type) - volumes = [DockerVolume.from_str(v) for v in preprocessed_volumes_list] + volumes = _parse_volumes(volumes_raw, self.container_type) run_command = singularity_util.build_singularity_run_command( command,