From 561ec7f9cb305f9a99bfff47b5e020956ca779de Mon Sep 17 00:00:00 2001 From: Kris Wilson Date: Sat, 12 May 2018 01:06:42 -0700 Subject: [PATCH] Better error handling for missing setuptools. --- .travis.yml | 4 ++-- pex/pex_builder.py | 13 +++++++++---- pex/testing.py | 23 +++++++++++++---------- tox.ini | 1 + 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/.travis.yml b/.travis.yml index 031b09910..286c55598 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,7 @@ env: global: # This is necessary to have consistent testing of methods that rely on falling back to PATH for # selecting a python interpreter. - - PATH=$PATH:$PWD/.tox/py36/bin:$PWD/.tox/py27/bin + - PATH=$PWD/.tox/py36/bin:$PWD/.tox/py27/bin:$PATH cache: directories: @@ -73,7 +73,7 @@ matrix: env: TOXENV=pypy install: - - pip install -U tox + - pip install -U tox "setuptools<34" script: - tox -v diff --git a/pex/pex_builder.py b/pex/pex_builder.py index 382bfcbcc..403fb998e 100644 --- a/pex/pex_builder.py +++ b/pex/pex_builder.py @@ -403,12 +403,17 @@ def _prepare_bootstrap(self): # self-contained. wrote_setuptools = False - setuptools = DistributionHelper.distribution_from_path( - self._interpreter.get_location('setuptools'), - name='setuptools') + setuptools_location = self._interpreter.get_location('setuptools') + if setuptools_location is None: + raise RuntimeError( + 'Failed to find setuptools via %s while building pex!' % self._interpreter.binary + ) + setuptools = DistributionHelper.distribution_from_path(setuptools_location, name='setuptools') if setuptools is None: - raise RuntimeError('Failed to find setuptools while building pex!') + raise RuntimeError( + 'Failed to find setuptools via %s while building pex!' % self._interpreter.binary + ) for fn, content_stream in DistributionHelper.walk_data(setuptools): if fn.startswith('pkg_resources') or fn.startswith('_markerlib'): diff --git a/pex/testing.py b/pex/testing.py index 40e090e4d..df756532c 100644 --- a/pex/testing.py +++ b/pex/testing.py @@ -18,6 +18,7 @@ from .installer import EggInstaller, Packager from .pex_builder import PEXBuilder from .util import DistributionHelper, named_temporary_file +from .version import SETUPTOOLS_REQUIREMENT @contextlib.contextmanager @@ -209,7 +210,6 @@ class IntegResults(namedtuple('results', 'output return_code exception traceback def assert_success(self): if not (self.exception is None and self.return_code is None): - print(self.traceback) raise AssertionError('integration test failed: return_code=%s, exception=%r, traceback=%s' % ( self.return_code, self.exception, self.traceback )) @@ -289,12 +289,12 @@ def combine_pex_coverage(coverage_file_iter): return combined.filename -def bootstrap_python_installer(install_location): - safe_rmtree(install_location) +def bootstrap_python_installer(dest): + safe_rmtree(dest) for _ in range(3): try: subprocess.check_call( - ['git', 'clone', 'https://github.com/pyenv/pyenv.git', install_location] + ['git', 'clone', 'https://github.com/pyenv/pyenv.git', dest] ) except subprocess.CalledProcessError as e: print('caught exception: %r' % e) @@ -307,13 +307,16 @@ def bootstrap_python_installer(install_location): def ensure_python_interpreter(version): pyenv_root = os.path.join(os.getcwd(), '.pyenv_test') - installer_path = os.path.join(pyenv_root, 'bin', 'pyenv') - if not os.path.exists(installer_path): + interpreter_location = os.path.join(pyenv_root, 'versions', version) + pyenv = os.path.join(pyenv_root, 'bin', 'pyenv') + pip = os.path.join(interpreter_location, 'bin', 'pip') + + if not os.path.exists(pyenv): bootstrap_python_installer(pyenv_root) - install_location = os.path.join(pyenv_root, 'versions', version) - if not os.path.exists(install_location): + if not os.path.exists(interpreter_location): os.environ['PYENV_ROOT'] = pyenv_root - subprocess.call([installer_path, 'install', version]) + subprocess.call([pyenv, 'install', version]) + subprocess.call([pip, 'install', SETUPTOOLS_REQUIREMENT]) - return os.path.join(install_location, 'bin', 'python' + version[0:3]) + return os.path.join(interpreter_location, 'bin', 'python' + version[0:3]) diff --git a/tox.ini b/tox.ini index 50350f131..3c8cd405e 100644 --- a/tox.ini +++ b/tox.ini @@ -17,6 +17,7 @@ deps = twitter.common.testing>=0.3.1,<0.4.0 wheel==0.29.0 packaging==16.8 + setuptools<34.0 py27: mock pypy: mock run: requests