diff --git a/news/11111.feature.rst b/news/11111.feature.rst index 41fa2398f4e..39cb4b35c12 100644 --- a/news/11111.feature.rst +++ b/news/11111.feature.rst @@ -1 +1 @@ -Use the ``data-dist-info-metadata`` attribute from :pep:`658` to resolve distribution metadata when ``--use-feature=fast-deps`` is enabled. +Use the ``data-dist-info-metadata`` attribute from :pep:`658` to resolve distribution metadata without downloading the dist yet. diff --git a/src/pip/_internal/operations/prepare.py b/src/pip/_internal/operations/prepare.py index 2894bd4622e..9bf71a6a053 100644 --- a/src/pip/_internal/operations/prepare.py +++ b/src/pip/_internal/operations/prepare.py @@ -333,19 +333,15 @@ def _fetch_metadata_only( self, req: InstallRequirement, ) -> Optional[BaseDistribution]: - # --use-feature=fast-deps must be provided. - if not self.use_lazy_wheel: - return None if self.require_hashes: logger.debug( "Metadata-only fetching is not used as hash checking is required", ) return None # Try PEP 658 metadata first, then fall back to lazy wheel if unavailable. - pep_658_dist = self._fetch_metadata_using_pep_658(req) - if pep_658_dist is not None: - return pep_658_dist - return self._fetch_metadata_using_lazy_wheel(req.link) + return self._fetch_metadata_using_pep_658( + req + ) or self._fetch_metadata_using_lazy_wheel(req.link) def _fetch_metadata_using_pep_658( self, @@ -355,6 +351,12 @@ def _fetch_metadata_using_pep_658( metadata_link = req.link.metadata_link() if metadata_link is None: return None + assert req.req is not None + logger.info( + "Obtaining dependency information for %s from %s", + req.req, + metadata_link, + ) metadata_file = get_http_url( metadata_link, self._download, @@ -366,7 +368,6 @@ def _fetch_metadata_using_pep_658( containing_dir = os.path.dirname(metadata_file.path) new_metadata_path = os.path.join(containing_dir, "METADATA") os.rename(metadata_file.path, new_metadata_path) - assert req.req is not None return get_metadata_distribution( new_metadata_path, req.link.filename, @@ -378,9 +379,12 @@ def _fetch_metadata_using_lazy_wheel( link: Link, ) -> Optional[BaseDistribution]: """Fetch metadata using lazy wheel, if possible.""" + # --use-feature=fast-deps must be provided. + if not self.use_lazy_wheel: + return None if link.is_file or not link.is_wheel: logger.debug( - "Lazy wheel is not used as %r does not points to a remote wheel", + "Lazy wheel is not used as %r does not point to a remote wheel", link, ) return None diff --git a/tests/functional/test_download.py b/tests/functional/test_download.py index bf352450332..e2e200ef9eb 100644 --- a/tests/functional/test_download.py +++ b/tests/functional/test_download.py @@ -1350,7 +1350,6 @@ def download_generated_index( def run_for_generated_index( packages: Dict[str, List[Package]], args: List[str], - fast_deps: bool = False, allow_error: bool = False, ) -> Tuple[TestPipResult, Path]: """ @@ -1358,26 +1357,15 @@ def run_for_generated_index( execute `pip download -i ...` pointing to our generated index. """ index_dir = index_for_packages(packages) - pip_args = [] - if fast_deps: - pip_args.append("--use-feature=fast-deps") - pip_args.extend( - [ - "download", - "-d", - str(download_dir), - "-i", - path_to_url(index_dir), - ] - ) - pip_args.extend(args) - result = script.pip( - *pip_args, - # We need allow_stderr_warning=True if fast_deps=True, since that will print - # a warning to stderr. - allow_stderr_warning=fast_deps, - allow_error=allow_error, - ) + pip_args = [ + "download", + "-d", + str(download_dir), + "-i", + path_to_url(index_dir), + *args, + ] + result = script.pip(*pip_args, allow_error=allow_error) return (result, download_dir) return run_for_generated_index @@ -1413,12 +1401,11 @@ def test_download_metadata( requirement_to_download: str, expected_outputs: List[str], ) -> None: - """Verify that when using --use-feature=fast-deps, if a data-dist-info-metadata - attribute is present, then it is used instead of the actual dist's METADATA.""" + """Verify that if a data-dist-info-metadata attribute is present, then it is used + instead of the actual dist's METADATA.""" _, download_dir = download_generated_index( _simple_packages, [requirement_to_download], - fast_deps=True, ) assert sorted(os.listdir(download_dir)) == expected_outputs @@ -1442,7 +1429,6 @@ def test_incorrect_metadata_hash( result, _ = download_generated_index( _simple_packages, [requirement_to_download], - fast_deps=True, allow_error=True, ) assert result.returncode != 0 @@ -1466,7 +1452,6 @@ def test_metadata_not_found( result, _ = download_generated_index( _simple_packages, [requirement_to_download], - fast_deps=True, allow_error=True, ) assert result.returncode != 0