Skip to content

Commit 7aeff69

Browse files
committed
Extract METADATA on wheel upload as *.whl.metadata (#8254)
This allows to download just the .metadata file for dependency resolution instead of full wheels as it happens today #8254 (comment) The filename convention and download location is covered by PEP-0658 https://www.python.org/dev/peps/pep-0658/#specification
1 parent 4a0571a commit 7aeff69

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

warehouse/forklift/legacy.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,6 +1321,7 @@ def file_upload(request):
13211321

13221322
# Check that if it's a binary wheel, it's on a supported platform
13231323
if filename.endswith(".whl"):
1324+
has_wheel_metadata = True
13241325
wheel_info = _wheel_file_re.match(filename)
13251326
plats = wheel_info.group("plat").split(".")
13261327
for plat in plats:
@@ -1330,6 +1331,14 @@ def file_upload(request):
13301331
"Binary wheel '{filename}' has an unsupported "
13311332
"platform tag '{plat}'.".format(filename=filename, plat=plat),
13321333
)
1334+
# Extract .metadata file
1335+
# https://www.python.org/dev/peps/pep-0658/#specification
1336+
with zipfile.ZipFile(temporary_filename) as zfp:
1337+
metafile = wheel_info.group("namever") + ".dist-info/METADATA"
1338+
with open(temporary_filename + ".metadata", "wb") as fp:
1339+
fp.write(zfp.read(metafile))
1340+
else:
1341+
has_wheel_metadata = False
13331342

13341343
# Also buffer the entire signature file to disk.
13351344
if "gpg_signature" in request.POST:
@@ -1417,6 +1426,17 @@ def file_upload(request):
14171426
"python-version": file_.python_version,
14181427
},
14191428
)
1429+
if has_wheel_metadata:
1430+
storage.store(
1431+
file_.path + ".metadata",
1432+
temporary_filename + ".metadata",
1433+
meta={
1434+
"project": file_.release.project.normalized_name,
1435+
"version": file_.release.version,
1436+
"package-type": file_.packagetype,
1437+
"python-version": file_.python_version,
1438+
},
1439+
)
14201440
if has_signature:
14211441
storage.store(
14221442
file_.pgp_path,

0 commit comments

Comments
 (0)