Skip to content

Commit

Permalink
Broaden abi selection for non-specified abi types.
Browse files Browse the repository at this point in the history
  • Loading branch information
kwlzn committed May 26, 2018
1 parent 1c30494 commit 004ff64
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 3 deletions.
27 changes: 27 additions & 0 deletions pex/pep425tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,33 @@ def _supports_arch(major, minor, arch):
return arches


def _gen_all_abis(impl, version):
def tmpl_abi(impl, version, suffix):
return ''.join((impl, version, suffix))
yield tmpl_abi(impl, version, 'd')
yield tmpl_abi(impl, version, 'dm')
yield tmpl_abi(impl, version, 'dmu')
yield tmpl_abi(impl, version, 'm')
yield tmpl_abi(impl, version, 'mu')
yield tmpl_abi(impl, version, 'u')


def get_supported_for_any_abi(version=None, noarch=False, platform=None, impl=None,
force_manylinux=False):
"""Generates supported tags for unspecified ABI types to support more intuitive cross-platform
resolution."""
unique_tags = {
tag for abi in _gen_all_abis(impl, version)
for tag in get_supported(version=version,
noarch=noarch,
platform=platform,
impl=impl,
abi=abi,
force_manylinux=force_manylinux)
}
return list(unique_tags)


def get_supported(version=None, noarch=False, platform=None, impl=None, abi=None,
force_manylinux=False):
"""Return a list of supported tags for each version specified in
Expand Down
15 changes: 12 additions & 3 deletions pex/platforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@

from collections import namedtuple

from .pep425tags import get_abbr_impl, get_abi_tag, get_impl_ver, get_platform, get_supported
from .pep425tags import (
get_abbr_impl,
get_abi_tag,
get_impl_ver,
get_platform,
get_supported,
get_supported_for_any_abi
)


class Platform(namedtuple('Platform', ['platform', 'impl', 'version', 'abi'])):
Expand Down Expand Up @@ -63,11 +70,13 @@ def is_extended(self):
def supported_tags(self, interpreter=None, force_manylinux=True):
"""Returns a list of supported PEP425 tags for the current platform."""
if interpreter and not self.is_extended:
tags = get_supported(
# N.B. If we don't get an extended platform specifier, we generate
# all possible ABI permutations to mimic earlier pex version
# behavior and make cross-platform resolution more intuitive.
tags = get_supported_for_any_abi(
platform=self.platform,
impl=interpreter.identity.abbr_impl,
version=interpreter.identity.impl_ver,
abi=interpreter.identity.abi_tag,
force_manylinux=force_manylinux
)
else:
Expand Down
1 change: 1 addition & 0 deletions pex/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
IS_NOT_LINUX = "platform.system() != 'Linux'"
NOT_CPYTHON27_OR_OSX = "%s or %s" % (NOT_CPYTHON27, IS_NOT_LINUX)
NOT_CPYTHON27_OR_LINUX = "%s or %s" % (NOT_CPYTHON27, IS_LINUX)
NOT_CPYTHON27_OR_LINUX = "%s or %s" % (NOT_CPYTHON27, IS_LINUX)
NOT_CPYTHON36_OR_LINUX = "%s or %s" % (NOT_CPYTHON36, IS_LINUX)


Expand Down
Binary file not shown.
29 changes: 29 additions & 0 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from pex.testing import (
IS_PYPY,
NOT_CPYTHON27,
NOT_CPYTHON27_OR_LINUX,
NOT_CPYTHON27_OR_OSX,
NOT_CPYTHON36,
NOT_CPYTHON36_OR_LINUX,
Expand Down Expand Up @@ -880,3 +881,31 @@ def test_jupyter_appnope_env_markers():
'--version'])
res.assert_success()
assert len(res.output) > 4


# TODO: https://github.com/pantsbuild/pex/issues/479
@pytest.mark.skipif(NOT_CPYTHON27_OR_LINUX,
reason='this needs to run on an interpreter with ABI type m (OSX) vs mu (linux)')
def test_cross_platform_abi_targeting_behavior():
with temporary_dir() as td:
pex_out_path = os.path.join(td, 'pex.pex')
res = run_pex_command(['--disable-cache',
'--no-pypi',
'--platform=linux-x86_64',
'--find-links=tests/example_packages/',
'MarkupSafe==1.0',
'-o', pex_out_path])
res.assert_success()


@pytest.mark.skipif(NOT_CPYTHON27)
def test_cross_platform_abi_targeting_behavior_exact():
with temporary_dir() as td:
pex_out_path = os.path.join(td, 'pex.pex')
res = run_pex_command(['--disable-cache',
'--no-pypi',
'--platform=linux-x86_64-cp-27-mu',
'--find-links=tests/example_packages/',
'MarkupSafe==1.0',
'-o', pex_out_path])
res.assert_success()

0 comments on commit 004ff64

Please sign in to comment.