Path: blob/master/venv/Lib/site-packages/pip/_internal/models/wheel.py
811 views
"""Represents a wheel file and provides access to the various parts of the1name that have meaning.2"""3import re45from pip._vendor.packaging.tags import Tag67from pip._internal.exceptions import InvalidWheelFilename8from pip._internal.utils.typing import MYPY_CHECK_RUNNING910if MYPY_CHECK_RUNNING:11from typing import List121314class Wheel(object):15"""A wheel file"""1617wheel_file_re = re.compile(18r"""^(?P<namever>(?P<name>.+?)-(?P<ver>.*?))19((-(?P<build>\d[^-]*?))?-(?P<pyver>.+?)-(?P<abi>.+?)-(?P<plat>.+?)20\.whl|\.dist-info)$""",21re.VERBOSE22)2324def __init__(self, filename):25# type: (str) -> None26"""27:raises InvalidWheelFilename: when the filename is invalid for a wheel28"""29wheel_info = self.wheel_file_re.match(filename)30if not wheel_info:31raise InvalidWheelFilename(32"{} is not a valid wheel filename.".format(filename)33)34self.filename = filename35self.name = wheel_info.group('name').replace('_', '-')36# we'll assume "_" means "-" due to wheel naming scheme37# (https://github.com/pypa/pip/issues/1150)38self.version = wheel_info.group('ver').replace('_', '-')39self.build_tag = wheel_info.group('build')40self.pyversions = wheel_info.group('pyver').split('.')41self.abis = wheel_info.group('abi').split('.')42self.plats = wheel_info.group('plat').split('.')4344# All the tag combinations from this file45self.file_tags = {46Tag(x, y, z) for x in self.pyversions47for y in self.abis for z in self.plats48}4950def get_formatted_file_tags(self):51# type: () -> List[str]52"""Return the wheel's tags as a sorted list of strings."""53return sorted(str(tag) for tag in self.file_tags)5455def support_index_min(self, tags):56# type: (List[Tag]) -> int57"""Return the lowest index that one of the wheel's file_tag combinations58achieves in the given list of supported tags.5960For example, if there are 8 supported tags and one of the file tags61is first in the list, then return 0.6263:param tags: the PEP 425 tags to check the wheel against, in order64with most preferred first.6566:raises ValueError: If none of the wheel's file tags match one of67the supported tags.68"""69return min(tags.index(tag) for tag in self.file_tags if tag in tags)7071def supported(self, tags):72# type: (List[Tag]) -> bool73"""Return whether the wheel is compatible with one of the given tags.7475:param tags: the PEP 425 tags to check the wheel against.76"""77return not self.file_tags.isdisjoint(tags)787980