diff --git a/src/cloudai/_core/installables.py b/src/cloudai/_core/installables.py index 924655733..e578190f7 100644 --- a/src/cloudai/_core/installables.py +++ b/src/cloudai/_core/installables.py @@ -78,6 +78,9 @@ def installed_path(self) -> Union[str, Path]: """Return the cached path or URL of the docker image.""" if self._installed_path: return self._installed_path.absolute() if isinstance(self._installed_path, Path) else self._installed_path + local_image_path = Path(self.url) + if local_image_path.is_absolute() or self.url.startswith("."): + return local_image_path.absolute() return self.url @installed_path.setter diff --git a/tests/systems/slurm/test_installer.py b/tests/systems/slurm/test_installer.py index 2c09ddc25..8cf6ecaa0 100644 --- a/tests/systems/slurm/test_installer.py +++ b/tests/systems/slurm/test_installer.py @@ -368,3 +368,17 @@ def test_mark_as_installed_local_container(slurm_system: SlurmSystem): installer.mark_as_installed_one(docker_image) assert docker_image.installed_path == local_image.absolute() + + +def test_mark_as_installed_duplicate_local_containers_preserve_local_path(slurm_system: SlurmSystem): + installer = SlurmInstaller(slurm_system) + + local_image = Path("/tmp/local_image.sqsh") + first = DockerImage(url=str(local_image)) + second = DockerImage(url=str(local_image)) + + result = installer.mark_as_installed([first, second]) + + assert result.success + assert first.installed_path == local_image + assert second.installed_path == local_image