Skip to content

Commit 3c508cb

Browse files
fix importlib.metadata case
1 parent 69e28eb commit 3c508cb

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/pip/_internal/operations/prepare.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,15 @@ def _fetch_metadata_using_pep_658(
360360
self._download,
361361
hashes=metadata_link.as_hashes(),
362362
)
363+
# The file will be downloaded under the same name as it's listed in the index,
364+
# which will end with .metadata. To make importlib.metadata.PathDistribution
365+
# work, we need to keep it in the same directory, but rename it to METADATA.
366+
containing_dir = os.path.dirname(metadata_file.path)
367+
new_metadata_path = os.path.join(containing_dir, "METADATA")
368+
os.rename(metadata_file.path, new_metadata_path)
363369
assert req.req is not None
364370
return get_metadata_distribution(
365-
metadata_file.path,
371+
new_metadata_path,
366372
req.link.filename,
367373
req.req.name,
368374
)

0 commit comments

Comments
 (0)