Skip to content

Commit

Permalink
Fix pex-tool#511 to fix pex-tool#523 test on 3.7 machine with access …
Browse files Browse the repository at this point in the history
…to 2.7 bad interp.
  • Loading branch information
jsirois committed Oct 2, 2018
1 parent b2a2121 commit 12bb2bb
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
6 changes: 4 additions & 2 deletions pex/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,10 @@ def __str__(self):
)

def __repr__(self):
return 'PythonIdentity(%r, %s, %s, %s)' % (
self._interpreter,
return 'PythonIdentity(%r, %r, %r, %r, %r, %r)' % (
self.abbr_impl,
self.abi_tag,
self.impl_ver,
self._version[0],
self._version[1],
self._version[2]
Expand Down
44 changes: 43 additions & 1 deletion pex/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,52 @@ class Resolver(object):

class Error(Exception): pass

@staticmethod
def _expand_and_maybe_adjust_platform(interpreter, platform=None):
# Adjusts `platform` if it is 'current' and does not match the given `interpreter` platform.
cur_plat = Platform.current()

given_platform = Platform.create(platform or 'current')
if cur_plat.platform != given_platform.platform:
# IE: Say we're on OSX and platform was 'linux-x86_64' or 'linux_x86_64-cp-27-cp27mu'.
return given_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.
adjusted_platform = Platform(platform=cur_plat.platform,
impl=ii.abbr_impl,
version=ii.impl_ver,
abi=ii.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=given_platform,
current_platform=cur_plat,
current_interpreter=PythonInterpreter.get(),
given_interpreter=interpreter,
calculated_platform=adjusted_platform),
V=9
)

return adjusted_platform

def __init__(self, allow_prereleases=None, interpreter=None, platform=None,
pkg_blacklist=None, use_manylinux=None):
self._interpreter = interpreter or PythonInterpreter.get()
self._platform = Platform.create(platform) if platform else Platform.current()
self._platform = self._expand_and_maybe_adjust_platform(self._interpreter, platform)
self._allow_prereleases = allow_prereleases
self._blacklist = pkg_blacklist.copy() if pkg_blacklist else {}
self._supported_tags = self._platform.supported_tags(
Expand Down

0 comments on commit 12bb2bb

Please sign in to comment.