From 4f69e8e2d069312f7812918ab28c7854bbf17141 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Randy=20D=C3=B6ring?= <30527984+radoering@users.noreply.github.com> Date: Fri, 25 Mar 2022 20:36:27 +0100 Subject: [PATCH] Do not write PEP610 URL reference for cached packages installed from a private source --- src/poetry/installation/executor.py | 4 ++-- tests/installation/test_executor.py | 36 +++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/poetry/installation/executor.py b/src/poetry/installation/executor.py index 43ebfe51f69..16c85006ba6 100644 --- a/src/poetry/installation/executor.py +++ b/src/poetry/installation/executor.py @@ -725,11 +725,11 @@ def _save_url_reference(self, operation: OperationTypes) -> None: package = operation.package - if not package.source_url: + if not package.source_url or package.source_type == "legacy": # Since we are installing from our own distribution cache # pip will write a `direct_url.json` file pointing to the cache # distribution. - # That's not what we want so we remove the direct_url.json file, + # That's not what we want, so we remove the direct_url.json file, # if it exists. for ( direct_url_json diff --git a/tests/installation/test_executor.py b/tests/installation/test_executor.py index 8060c29cf10..c7555bbd375 100644 --- a/tests/installation/test_executor.py +++ b/tests/installation/test_executor.py @@ -411,6 +411,42 @@ def verify_installed_distribution( assert not direct_url_file.exists() +@pytest.mark.parametrize( + "package", + [ + Package("demo", "0.1.0"), # PyPI + Package( # private source + "demo", + "0.1.0", + source_type="legacy", + source_url="http://localhost:3141/root/pypi/+simple", + source_reference="private", + ), + ], +) +def test_executor_should_not_write_pep610_url_references_for_cached_package( + package: Package, + mocker: MockerFixture, + fixture_dir: FixtureDirGetter, + tmp_venv: VirtualEnv, + pool: Pool, + config: Config, + io: BufferedIO, +): + link_cached = Link( + fixture_dir("distributions") + .joinpath("demo-0.1.0-py2.py3-none-any.whl") + .as_uri() + ) + mocker.patch( + "poetry.installation.executor.Executor._download", return_value=link_cached + ) + + executor = Executor(tmp_venv, pool, config, io) + executor.execute([Install(package)]) + verify_installed_distribution(tmp_venv, package) + + def test_executor_should_write_pep610_url_references_for_files( tmp_venv: VirtualEnv, pool: Pool, config: Config, io: BufferedIO ):