Skip to content

Commit

Permalink
restructure to make roundtrip testable
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bernt-matthias committed Oct 30, 2024
1 parent 2d7cd6f commit e09cba3
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions lib/galaxy/tool_util/deps/container_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit e09cba3

Please sign in to comment.