Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/cwl_utils/image_puller.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ def __init__(
cmd: str,
force_pull: bool,
) -> None:
"""Create an ImagePuller."""
"""
Create an ImagePuller.

req already contains any tag that will be used.
"""
self.req = req
self.save_directory = save_directory
self.cmd = cmd
Expand Down Expand Up @@ -86,14 +90,14 @@ def save_docker_image(self) -> None:
class SingularityImagePuller(ImagePuller):
"""Pull docker image with Singularity."""

CHARS_TO_REPLACE = ["/", ":"]
NEW_CHAR = "_"
CHARS_TO_REPLACE = ["_", "/"]
NEW_STRINGS = ["___", "_s_"]
Comment on lines -89 to +94

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @adamnovak ! Thank you for this and the linked PR. I worry that this will cause existing stored images to be ignored. Any idea on how we can diverge less from the previously naming scheme?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One problem that's being solved here is name collisions: it's possible with the previous naming scheme to have two distinct images (mostly pairs like a/b_c and a_b/c) share a cache key.

The obvious way to re-use existing cached images would be to look and see if the files already exist under the old scheme. Maybe that's OK even if there were possible collisions, since we won't create any new collisions and if people have images cached they must have been working.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The obvious way to re-use existing cached images would be to look and see if the files already exist under the old scheme.

yes, please and thank you


def get_image_name(self) -> str:
"""Determine the file name appropriate to the installed version of Singularity."""
image_name = self.req
for char in self.CHARS_TO_REPLACE:
image_name = image_name.replace(char, self.NEW_CHAR)
for char, replacement in zip(self.CHARS_TO_REPLACE, self.NEW_STRINGS):
image_name = image_name.replace(char, replacement)
if is_singularity_version_2_6():
suffix = ".img"
elif is_singularity_version_3_or_newer():
Expand Down
33 changes: 33 additions & 0 deletions src/cwl_utils/tests/test_image_puller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# SPDX-License-Identifier: Apache-2.0
"""Tests for classes for docker-extract."""

from cwl_utils.image_puller import SingularityImagePuller
from cwl_utils.singularity import get_version as get_singularity_version
from cwl_utils.singularity import is_version_2_6 as is_singularity_version_2_6
from cwl_utils.singularity import (
is_version_3_or_newer as is_singularity_version_3_or_newer,
)

from .util import needs_singularity


@needs_singularity
class TestSingularityImagePuller:
"""Tests for SingularityImagePuller."""

def test_get_image_name_matches_cwltool(self) -> None:
"""Make sure image names generated match those expected by cwltool."""
if is_singularity_version_2_6():
suffix = ".img"
elif is_singularity_version_3_or_newer():
suffix = ".sif"
else:
raise Exception(
f"Don't know how to handle this version of singularity: {get_singularity_version()}."
)

def get_name(s: str) -> str:
return SingularityImagePuller(s, None, "", False).get_image_name()

assert get_name("some_name/repo:123") == f"some___name_s_repo:123{suffix}"
assert get_name("some/name_repo:123") == f"some_s_name___repo:123{suffix}"