Skip to content

Commit f84c28b

Browse files
committed
Move exraction code into extract_wheel_metadata()
This will be useful for backfill scripts.
1 parent 5f59563 commit f84c28b

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

warehouse/forklift/legacy.py

+18-6
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,21 @@ def _is_duplicate_file(db_session, filename, hashes):
762762
return None
763763

764764

765+
def extract_wheel_metadata(path):
766+
"""
767+
Extract METADATA file and return it as a content. The name of the
768+
.whl file is used to find the corresponding .dist-info dir.
769+
770+
See https://www.python.org/dev/peps/pep-0658/#specification
771+
"""
772+
global _wheel_file_re
773+
filename = os.path.basepath(path)
774+
namever = _wheel_file_re.match(filename).group("namever")
775+
metafile = namever + ".dist-info/METADATA"
776+
with zipfile.ZipFile(path) as zfp:
777+
return zfp.read(metafile)
778+
779+
765780
@view_config(
766781
route_name="forklift.legacy.file_upload",
767782
uses_session=True,
@@ -1331,12 +1346,9 @@ def file_upload(request):
13311346
"Binary wheel '{filename}' has an unsupported "
13321347
"platform tag '{plat}'.".format(filename=filename, plat=plat),
13331348
)
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))
1349+
wheel_metadata = extract_wheel_metadata(temporary_filename)
1350+
with open(temporary_filename + ".metadata", "wb") as fp:
1351+
fp.write(wheel_metadata)
13401352
else:
13411353
has_wheel_metadata = False
13421354

0 commit comments

Comments
 (0)