Mercurial > repos > guerler > hhblits
comparison lib/python3.8/site-packages/pip/_internal/models/wheel.py @ 0:9e54283cc701 draft
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
| author | guerler |
|---|---|
| date | Mon, 27 Jul 2020 03:47:31 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:9e54283cc701 |
|---|---|
| 1 """Represents a wheel file and provides access to the various parts of the | |
| 2 name that have meaning. | |
| 3 """ | |
| 4 import re | |
| 5 | |
| 6 from pip._vendor.packaging.tags import Tag | |
| 7 | |
| 8 from pip._internal.exceptions import InvalidWheelFilename | |
| 9 from pip._internal.utils.typing import MYPY_CHECK_RUNNING | |
| 10 | |
| 11 if MYPY_CHECK_RUNNING: | |
| 12 from typing import List | |
| 13 | |
| 14 | |
| 15 class Wheel(object): | |
| 16 """A wheel file""" | |
| 17 | |
| 18 wheel_file_re = re.compile( | |
| 19 r"""^(?P<namever>(?P<name>.+?)-(?P<ver>.*?)) | |
| 20 ((-(?P<build>\d[^-]*?))?-(?P<pyver>.+?)-(?P<abi>.+?)-(?P<plat>.+?) | |
| 21 \.whl|\.dist-info)$""", | |
| 22 re.VERBOSE | |
| 23 ) | |
| 24 | |
| 25 def __init__(self, filename): | |
| 26 # type: (str) -> None | |
| 27 """ | |
| 28 :raises InvalidWheelFilename: when the filename is invalid for a wheel | |
| 29 """ | |
| 30 wheel_info = self.wheel_file_re.match(filename) | |
| 31 if not wheel_info: | |
| 32 raise InvalidWheelFilename( | |
| 33 "%s is not a valid wheel filename." % filename | |
| 34 ) | |
| 35 self.filename = filename | |
| 36 self.name = wheel_info.group('name').replace('_', '-') | |
| 37 # we'll assume "_" means "-" due to wheel naming scheme | |
| 38 # (https://github.com/pypa/pip/issues/1150) | |
| 39 self.version = wheel_info.group('ver').replace('_', '-') | |
| 40 self.build_tag = wheel_info.group('build') | |
| 41 self.pyversions = wheel_info.group('pyver').split('.') | |
| 42 self.abis = wheel_info.group('abi').split('.') | |
| 43 self.plats = wheel_info.group('plat').split('.') | |
| 44 | |
| 45 # All the tag combinations from this file | |
| 46 self.file_tags = { | |
| 47 Tag(x, y, z) for x in self.pyversions | |
| 48 for y in self.abis for z in self.plats | |
| 49 } | |
| 50 | |
| 51 def get_formatted_file_tags(self): | |
| 52 # type: () -> List[str] | |
| 53 """Return the wheel's tags as a sorted list of strings.""" | |
| 54 return sorted(str(tag) for tag in self.file_tags) | |
| 55 | |
| 56 def support_index_min(self, tags): | |
| 57 # type: (List[Tag]) -> int | |
| 58 """Return the lowest index that one of the wheel's file_tag combinations | |
| 59 achieves in the given list of supported tags. | |
| 60 | |
| 61 For example, if there are 8 supported tags and one of the file tags | |
| 62 is first in the list, then return 0. | |
| 63 | |
| 64 :param tags: the PEP 425 tags to check the wheel against, in order | |
| 65 with most preferred first. | |
| 66 | |
| 67 :raises ValueError: If none of the wheel's file tags match one of | |
| 68 the supported tags. | |
| 69 """ | |
| 70 return min(tags.index(tag) for tag in self.file_tags if tag in tags) | |
| 71 | |
| 72 def supported(self, tags): | |
| 73 # type: (List[Tag]) -> bool | |
| 74 """Return whether the wheel is compatible with one of the given tags. | |
| 75 | |
| 76 :param tags: the PEP 425 tags to check the wheel against. | |
| 77 """ | |
| 78 return not self.file_tags.isdisjoint(tags) |
