Commit d9eab03d by David Hotham Committed by Randy Döring

Use locally cached wheels during install

parent ceb35868
...@@ -25,15 +25,10 @@ class Chef: ...@@ -25,15 +25,10 @@ class Chef:
Path(config.get("cache-dir")).expanduser().joinpath("artifacts") Path(config.get("cache-dir")).expanduser().joinpath("artifacts")
) )
def get_cached_archive_for_link(self, link: Link) -> Link: def get_cached_archive_for_link(self, link: Link) -> Link | None:
# If the archive is already a wheel, there is no need to cache it.
if link.is_wheel:
return link
archives = self.get_cached_archives_for_link(link) archives = self.get_cached_archives_for_link(link)
if not archives: if not archives:
return link return None
candidates: list[tuple[float | None, Link]] = [] candidates: list[tuple[float | None, Link]] = []
for archive in archives: for archive in archives:
...@@ -54,7 +49,7 @@ class Chef: ...@@ -54,7 +49,7 @@ class Chef:
) )
if not candidates: if not candidates:
return link return None
return min(candidates)[1] return min(candidates)[1]
......
...@@ -614,9 +614,9 @@ class Executor: ...@@ -614,9 +614,9 @@ class Executor:
def _download_link(self, operation: Install | Update, link: Link) -> Link | Path: def _download_link(self, operation: Install | Update, link: Link) -> Link | Path:
package = operation.package package = operation.package
archive: Link | Path archive: Link | Path | None
archive = self._chef.get_cached_archive_for_link(link) archive = self._chef.get_cached_archive_for_link(link)
if archive is link: if archive is None:
# No cached distributions was found, so we download and prepare it # No cached distributions was found, so we download and prepare it
try: try:
archive = self._download_archive(operation, link) archive = self._download_archive(operation, link)
......
...@@ -3,6 +3,8 @@ from __future__ import annotations ...@@ -3,6 +3,8 @@ from __future__ import annotations
from pathlib import Path from pathlib import Path
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
import pytest
from packaging.tags import Tag from packaging.tags import Tag
from poetry.core.packages.utils.link import Link from poetry.core.packages.utils.link import Link
...@@ -16,7 +18,22 @@ if TYPE_CHECKING: ...@@ -16,7 +18,22 @@ if TYPE_CHECKING:
from tests.conftest import Config from tests.conftest import Config
def test_get_cached_archive_for_link(config: Config, mocker: MockerFixture): @pytest.mark.parametrize(
("link", "cached"),
[
(
"https://files.python-poetry.org/demo-0.1.0.tar.gz",
"file:///foo/demo-0.1.0-cp38-cp38-macosx_10_15_x86_64.whl",
),
(
"https://example.com/demo-0.1.0-cp38-cp38-macosx_10_15_x86_64.whl",
"file:///foo/demo-0.1.0-cp38-cp38-macosx_10_15_x86_64.whl",
),
],
)
def test_get_cached_archive_for_link(
config: Config, mocker: MockerFixture, link: str, cached: str
):
chef = Chef( chef = Chef(
config, config,
MockEnv( MockEnv(
...@@ -40,11 +57,9 @@ def test_get_cached_archive_for_link(config: Config, mocker: MockerFixture): ...@@ -40,11 +57,9 @@ def test_get_cached_archive_for_link(config: Config, mocker: MockerFixture):
], ],
) )
archive = chef.get_cached_archive_for_link( archive = chef.get_cached_archive_for_link(Link(link))
Link("https://files.python-poetry.org/demo-0.1.0.tar.gz")
)
assert Link("file:///foo/demo-0.1.0-cp38-cp38-macosx_10_15_x86_64.whl") == archive assert Link(cached) == archive
def test_get_cached_archives_for_link(config: Config, mocker: MockerFixture): def test_get_cached_archives_for_link(config: Config, mocker: MockerFixture):
......
...@@ -369,7 +369,7 @@ def test_executor_should_delete_incomplete_downloads( ...@@ -369,7 +369,7 @@ def test_executor_should_delete_incomplete_downloads(
) )
mocker.patch( mocker.patch(
"poetry.installation.chef.Chef.get_cached_archive_for_link", "poetry.installation.chef.Chef.get_cached_archive_for_link",
side_effect=lambda link: link, side_effect=lambda link: None,
) )
mocker.patch( mocker.patch(
"poetry.installation.chef.Chef.get_cache_directory_for_link", "poetry.installation.chef.Chef.get_cache_directory_for_link",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment