Skip to content

Commit c3542c7

Browse files
authored
Merge pull request #202 from NVIDIA/am/abs-docker-path
Always return an absolute path to cached docker image
2 parents 178a80e + c0a0dc8 commit c3542c7

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/cloudai/util/docker_image_cache_manager.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def __init__(self, success: bool, docker_image_path: Optional[Path] = None, mess
8282
message (str): A message providing additional information about the result.
8383
"""
8484
self.success = success
85-
self.docker_image_path = docker_image_path or Path()
85+
self._docker_image_path = docker_image_path or Path()
8686
self.message = message
8787

8888
def __bool__(self):
@@ -103,6 +103,26 @@ def __str__(self):
103103
"""
104104
return self.message
105105

106+
@property
107+
def docker_image_path(self) -> Path:
108+
"""
109+
Get the path to the Docker image.
110+
111+
Returns
112+
Path: Absolute path to the Docker image.
113+
"""
114+
return self._docker_image_path.absolute()
115+
116+
@docker_image_path.setter
117+
def docker_image_path(self, value: Path) -> None:
118+
"""
119+
Set the path to the Docker image.
120+
121+
Args:
122+
value (Path): The path to the Docker image.
123+
"""
124+
self._docker_image_path = value
125+
106126

107127
class DockerImageCacheManager:
108128
"""

tests/test_docker_image_cache_manager.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,3 +299,11 @@ def test_check_docker_image_accessibility_with_enroot(mock_tempdir, mock_which,
299299
command = mock_popen.call_args[0][0]
300300
assert "enroot import -o" in command
301301
assert "docker://docker.io/hello-world" in command
302+
303+
304+
def test_docker_image_path_is_always_absolute():
305+
r = DockerImageCacheResult(True, Path("relative/path"), "message")
306+
assert r.docker_image_path.is_absolute()
307+
308+
r.docker_image_path = Path("another/relative/path")
309+
assert r.docker_image_path.is_absolute()

0 commit comments

Comments
 (0)