Skip to content

Commit 4da3bcb

Browse files
authored
Do not write PEP610 URL reference for cached packages installed from a private source (#5362)
1 parent e1b8dd9 commit 4da3bcb

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

src/poetry/installation/executor.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -725,11 +725,11 @@ def _save_url_reference(self, operation: OperationTypes) -> None:
725725

726726
package = operation.package
727727

728-
if not package.source_url:
728+
if not package.source_url or package.source_type == "legacy":
729729
# Since we are installing from our own distribution cache
730730
# pip will write a `direct_url.json` file pointing to the cache
731731
# distribution.
732-
# That's not what we want so we remove the direct_url.json file,
732+
# That's not what we want, so we remove the direct_url.json file,
733733
# if it exists.
734734
for (
735735
direct_url_json

tests/installation/test_executor.py

+36
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,42 @@ def verify_installed_distribution(
411411
assert not direct_url_file.exists()
412412

413413

414+
@pytest.mark.parametrize(
415+
"package",
416+
[
417+
Package("demo", "0.1.0"), # PyPI
418+
Package( # private source
419+
"demo",
420+
"0.1.0",
421+
source_type="legacy",
422+
source_url="http://localhost:3141/root/pypi/+simple",
423+
source_reference="private",
424+
),
425+
],
426+
)
427+
def test_executor_should_not_write_pep610_url_references_for_cached_package(
428+
package: Package,
429+
mocker: MockerFixture,
430+
fixture_dir: FixtureDirGetter,
431+
tmp_venv: VirtualEnv,
432+
pool: Pool,
433+
config: Config,
434+
io: BufferedIO,
435+
):
436+
link_cached = Link(
437+
fixture_dir("distributions")
438+
.joinpath("demo-0.1.0-py2.py3-none-any.whl")
439+
.as_uri()
440+
)
441+
mocker.patch(
442+
"poetry.installation.executor.Executor._download", return_value=link_cached
443+
)
444+
445+
executor = Executor(tmp_venv, pool, config, io)
446+
executor.execute([Install(package)])
447+
verify_installed_distribution(tmp_venv, package)
448+
449+
414450
def test_executor_should_write_pep610_url_references_for_files(
415451
tmp_venv: VirtualEnv, pool: Pool, config: Config, io: BufferedIO
416452
):

0 commit comments

Comments
 (0)