Skip to content

Commit

Permalink
Move exraction code into extract_wheel_metadata()
Browse files Browse the repository at this point in the history
This will be useful for backfill scripts.
  • Loading branch information
abitrolly committed Sep 17, 2021
1 parent 5f59563 commit f84c28b
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions warehouse/forklift/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,21 @@ def _is_duplicate_file(db_session, filename, hashes):
return None


def extract_wheel_metadata(path):
"""
Extract METADATA file and return it as a content. The name of the
.whl file is used to find the corresponding .dist-info dir.
See https://www.python.org/dev/peps/pep-0658/#specification
"""
global _wheel_file_re
filename = os.path.basepath(path)
namever = _wheel_file_re.match(filename).group("namever")
metafile = namever + ".dist-info/METADATA"
with zipfile.ZipFile(path) as zfp:
return zfp.read(metafile)


@view_config(
route_name="forklift.legacy.file_upload",
uses_session=True,
Expand Down Expand Up @@ -1331,12 +1346,9 @@ def file_upload(request):
"Binary wheel '{filename}' has an unsupported "
"platform tag '{plat}'.".format(filename=filename, plat=plat),
)
# Extract .metadata file
# https://www.python.org/dev/peps/pep-0658/#specification
with zipfile.ZipFile(temporary_filename) as zfp:
metafile = wheel_info.group("namever") + ".dist-info/METADATA"
with open(temporary_filename + ".metadata", "wb") as fp:
fp.write(zfp.read(metafile))
wheel_metadata = extract_wheel_metadata(temporary_filename)
with open(temporary_filename + ".metadata", "wb") as fp:
fp.write(wheel_metadata)
else:
has_wheel_metadata = False

Expand Down

0 comments on commit f84c28b

Please sign in to comment.