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 ):