Skip to content

Commit

Permalink
Simplify and clarify resolver platform expansion.
Browse files Browse the repository at this point in the history
  • Loading branch information
jsirois committed Oct 3, 2018
1 parent c9f0618 commit 0e3fc9c
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions pex/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,25 +165,24 @@ 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()
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'.

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'.
if given_platform.is_extended:
# Always respect an extended platform.
return given_platform

if (interpreter.identity.abbr_impl,
interpreter.identity.impl_ver,
interpreter.identity.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
cur_plat = Platform.current()
if cur_plat.platform != given_platform.platform:
# IE: Say we're on OSX and platform was 'linux-x86_64'.
return given_platform

# Otherwise we need to adjust the platform to match a local interpreter different from the
# currently executing interpreter.
# Otherwise we need to expand the platform to match the given interpreter.
adjusted_platform = Platform(platform=cur_plat.platform,
impl=interpreter.identity.abbr_impl,
version=interpreter.identity.impl_ver,
Expand All @@ -210,7 +209,7 @@ def _expand_and_maybe_adjust_platform(interpreter, platform=None):
def __init__(self, allow_prereleases=None, interpreter=None, platform=None,
pkg_blacklist=None, use_manylinux=None):
self._interpreter = interpreter or PythonInterpreter.get()
self._platform = self._expand_and_maybe_adjust_platform(self._interpreter, platform)
self._platform = self._maybe_expand_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 0e3fc9c

Please sign in to comment.