Пример #1
0
    def _can_add(self, dist):
        # type: (Distribution) -> Optional[_RankedDistribution]
        filename, ext = os.path.splitext(os.path.basename(dist.location))
        if ext.lower() != ".whl":
            # This supports resolving pex's own vendored distributions which are vendored in directory
            # directory with the project name (`pip/` for pip) and not the corresponding wheel name
            # (`pip-19.3.1-py2.py3-none-any.whl/` for pip). Pex only vendors universal wheels for all
            # platforms it supports at buildtime and runtime so this is always safe.
            return _RankedDistribution.maximum(dist)

        # Wheel filename format: https://www.python.org/dev/peps/pep-0427/#file-name-convention
        # `{distribution}-{version}(-{build tag})?-{python tag}-{abi tag}-{platform tag}.whl`
        wheel_components = filename.split("-")
        if len(wheel_components) < 3:
            return None

        # `{python tag}-{abi tag}-{platform tag}`
        wheel_tags = tags.parse_tag("-".join(wheel_components[-3:]))
        # There will be multiple parsed tags for compressed tag sets. Ensure we grab the parsed tag
        # with highest rank from that expanded set.
        rank = max(
            self._supported_tags_to_rank.get(tag, -1) for tag in wheel_tags)
        if rank == -1:
            return None

        if self._interpreter_version:
            python_requires = dist_metadata.requires_python(dist)
            if python_requires and self._interpreter_version not in python_requires:
                return None

        return _RankedDistribution(rank, dist)
Пример #2
0
    def can_add(self, dist):
        filename, ext = os.path.splitext(os.path.basename(dist.location))
        if ext.lower() != ".whl":
            # This supports resolving pex's own vendored distributions which are vendored in directory
            # directory with the project name (`pip/` for pip) and not the corresponding wheel name
            # (`pip-19.3.1-py2.py3-none-any.whl/` for pip). Pex only vendors universal wheels for all
            # platforms it supports at buildtime and runtime so this is always safe.
            return True

        # Wheel filename format: https://www.python.org/dev/peps/pep-0427/#file-name-convention
        # `{distribution}-{version}(-{build tag})?-{python tag}-{abi tag}-{platform tag}.whl`
        wheel_components = filename.split("-")
        if len(wheel_components) < 3:
            return False

        wheel_tags = "-".join(
            wheel_components[-3:])  # `{python tag}-{abi tag}-{platform tag}`
        if self._supported_tags.isdisjoint(tags.parse_tag(wheel_tags)):
            return False

        python_requires = dist_metadata.requires_python(dist)
        if not python_requires:
            return True

        return self._interpreter.identity.version_str in python_requires
Пример #3
0
def test_platform_supported_tags():
    platform = Platform.create("macosx-10.13-x86_64-cp-36-m")

    # A golden file test. This could break if we upgrade Pip and it upgrades packaging which, from
    # time to time, corrects omissions in tag sets.
    assert (tuple(
        itertools.chain.from_iterable(
            tags.parse_tag(tag) for tag in pkgutil.get_data(
                __name__, "data/platforms/macosx_10_13_x86_64-cp-36-m.tags.txt"
            ).decode("utf-8").splitlines()
            if not tag.startswith("#"))) == platform.supported_tags())
Пример #4
0
    def can_add(self, dist):
        filename, ext = os.path.splitext(os.path.basename(dist.location))
        if ext.lower() != '.whl':
            # This supports resolving pex's own vendored distributions which are vendored in directory
            # directory with the project name (`pip/` for pip) and not the corresponding wheel name
            # (`pip-19.3.1-py2.py3-none-any.whl/` for pip). Pex only vendors universal wheels for all
            # platforms it supports at buildtime and runtime so this is always safe.
            return True

        try:
            wheel_name_, wheel_raw_version_, wheel_tags = filename.split(
                '-', 2)
        except ValueError:
            return False

        return not self._supported_tags.isdisjoint(tags.parse_tag(wheel_tags))
Пример #5
0
 def parse_tags(output):
     # type: (bytes) -> Iterator[tags.Tag]
     count = None  # type: Optional[int]
     try:
         for line in output.decode("utf-8").splitlines():
             if count is None:
                 match = re.match(r"^Compatible tags: (?P<count>\d+)\s+", line)
                 if match:
                     count = int(match.group("count"))
                 continue
             count -= 1
             if count < 0:
                 raise AssertionError("Expected {} tags but got more.".format(count))
             for tag in tags.parse_tag(line.strip()):
                 yield tag
     finally:
         if count != 0:
             raise AssertionError("Finished with count {}.".format(count))