From bf694d833111f87861e566b7eee13856519872ff Mon Sep 17 00:00:00 2001 From: John Sirois Date: Fri, 1 Sep 2017 11:26:38 -0700 Subject: [PATCH] Leverage `subprocess32` when available. This allows for an upgrade in subprocess robustness when available that Pants will leverage for one. Also formalize the pex optional dependencies with `extras_require`, mainly for documentation purposes. --- .travis.yml | 4 ++++ pex/executor.py | 18 +++++++++++++++--- setup.py | 8 ++++++++ tox.ini | 11 +++++++---- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index ab1e376eb..302983e0f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,6 +22,10 @@ matrix: python: "2.7" env: TOXENV=py27 + - language: python + python: "2.7" + env: TOXENV=py27-subprocess + - language: python python: "2.7" env: TOXENV=py27-requests diff --git a/pex/executor.py b/pex/executor.py index 8db04d078..4541666c4 100644 --- a/pex/executor.py +++ b/pex/executor.py @@ -2,9 +2,21 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). import errno -import subprocess - -from .compatibility import string +import os + +from .compatibility import PY2, string +from .tracer import TRACER + +if os.name == 'posix' and PY2: + try: + # Use the subprocess backports if they're available for improved robustness. + import subprocess32 as subprocess + except ImportError: + TRACER.log('Please build pex with the subprocess32 module for more reliable requirement ' + 'installation and interpreter execution.') + import subprocess +else: + import subprocess class Executor(object): diff --git a/setup.py b/setup.py index 9d8b1b9ae..a1f0bedfa 100644 --- a/setup.py +++ b/setup.py @@ -56,6 +56,14 @@ SETUPTOOLS_REQUIREMENT, WHEEL_REQUIREMENT, ], + extras_require={ + # For improved subprocess robustness under python2.7. + 'subprocess': ['subprocess32>=3.2.7'], + # For improved requirement resolution and fetching robustness. + 'requests': ['requests>=2.8.14'], + # For improved requirement resolution and fetching performance. + 'cachecontrol': ['CacheControl>=0.12.3'], + }, tests_require = [ 'mock', 'twitter.common.contextutil>=0.3.1,<0.4.0', diff --git a/tox.ini b/tox.ini index 9d1f959b3..eaa206ba0 100644 --- a/tox.ini +++ b/tox.ini @@ -25,6 +25,7 @@ deps = cachecontrol: CacheControl cachecontrol: lockfile coverage: coverage==4.0.3 + subprocess: subprocess32 whitelist_externals = open [integration] @@ -77,10 +78,10 @@ deps = commands = # meta tox -e py27-coverage - tox -e py27-requests-cachecontrol-coverage - tox -e py34-requests-cachecontrol-coverage - tox -e py34-coverage - tox -e pypy-requests-cachecontrol-coverage + tox -e py27-subprocess-requests-cachecontrol-coverage + tox -e py36-requests-cachecontrol-coverage + tox -e py36-coverage + tox -e pypy-subprocess-requests-cachecontrol-coverage python scripts/combine_coverage.py coverage report coverage html @@ -137,6 +138,7 @@ commands = pex --cache-dir {envtmpdir}/buildcache wheel requests . -o dist/pex36 [testenv:py27] [testenv:py27-requests] [testenv:py27-requests-cachecontrol] +[testenv:py27-subprocess] [testenv:py33] [testenv:py33-requests] [testenv:py33-requests-cachecontrol] @@ -152,3 +154,4 @@ commands = pex --cache-dir {envtmpdir}/buildcache wheel requests . -o dist/pex36 [testenv:pypy] [testenv:pypy-requests] [testenv:pypy-requests-cachecontrol] +[testenv:pypy-subprocess]