Skip to content

Commit 6da7a67

Browse files
committed
Use locally cached wheels during install
1 parent fda6737 commit 6da7a67

File tree

4 files changed

+26
-16
lines changed

4 files changed

+26
-16
lines changed

src/poetry/installation/chef.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,10 @@ def __init__(self, config: Config, env: Env) -> None:
2525
Path(config.get("cache-dir")).expanduser().joinpath("artifacts")
2626
)
2727

28-
def get_cached_archive_for_link(self, link: Link) -> Link:
29-
# If the archive is already a wheel, there is no need to cache it.
30-
if link.is_wheel:
31-
return link
32-
28+
def get_cached_archive_for_link(self, link: Link) -> Link | None:
3329
archives = self.get_cached_archives_for_link(link)
34-
3530
if not archives:
36-
return link
31+
return None
3732

3833
candidates: list[tuple[float | None, Link]] = []
3934
for archive in archives:
@@ -54,7 +49,7 @@ def get_cached_archive_for_link(self, link: Link) -> Link:
5449
)
5550

5651
if not candidates:
57-
return link
52+
return None
5853

5954
return min(candidates)[1]
6055

src/poetry/installation/executor.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -614,9 +614,9 @@ def _download(self, operation: Install | Update) -> Link | Path:
614614
def _download_link(self, operation: Install | Update, link: Link) -> Link | Path:
615615
package = operation.package
616616

617-
archive: Link | Path
617+
archive: Link | Path | None
618618
archive = self._chef.get_cached_archive_for_link(link)
619-
if archive is link:
619+
if archive is None:
620620
# No cached distributions was found, so we download and prepare it
621621
try:
622622
archive = self._download_archive(operation, link)

tests/installation/test_chef.py

+20-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from pathlib import Path
44
from typing import TYPE_CHECKING
55

6+
import pytest
7+
68
from packaging.tags import Tag
79
from poetry.core.packages.utils.link import Link
810

@@ -16,7 +18,22 @@
1618
from tests.conftest import Config
1719

1820

19-
def test_get_cached_archive_for_link(config: Config, mocker: MockerFixture):
21+
@pytest.mark.parametrize(
22+
("link", "cached"),
23+
[
24+
(
25+
"https://files.python-poetry.org/demo-0.1.0.tar.gz",
26+
"file:///foo/demo-0.1.0-cp38-cp38-macosx_10_15_x86_64.whl",
27+
),
28+
(
29+
"https://example.com/demo-0.1.0-cp38-cp38-macosx_10_15_x86_64.whl",
30+
"file:///foo/demo-0.1.0-cp38-cp38-macosx_10_15_x86_64.whl",
31+
),
32+
],
33+
)
34+
def test_get_cached_archive_for_link(
35+
config: Config, mocker: MockerFixture, link: str, cached: str
36+
):
2037
chef = Chef(
2138
config,
2239
MockEnv(
@@ -40,11 +57,9 @@ def test_get_cached_archive_for_link(config: Config, mocker: MockerFixture):
4057
],
4158
)
4259

43-
archive = chef.get_cached_archive_for_link(
44-
Link("https://files.python-poetry.org/demo-0.1.0.tar.gz")
45-
)
60+
archive = chef.get_cached_archive_for_link(Link(link))
4661

47-
assert Link("file:///foo/demo-0.1.0-cp38-cp38-macosx_10_15_x86_64.whl") == archive
62+
assert Link(cached) == archive
4863

4964

5065
def test_get_cached_archives_for_link(config: Config, mocker: MockerFixture):

tests/installation/test_executor.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ def test_executor_should_delete_incomplete_downloads(
369369
)
370370
mocker.patch(
371371
"poetry.installation.chef.Chef.get_cached_archive_for_link",
372-
side_effect=lambda link: link,
372+
side_effect=lambda link: None,
373373
)
374374
mocker.patch(
375375
"poetry.installation.chef.Chef.get_cache_directory_for_link",

0 commit comments

Comments
 (0)