diff --git a/src/poetry/installation/executor.py b/src/poetry/installation/executor.py index 2962e7716dc..9a2aad10734 100644 --- a/src/poetry/installation/executor.py +++ b/src/poetry/installation/executor.py @@ -855,17 +855,18 @@ def _save_url_reference(self, operation: Operation) -> None: package = operation.package 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, - # if it exists. - for ( - direct_url_json - ) in self._env.site_packages.find_distribution_direct_url_json_files( - distribution_name=package.name, writable_only=True - ): - direct_url_json.unlink(missing_ok=True) + if not self._use_modern_installation: + # 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, if it + # exists. + for ( + direct_url_json + ) in self._env.site_packages.find_distribution_direct_url_json_files( + distribution_name=package.name, writable_only=True + ): + direct_url_json.unlink(missing_ok=True) return url_reference: dict[str, Any] | None = None