-
-
Notifications
You must be signed in to change notification settings - Fork 645
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix 'current' platform handling. #6104
Changes from 4 commits
65374e3
8fc4b62
2c69db0
fe2907e
fae5bd9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[bdist_wheel] | ||
universal=1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,15 @@ | |
|
||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
import logging | ||
|
||
from pex.interpreter import PythonInterpreter | ||
from pex.platforms import Platform | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def create_bare_interpreter(binary_path): | ||
"""Creates an interpreter for python binary at the given path. | ||
|
||
|
@@ -22,13 +27,60 @@ def create_bare_interpreter(binary_path): | |
return PythonInterpreter(binary_path, interpreter_with_extras.identity, extras=None) | ||
|
||
|
||
def get_local_platform(): | ||
"""Returns the name of the local platform; eg: 'linux_x86_64' or 'macosx_10_8_x86_64'. | ||
def _interpreter_str(interp): | ||
ident = interp.identity | ||
return ('PythonInterpreter({binary!r}, {identity!r} with extended info: ' | ||
'(abbr_impl: {abbr_impl!r}, impl_ver: {impl_ver!r}, abi_tag: {abi_tag!r}))' | ||
.format(binary=interp.binary, | ||
identity=ident, | ||
abbr_impl=ident.abbr_impl, | ||
impl_ver=ident.impl_ver, | ||
abi_tag=ident.abi_tag)) | ||
|
||
|
||
def expand_and_maybe_adjust_platform(interpreter, platform): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a TODO to upstream this into pex might be good? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup - this old one pex-tool/pex#511, I'll add a TODO similar to the method above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
"""Adjusts `platform` if it is 'current' and does not match the given `interpreter` platform. | ||
|
||
:returns: The local platform name. | ||
:rtype: str | ||
: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 some or all usages when https://github.com/pantsbuild/pex/issues/511 | ||
# is fixed. | ||
current_platform = Platform.current() | ||
return current_platform.platform | ||
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}: | ||
Resolves as {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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -205,10 +205,8 @@ def _prepare_and_create_dist(self, interpreter, shared_libs_product, versioned_t | |
'Installing setup requirements: {}\n\n' | ||
.format([req.key for req in setup_reqs_to_resolve])) | ||
|
||
cur_platforms = ['current'] if is_platform_specific else None | ||
|
||
setup_requires_site_dir = ensure_setup_requires_site_dir( | ||
setup_reqs_to_resolve, interpreter, setup_requires_dir, platforms=cur_platforms) | ||
setup_reqs_to_resolve, interpreter, setup_requires_dir, platforms=['current']) | ||
if setup_requires_site_dir: | ||
self.context.log.debug('Setting PYTHONPATH with setup_requires site directory: {}' | ||
.format(setup_requires_site_dir)) | ||
|
@@ -226,8 +224,9 @@ def _create_dist(self, dist_tgt, dist_target_dir, interpreter, | |
self._copy_sources(dist_tgt, dist_target_dir) | ||
|
||
setup_runner = SetupPyRunner.for_bdist_wheel( | ||
dist_target_dir, | ||
is_platform_specific=is_platform_specific) | ||
source_dir=dist_target_dir, | ||
is_platform_specific=is_platform_specific, | ||
interpreter=interpreter) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK @CMLivingston and @cosmicexplorer - other issues elsewhere aside - this code never stood a fair chance of working since the selected interpreter was not passed. |
||
|
||
with environment_as(**setup_py_execution_environment.as_environment()): | ||
# Build a whl using SetupPyRunner and return its absolute path. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,57 +4,68 @@ | |
|
||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
import logging | ||
from builtins import object | ||
from copy import copy | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class WrappedPEX(object): | ||
"""Wrapper around a PEX that exposes only its run() method. | ||
|
||
Allows us to set the PEX_PATH in the environment when running. | ||
""" | ||
|
||
_PEX_PATH_ENV_VAR_NAME = 'PEX_PATH' | ||
_PEX_PYTHON_PATH_ENV_VAR_NAME = 'PEX_PYTHON_PATH' | ||
|
||
# TODO(benjy): I think we can get rid of the interpreter argument. | ||
# In all cases it appears to be set to pex.interpreter. | ||
def __init__(self, pex, interpreter, extra_pex_paths=None): | ||
def __init__(self, pex, extra_pex_paths=None): | ||
""" | ||
:param pex: The main pex we wrap. | ||
:param interpreter: The interpreter the main pex will run on. | ||
:param extra_pex_paths: Other pexes, to "merge" in via the PEX_PATH mechanism. | ||
""" | ||
self._pex = pex | ||
self._interpreter = interpreter | ||
self._extra_pex_paths = extra_pex_paths | ||
|
||
@property | ||
def interpreter(self): | ||
return self._interpreter | ||
return self._pex._interpreter | ||
|
||
def path(self): | ||
return self._pex.path() | ||
|
||
def cmdline(self, args=()): | ||
cmdline = ' '.join(self._pex.cmdline(args)) | ||
|
||
def render_env_var(key, value): | ||
return '{key}={value}'.format(key=key, value=value) | ||
|
||
env_vars = [(self._PEX_PYTHON_PATH_ENV_VAR_NAME, self._pex._interpreter.binary)] | ||
|
||
pex_path = self._pex_path() | ||
if pex_path: | ||
return '{env_var_name}={pex_path} {cmdline}'.format(env_var_name=self._PEX_PATH_ENV_VAR_NAME, | ||
pex_path=pex_path, | ||
cmdline=cmdline) | ||
else: | ||
return cmdline | ||
env_vars.append((self._PEX_PATH_ENV_VAR_NAME, pex_path)) | ||
|
||
return '{execution_control_env_vars} {cmdline}'.format( | ||
execution_control_env_vars=' '.join(render_env_var(k, v) for k, v in env_vars), | ||
cmdline=cmdline | ||
) | ||
|
||
def run(self, *args, **kwargs): | ||
env = copy(kwargs.pop('env', {})) | ||
|
||
# Hack around bug in PEX where custom interpreters are not forwarded to PEXEnvironments. | ||
# TODO(John Sirois): Remove when XXX is fixed. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup - just finished filing on the pex side. I'll send up a final comment-only diff with issue inks here as soon as this goes green then merge: pex-tool/pex#522 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
env[self._PEX_PYTHON_PATH_ENV_VAR_NAME] = self._pex._interpreter.binary | ||
|
||
pex_path = self._pex_path() | ||
if pex_path: | ||
kwargs_copy = copy(kwargs) | ||
env = copy(kwargs_copy.get('env')) if 'env' in kwargs_copy else {} | ||
env[self._PEX_PATH_ENV_VAR_NAME] = self._pex_path() | ||
kwargs_copy['env'] = env | ||
return self._pex.run(*args, **kwargs_copy) | ||
else: | ||
return self._pex.run(*args, **kwargs) | ||
env[self._PEX_PATH_ENV_VAR_NAME] = pex_path | ||
|
||
logger.debug('Executing WrappedPEX using: {}'.format(self.cmdline(args=tuple(*args)))) | ||
return self._pex.run(*args, env=env, **kwargs) | ||
|
||
def _pex_path(self): | ||
if self._extra_pex_paths: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
YYY -> pex-tool/pex#523
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.