diff --git a/craft_providers/base.py b/craft_providers/base.py index d8b4477f3..844c5b9c0 100644 --- a/craft_providers/base.py +++ b/craft_providers/base.py @@ -846,22 +846,24 @@ def _mount_shared_cache_dirs(self, executor: Executor) -> None: ) guest_base_cache_path = pathlib.Path(guest_cache_proc.stdout) - # PIP cache - host_pip_cache_path = host_base_cache_path / "pip" - host_pip_cache_path.mkdir(parents=True, exist_ok=True) + for tool in ("pip", "uv"): + host_tool_cache_path = host_base_cache_path / tool + host_tool_cache_path.mkdir(parents=True, exist_ok=True) - guest_pip_cache_path = guest_base_cache_path / "pip" - executor.execute_run( - ["mkdir", "-p", guest_pip_cache_path.as_posix()], - ) - - try: - executor.mount(host_source=host_pip_cache_path, target=guest_pip_cache_path) - except ProviderError as exc: - logger.warning( - "Failed to mount cache in instance. Proceeding without cache." + guest_tool_cache_path = guest_base_cache_path / tool + executor.execute_run( + ["mkdir", "-p", guest_tool_cache_path.as_posix()], ) - logger.debug(exc) + + try: + executor.mount( + host_source=host_tool_cache_path, target=guest_tool_cache_path + ) + except ProviderError as exc: + logger.warning( + "Failed to mount cache in instance. Proceeding without cache." + ) + logger.debug(exc) def _pre_setup_packages(self, executor: Executor) -> None: """Do anything before setting up the packages. diff --git a/tests/unit/bases/test_ubuntu_buildd.py b/tests/unit/bases/test_ubuntu_buildd.py index 6469f64a2..cc46e9a42 100644 --- a/tests/unit/bases/test_ubuntu_buildd.py +++ b/tests/unit/bases/test_ubuntu_buildd.py @@ -706,14 +706,18 @@ def test_mount_cache_dirs(fake_process, fake_executor, cache_path: pathlib.Path, fake_process.register( [*DEFAULT_FAKE_CMD, "mkdir", "-p", "/root/.cache/pip"], ) + fake_process.register( + [*DEFAULT_FAKE_CMD, "mkdir", "-p", "/root/.cache/uv"], + ) base._mount_shared_cache_dirs(fake_executor) expected_mounts = [ { - "host_source": host_cache_dir / "pip", - "target": user_cache_dir / "pip", - }, + "host_source": host_cache_dir / tool, + "target": user_cache_dir / tool, + } + for tool in ("pip", "uv") ] assert fake_executor.records_of_mount == expected_mounts diff --git a/tests/unit/test_base.py b/tests/unit/test_base.py index a1cada869..f8a0c9be4 100644 --- a/tests/unit/test_base.py +++ b/tests/unit/test_base.py @@ -155,14 +155,23 @@ def test_mount_shared_cache_dirs(fake_process, fake_base, fake_executor, cache_d fake_process.register( [*DEFAULT_FAKE_CMD, "mkdir", "-p", "/root/.cache/pip"], ) + fake_process.register( + [*DEFAULT_FAKE_CMD, "mkdir", "-p", "/root/.cache/uv"], + ) fake_base._mount_shared_cache_dirs(fake_executor) - expected = { - "host_source": cache_dir.resolve() / "base-v7" / "FakeBaseAlias.TREBLE" / "pip", - "target": user_cache_dir / "pip", - } - assert fake_executor.records_of_mount == [expected] + expected = [ + { + "host_source": cache_dir.resolve() + / "base-v7" + / "FakeBaseAlias.TREBLE" + / tool, + "target": user_cache_dir / tool, + } + for tool in ("pip", "uv") + ] + assert fake_executor.records_of_mount == expected @pytest.mark.parametrize("cache_dir", [pathlib.Path("/tmp/fake-cache-dir")]) @@ -181,6 +190,9 @@ def test_mount_shared_cache_dirs_mkdir_failed( fake_process.register( [*DEFAULT_FAKE_CMD, "mkdir", "-p", "/root/.cache/pip"], ) + fake_process.register( + [*DEFAULT_FAKE_CMD, "mkdir", "-p", "/root/.cache/uv"], + ) mocker.patch("pathlib.Path.mkdir", side_effect=OSError) @@ -205,6 +217,9 @@ def test_mount_shared_cache_dirs_mount_failed( fake_process.register( [*DEFAULT_FAKE_CMD, "mkdir", "-p", "/root/.cache/pip"], ) + fake_process.register( + [*DEFAULT_FAKE_CMD, "mkdir", "-p", "/root/.cache/uv"], + ) mocker.patch("pathlib.Path.mkdir") # don't try to create the directory mocker.patch.object(fake_executor, "mount", side_effect=ProviderError(error_msg))