Skip to content

Commit

Permalink
make it work without --use-feature=fast-deps!
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmicexplorer committed May 15, 2022
1 parent 3c508cb commit e43e167
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 35 deletions.
22 changes: 13 additions & 9 deletions src/pip/_internal/operations/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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
Expand Down
37 changes: 11 additions & 26 deletions tests/functional/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -1350,34 +1350,22 @@ 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]:
"""
Produce a PyPI directory structure pointing to the specified packages, then
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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit e43e167

Please sign in to comment.