Skip to content

Commit

Permalink
Better error handling for missing setuptools. (#471)
Browse files Browse the repository at this point in the history
This helped reveal the cause of #470
  • Loading branch information
kwlzn authored May 13, 2018
1 parent 9c5d7f3 commit 07b8690
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -73,7 +73,7 @@ matrix:
env: TOXENV=pypy

install:
- pip install -U tox
- pip install -U tox "setuptools<34"

script:
- tox -v
13 changes: 9 additions & 4 deletions pex/pex_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'):
Expand Down
23 changes: 13 additions & 10 deletions pex/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
))
Expand Down Expand Up @@ -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)
Expand All @@ -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])
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 07b8690

Please sign in to comment.