Skip to content

Commit

Permalink
Build pexes that work on all Python patch versions. (#7550)
Browse files Browse the repository at this point in the history
We want to constrain pants.pex to run on CPython 2.7 or CPython 3.6,
but no further. Fixup CI to only request a specific patch-level in the
Python interpreter used in the two spots that care.
  • Loading branch information
jsirois authored Apr 14, 2019
1 parent a3cb9c0 commit 30fadb7
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
8 changes: 6 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -596,13 +596,17 @@ py27_osx_build_wheels_ucs4: &py27_osx_build_wheels_ucs4
- *base_build_wheels_env
- CACHE_NAME=osxwheelsbuild.ucs4
- PYTHON_CONFIGURE_OPTS=--enable-unicode=ucs4
# We set $PY to ensure the UCS4 interpreter is used when bootstrapping the PEX.
# We ensure selection of the the UCS4 interpreter by the pants script and pants.pex with these
# env vars.
- PYTHON_27_VERSION_UCS4=2.7.13
- PY=${PYENV_ROOT}/shims/python2.7
- PEX_PYTHON_PATH=${PYENV_ROOT}/shims/python2.7
- PANTS_PYTHON_SETUP_INTERPRETER_CONSTRAINTS="['CPython==${PYTHON_27_VERSION_UCS4}']"
before_install:
- curl -L https://github.com/stedolan/jq/releases/download/jq-1.5/jq-osx-amd64 -o /usr/local/bin/jq
- chmod 755 /usr/local/bin/jq
- ./build-support/bin/install_aws_cli_for_ci.sh
- ./build-support/bin/install_python_for_ci.sh 2.7.13 ${PYENV_PY36_VERSION}
- ./build-support/bin/install_python_for_ci.sh ${PYTHON_27_VERSION_UCS4} ${PYENV_PY36_VERSION}
script:
- ./build-support/bin/ci.sh -2b
- ./build-support/bin/check_pants_pex_abi.py cp27mu
Expand Down
10 changes: 2 additions & 8 deletions build-support/bin/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,11 @@ else
fi
export PY="${PY:-python${py_major_minor}}"

# Also set PANTS_PYTHON_SETUP_INTERPRETER_CONSTRAINTS. We set this to the exact Python version
# to resolve any potential ambiguity when multiple Python interpreters are discoverable, such as
# Python 2.7.10 vs. 2.7.13. When running with Python 3, we must also set this constraint to ensure
# all spawned subprocesses use Python 3 rather than the default of Python 2. This is in part
# necessary to avoid the _Py_Dealloc error (#6985).
py_major_minor_patch=$(${PY} -c 'import sys; print(".".join(map(str, sys.version_info[0:3])))')
export PANTS_PYTHON_SETUP_INTERPRETER_CONSTRAINTS="${PANTS_PYTHON_SETUP_INTERPRETER_CONSTRAINTS:-['CPython==${py_major_minor_patch}']}"
export PANTS_PYTHON_SETUP_INTERPRETER_CONSTRAINTS="${PANTS_PYTHON_SETUP_INTERPRETER_CONSTRAINTS:-['CPython==${py_major_minor}.*']}"
banner "Setting interpreter constraints to ${PANTS_PYTHON_SETUP_INTERPRETER_CONSTRAINTS}"

if [[ "${run_bootstrap:-false}" == "true" ]]; then
start_travis_section "Bootstrap" "Bootstrapping pants as a Python ${py_major_minor_patch} PEX"
start_travis_section "Bootstrap" "Bootstrapping pants as a Python ${py_major_minor} PEX"
(
if [[ "${run_bootstrap_clean:-false}" == "true" ]]; then
./build-support/python/clean.sh || die "Failed to clean before bootstrapping pants."
Expand Down
23 changes: 9 additions & 14 deletions build-support/bin/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@ done
# Reset opt parsing's position to start
OPTIND=0

# Set the Python interpreter to be used for the virtualenv. Note we allow the user to
# predefine this value so that they may point to a specific interpreter, e.g. 2.7.13 vs. 2.7.15.
default_interpreter="python2.7";
# Setup Python interpreter constraints and pick a suitable interpreter to be used for the
# virtualenv.
if [[ "${python_three:-false}" == "true" ]]; then
default_interpreter="python3.6"
interpreter_constraint="CPython==3.6.*"
else
default_interpreter="python2.7"
interpreter_constraint="CPython==2.7.*"
fi
# Note we allow the user to predefine this value so that they may point to a specific interpreter,
# e.g. 2.7.13 vs. 2.7.15.
export PY="${PY:-${default_interpreter}}"
if ! which "${PY}" >/dev/null; then
die "Python interpreter ${PY} not discoverable on your PATH."
Expand All @@ -37,12 +42,7 @@ if [[ "${py_major_minor}" != "2.7" ]] && [[ "${py_major_minor}" != "3.6" ]]; the
die "Invalid interpreter. The release script requires Python 2.7 or 3.6 (you are using ${py_major_minor})."
fi

# Also set PANTS_PYTHON_SETUP_INTERPRETER_CONSTRAINTS. We set this to the exact Python version
# to resolve any potential ambiguity when multiple Python interpreters are discoverable, such as
# Python 2.7.13 vs. 2.7.15. We must also set this when running with Python 3 to ensure
# that spawned subprocesses use Python 3.
py_major_minor_patch=$(${PY} -c 'import sys; print(".".join(map(str, sys.version_info[0:3])))')
export PANTS_PYTHON_SETUP_INTERPRETER_CONSTRAINTS="${PANTS_PYTHON_SETUP_INTERPRETER_CONSTRAINTS:-['CPython==${py_major_minor_patch}']}"
export PANTS_PYTHON_SETUP_INTERPRETER_CONSTRAINTS="['${interpreter_constraint}']"

function run_local_pants() {
${ROOT}/pants "$@"
Expand Down Expand Up @@ -658,11 +658,6 @@ function build_pex() {
platform_flags=("${platform_flags[@]}" "--platform=${platform}")
done

interpreter_constraint="CPython==2.7.*"
if [[ "${python_three:-false}" == "true" ]]; then
interpreter_constraint="CPython==3.6.*"
fi

execute_pex \
-o "${dest}" \
--script=pants \
Expand Down
3 changes: 3 additions & 0 deletions build-support/docker/travis_ci_py27_ucs2/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ RUN /usr/bin/scl enable devtoolset-7 -- ${PYENV_BIN} install ${PYTHON_27_VERSION
RUN /usr/bin/scl enable devtoolset-7 -- ${PYENV_BIN} global ${PYTHON_27_VERSION_UCS2}
ENV PATH "${PYENV_ROOT}/shims:${PATH}"

# We ensure selection of the the UCS4 interpreter by the pants script and pants.pex with these
# env vars.
ENV PY "${PYENV_ROOT}/shims/python2.7"
ENV PEX_PYTHON_PATH "${PYENV_ROOT}/shims/python2.7"
ENV PANTS_PYTHON_SETUP_INTERPRETER_CONSTRAINTS="['CPython==${PYTHON_27_VERSION_UCS2}']"

# Setup mount points for the travis ci user & workdir.
VOLUME /travis/home
Expand Down
8 changes: 6 additions & 2 deletions build-support/travis/travis.yml.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -543,11 +543,15 @@ py27_osx_build_wheels_ucs4: &py27_osx_build_wheels_ucs4
- *base_build_wheels_env
- CACHE_NAME=osxwheelsbuild.ucs4
- PYTHON_CONFIGURE_OPTS=--enable-unicode=ucs4
# We set $PY to ensure the UCS4 interpreter is used when bootstrapping the PEX.
# We ensure selection of the the UCS4 interpreter by the pants script and pants.pex with these
# env vars.
- PYTHON_27_VERSION_UCS4=2.7.13
- PY=${PYENV_ROOT}/shims/python2.7
- PEX_PYTHON_PATH=${PYENV_ROOT}/shims/python2.7
- PANTS_PYTHON_SETUP_INTERPRETER_CONSTRAINTS="['CPython==${PYTHON_27_VERSION_UCS4}']"
before_install:
{{>before_install_osx}}
- ./build-support/bin/install_python_for_ci.sh 2.7.13 ${PYENV_PY36_VERSION}
- ./build-support/bin/install_python_for_ci.sh ${PYTHON_27_VERSION_UCS4} ${PYENV_PY36_VERSION}
script:
- ./build-support/bin/ci.sh -2b
- ./build-support/bin/check_pants_pex_abi.py cp27mu
Expand Down

0 comments on commit 30fadb7

Please sign in to comment.