Example #1
0
def test_platform_create():
    assert Platform.create('linux-x86_64') == ('linux_x86_64', None, None,
                                               None)
    assert Platform.create('linux-x86_64-cp-27-cp27mu') == ('linux_x86_64',
                                                            'cp', '27',
                                                            'cp27mu')
    assert Platform.create('linux-x86_64-cp-27-mu') == ('linux_x86_64', 'cp',
                                                        '27', 'cp27mu')
    assert Platform.create('macosx-10.4-x86_64-cp-27-m') == (
        'macosx_10_4_x86_64', 'cp', '27', 'cp27m')
Example #2
0
def test_platform_create():
    assert Platform.create("linux-x86_64-cp-27-cp27mu") == ("linux_x86_64",
                                                            "cp", "27",
                                                            "cp27mu")
    assert Platform.create("linux-x86_64-cp-27-mu") == ("linux_x86_64", "cp",
                                                        "27", "cp27mu")
    assert Platform.create("macosx-10.4-x86_64-cp-27-m") == (
        "macosx_10_4_x86_64",
        "cp",
        "27",
        "cp27m",
    )
Example #3
0
def test_platform_supported_tags_abi3():
    tags = Platform.create('linux-x86_64-cp-37-m').supported_tags()
    expected_tags = [
        ('cp37', 'cp37m', 'linux_x86_64'),
        ('cp37', 'cp37m', 'manylinux1_x86_64'),
        ('cp37', 'abi3', 'linux_x86_64'),
        ('cp37', 'abi3', 'manylinux1_x86_64'),
        ('cp37', 'none', 'linux_x86_64'),
        ('cp37', 'none', 'manylinux1_x86_64'),
        ('cp36', 'abi3', 'linux_x86_64'),
        ('cp36', 'abi3', 'manylinux1_x86_64'),
        ('cp35', 'abi3', 'linux_x86_64'),
        ('cp35', 'abi3', 'manylinux1_x86_64'),
        ('cp34', 'abi3', 'linux_x86_64'),
        ('cp34', 'abi3', 'manylinux1_x86_64'),
        ('cp33', 'abi3', 'linux_x86_64'),
        ('cp33', 'abi3', 'manylinux1_x86_64'),
        ('cp32', 'abi3', 'linux_x86_64'),
        ('cp32', 'abi3', 'manylinux1_x86_64'),
        ('py3', 'none', 'linux_x86_64'),
        ('py3', 'none', 'manylinux1_x86_64'),
        ('cp37', 'none', 'any'),
        ('cp3', 'none', 'any'),
        ('py37', 'none', 'any'),
        ('py3', 'none', 'any'),
        ('py36', 'none', 'any'),
        ('py35', 'none', 'any'),
        ('py34', 'none', 'any'),
        ('py33', 'none', 'any'),
        ('py32', 'none', 'any'),
        ('py31', 'none', 'any'),
        ('py30', 'none', 'any'),
    ]
    assert expected_tags == tags
Example #4
0
def test_platform_supported_tags_abi3():
  tags = Platform.create('linux-x86_64-cp-37-m').supported_tags()
  expected_tags = [
    ('cp37', 'cp37m', 'linux_x86_64'),
    ('cp37', 'cp37m', 'manylinux1_x86_64'),
    ('cp37', 'abi3', 'linux_x86_64'),
    ('cp37', 'abi3', 'manylinux1_x86_64'),
    ('cp37', 'none', 'linux_x86_64'),
    ('cp37', 'none', 'manylinux1_x86_64'),
    ('cp36', 'abi3', 'linux_x86_64'),
    ('cp36', 'abi3', 'manylinux1_x86_64'),
    ('cp35', 'abi3', 'linux_x86_64'),
    ('cp35', 'abi3', 'manylinux1_x86_64'),
    ('cp34', 'abi3', 'linux_x86_64'),
    ('cp34', 'abi3', 'manylinux1_x86_64'),
    ('cp33', 'abi3', 'linux_x86_64'),
    ('cp33', 'abi3', 'manylinux1_x86_64'),
    ('cp32', 'abi3', 'linux_x86_64'),
    ('cp32', 'abi3', 'manylinux1_x86_64'),
    ('py3', 'none', 'linux_x86_64'),
    ('py3', 'none', 'manylinux1_x86_64'),
    ('cp37', 'none', 'any'),
    ('cp3', 'none', 'any'),
    ('py37', 'none', 'any'),
    ('py3', 'none', 'any'),
    ('py36', 'none', 'any'),
    ('py35', 'none', 'any'),
    ('py34', 'none', 'any'),
    ('py33', 'none', 'any'),
    ('py32', 'none', 'any'),
    ('py31', 'none', 'any'),
    ('py30', 'none', 'any'),
  ]
  assert expected_tags == tags
Example #5
0
def expand_and_maybe_adjust_platform(interpreter, platform):
  """Adjusts `platform` if it is 'current' and does not match the given `interpreter` platform.

  :param interpreter: The target interpreter for the given `platform`.
  :type interpreter: :class:`pex.interpreter.PythonInterpreter`
  :param platform: The platform name to expand and maybe adjust.
  :type platform: text
  :returns: The `platform`, potentially adjusted.
  :rtype: :class:`pex.platforms.Platform`
  """
  # TODO(John Sirois): Kill all usages when https://github.com/pantsbuild/pex/issues/511 is fixed.
  cur_plat = Platform.current()

  if cur_plat.platform != Platform.create(platform).platform:
    # IE: Say we're on OSX and platform was 'linux-x86_64' or 'linux_x86_64-cp-27-cp27mu'.
    return Platform.create(platform)

  ii = interpreter.identity
  if (ii.abbr_impl, ii.impl_ver, ii.abi_tag) == (cur_plat.impl, cur_plat.version, cur_plat.abi):
    # IE: Say we're on Linux and platform was 'current' or 'linux-x86_64' or
    # 'linux_x86_64-cp-27-cp27mu'and the current extended platform info matches the given
    # interpreter exactly.
    return cur_plat

  # Otherwise we need to adjust the platform to match a local interpreter different from the
  # currently executing interpreter.
  interpreter_platform = Platform(platform=cur_plat.platform,
                                  impl=ii.abbr_impl,
                                  version=ii.impl_ver,
                                  abi=ii.abi_tag)

  logger.debug("""
Modifying given platform of {given_platform!r}:
Using the current platform of {current_platform!r}
Under current interpreter {current_interpreter!r}
        
To match given interpreter {given_interpreter!r}.
        
Calculated platform: {calculated_platform!r}""".format(
    given_platform=platform,
    current_platform=cur_plat,
    current_interpreter=_interpreter_str(PythonInterpreter.get()),
    given_interpreter=_interpreter_str(interpreter),
    calculated_platform=interpreter_platform)
  )

  return interpreter_platform
Example #6
0
def test_platform_supported_tags_manylinux():
    platform = Platform.create("linux-x86_64-cp-37-cp37m")
    tags = frozenset(platform.supported_tags())
    manylinux1_tags = frozenset(
        platform.supported_tags(manylinux="manylinux1"))
    manylinux2010_tags = frozenset(
        platform.supported_tags(manylinux="manylinux2010"))
    manylinux2014_tags = frozenset(
        platform.supported_tags(manylinux="manylinux2014"))
    assert manylinux2014_tags > manylinux2010_tags > manylinux1_tags > tags
Example #7
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())
Example #8
0
File: resolver.py Project: ofek/pex
def parsed_platform(platform=None):
  """Parse the given platform into a `Platform` object.

  Unlike `Platform.create`, this function supports the special platform of 'current' or `None`. This
  maps to the platform of any local python interpreter.

  :param platform: The platform string to parse. If `None` or 'current', return `None`. If already a
                   `Platform` object, return it.
  :type platform: str or :class:`Platform`
  :return: The parsed platform or `None` for the current platform.
  :rtype: :class:`Platform` or :class:`NoneType`
  """
  return Platform.create(platform) if platform and platform != 'current' else None
Example #9
0
  def _maybe_expand_platform(interpreter, platform=None):
    # Expands `platform` if it is 'current' and abbreviated.
    #
    # IE: If we're on linux and handed a platform of `None`, 'current', or 'linux_x86_64', we expand
    # the platform to an extended platform matching the given interpreter's abi info, eg:
    # 'linux_x86_64-cp-27-cp27mu'.

    cur_plat = Platform.current()
    def expand_platform():
      expanded_platform = Platform(platform=cur_plat.platform,
                                   impl=interpreter.identity.abbr_impl,
                                   version=interpreter.identity.impl_ver,
                                   abi=interpreter.identity.abi_tag)
      TRACER.log("""
Modifying given platform of {given_platform!r}:
Using the current platform of {current_platform!r}
Under current interpreter {current_interpreter!r}

To match given interpreter {given_interpreter!r}.

Calculated platform: {calculated_platform!r}""".format(
        given_platform=platform,
        current_platform=cur_plat,
        current_interpreter=PythonInterpreter.get(),
        given_interpreter=interpreter,
        calculated_platform=expanded_platform),
        V=9
      )
      return expanded_platform

    if platform in (None, 'current'):
      # Always expand the default local (abbreviated) platform to the given interpreter.
      return expand_platform()
    else:
      given_platform = Platform.create(platform)
      if given_platform.is_extended:
        # Always respect an explicit extended platform.
        return given_platform
      elif given_platform.platform != cur_plat.platform:
        # IE: Say we're on OSX and platform was 'linux-x86_64'; we can't expand a non-local
        # platform so we leave as-is.
        return given_platform
      else:
        # IE: Say we're on 64 bit linux and platform was 'linux-x86_64'; ie: the abbreviated local
        # platform.
        return expand_platform()
Example #10
0
def assert_tags(platform, expected_tags, manylinux=None):
  tags = Platform.create(platform).supported_tags(force_manylinux=manylinux)
  for expected_tag in expected_tags:
    assert expected_tag in tags
Example #11
0
def test_platform_current():
  assert Platform.create('current') == Platform.current()
Example #12
0
def test_platform_create_noop():
  existing = Platform.create('linux-x86_64')
  assert Platform.create(existing) == existing
Example #13
0
def test_platform_create():
  assert Platform.create('linux-x86_64') == ('linux_x86_64', None, None, None)
  assert Platform.create('linux-x86_64-cp-27-cp27mu') == ('linux_x86_64', 'cp', '27', 'cp27mu')
  assert Platform.create('linux-x86_64-cp-27-mu') == ('linux_x86_64', 'cp', '27', 'cp27mu')
  assert Platform.create(
    'macosx-10.4-x86_64-cp-27-m') == ('macosx_10_4_x86_64', 'cp', '27', 'cp27m')
Example #14
0
def assert_tags(platform, expected_tags, manylinux=None):
    tags = Platform.create(platform).supported_tags(force_manylinux=manylinux)
    for expected_tag in expected_tags:
        assert expected_tag in tags
Example #15
0
def test_platform_current():
    assert Platform.create('current') == Platform.current()
Example #16
0
def test_platform_create_noop():
    existing = Platform.create('linux-x86_64')
    assert Platform.create(existing) == existing
Example #17
0
def test_platform_create_noop():
    # type: () -> None
    existing = Platform.create("linux-x86_64-cp-27-mu")
    assert Platform.create(existing) is existing
Example #18
0
def test_platform_create_noop():
    existing = Platform.create("linux-x86_64-cp-27-mu")
    assert Platform.create(existing) == existing
Example #19
0
def test_platform_create_bad_platform_empty_fields():
    with pytest.raises(Platform.InvalidPlatformError):
        Platform.create("linux-x86_64-cp--cp27mu")
Example #20
0
def test_platform_create_bad_platform_missing_fields():
    with pytest.raises(Platform.InvalidPlatformError):
        Platform.create("linux-x86_64")