Skip to content

Commit

Permalink
gather requirements first when metadata is available
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanking13 committed Dec 5, 2024
1 parent c2c17fa commit 79e14b1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
25 changes: 16 additions & 9 deletions micropip/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,15 +249,22 @@ async def add_wheel(

wheel_download_task = asyncio.create_task(wheel.download(self.fetch_kwargs))
if self.deps:
try:
await wheel.download_pep658_metadata(self.fetch_kwargs)
except OSError:
# If something goes wrong while downloading the metadata
# we just log the error and continue, as the metadata can be fetched extracted from the wheel.
logger.debug("Metadata not available for %s", wheel.name)

await wheel_download_task
await self.gather_requirements(wheel.requires(extras))
# Case 1) If metadata file is available,
# we can gather requirements without waiting for the wheel to be downloaded.
if wheel.pep658_metadata_available():
try:
await wheel.download_pep658_metadata(self.fetch_kwargs)
except OSError:
# If something goes wrong while downloading the metadata,
# we have to wait for the wheel to be downloaded.
await wheel_download_task
await self.gather_requirements(wheel.requires(extras))

# Case 2) If metadata file is not available,
# we have to wait for the wheel to be downloaded.
else:
await wheel_download_task
await self.gather_requirements(wheel.requires(extras))

self.wheels.append(wheel)

Expand Down
6 changes: 6 additions & 0 deletions micropip/wheelinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ async def download(self, fetch_kwargs: dict[str, Any]):
)
self._metadata = Metadata(zipfile.Path(zf, metadata_path))

def pep658_metadata_available(self) -> bool:
"""
Check if the wheel's metadata is exposed via PEP 658.
"""
return self.data_dist_info_metadata is not None

async def download_pep658_metadata(
self,
fetch_kwargs: dict[str, Any],
Expand Down

0 comments on commit 79e14b1

Please sign in to comment.