Skip to content

Commit 2f92826

Browse files
committed
Extract basic wheel parsing into separate function
This functions as a guard for the rest of our wheel-handling code, ensuring that we will only get past this point if we have a wheel that we should be able to handle version-wise. We return a tuple instead of bundling up the result in a dedicated type because it's the simplest option. The interface will be easy to update later if the need arises.
1 parent d5b4c15 commit 2f92826

File tree

1 file changed

+22
-10
lines changed
  • src/pip/_internal/operations/install

1 file changed

+22
-10
lines changed

src/pip/_internal/operations/install/wheel.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -321,16 +321,7 @@ def install_unpacked_wheel(
321321

322322
source = wheeldir.rstrip(os.path.sep) + os.path.sep
323323

324-
try:
325-
info_dir = wheel_dist_info_dir(wheel_zip, name)
326-
metadata = wheel_metadata(wheel_zip, info_dir)
327-
version = wheel_version(metadata)
328-
except UnsupportedWheel as e:
329-
raise UnsupportedWheel(
330-
"{} has an invalid wheel, {}".format(name, str(e))
331-
)
332-
333-
check_compatibility(version, name)
324+
info_dir, metadata = parse_wheel(wheel_zip, name)
334325

335326
if wheel_root_is_purelib(metadata):
336327
lib_dir = scheme.purelib
@@ -633,6 +624,27 @@ def install_wheel(
633624
)
634625

635626

627+
def parse_wheel(wheel_zip, name):
628+
# type: (ZipFile, str) -> Tuple[str, Message]
629+
"""Extract information from the provided wheel, ensuring it meets basic
630+
standards.
631+
632+
Returns the name of the .dist-info directory and the parsed WHEEL metadata.
633+
"""
634+
try:
635+
info_dir = wheel_dist_info_dir(wheel_zip, name)
636+
metadata = wheel_metadata(wheel_zip, info_dir)
637+
version = wheel_version(metadata)
638+
except UnsupportedWheel as e:
639+
raise UnsupportedWheel(
640+
"{} has an invalid wheel, {}".format(name, str(e))
641+
)
642+
643+
check_compatibility(version, name)
644+
645+
return info_dir, metadata
646+
647+
636648
def wheel_dist_info_dir(source, name):
637649
# type: (ZipFile, str) -> str
638650
"""Returns the name of the contained .dist-info directory.

0 commit comments

Comments
 (0)