From 0ba37589e52d6e09035a457c97eabbcedd3a9247 Mon Sep 17 00:00:00 2001 From: Eric Arellano Date: Tue, 18 Dec 2018 09:14:55 -0700 Subject: [PATCH 01/22] Allow Pants to use Python 2 or Python 3 --- pants.ini | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pants.ini b/pants.ini index ba51a2631ef..9f6da5432b3 100644 --- a/pants.ini +++ b/pants.ini @@ -369,10 +369,11 @@ verify_commit: False [python-setup] -# We only support pants running under 2.7 for now with 3.3+ support to be added later. -# Any example or test targets that are meant to test interpreters outside pants own -# acceptable set should specify an explicit compatibility constraint. -interpreter_constraints: ["CPython>=2.7,<3"] +# We will support Python 2 until release 1.16, at which we will drop Python 2 support and +# require Python 3.6+ to run Pants. +# Note this does not mean client code has to use these specified versions, only that +# an appropriate interpreter must be discoverable. +interpreter_constraints: ["CPython>=2.7,<3","CPython>=3.6"] interpreter_cache_dir: %(pants_bootstrapdir)s/python_cache/interpreters resolver_cache_dir: %(pants_bootstrapdir)s/python_cache/requirements From 97f26bcdd1699005975898f9f76b7b41638dce13 Mon Sep 17 00:00:00 2001 From: Eric Arellano Date: Tue, 18 Dec 2018 09:52:32 -0700 Subject: [PATCH 02/22] Set Py2 constraint for CI if not Py3 Now that we allow both interpreters, we need to specify Py2 shards should use Py2, rather than just relying on the default defined in pants.ini --- build-support/bin/ci.sh | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/build-support/bin/ci.sh b/build-support/bin/ci.sh index b07a7515217..f9192715270 100755 --- a/build-support/bin/ci.sh +++ b/build-support/bin/ci.sh @@ -133,12 +133,15 @@ fi # NB: Ordering matters here. We (currently) always bootstrap a Python 2 pex. if [[ "${python_three:-false}" == "true" ]]; then - banner "Setting interpreter constraints for 3!" + banner "Setting interpreter constraints to Python 3!" export PANTS_PYTHON_SETUP_INTERPRETER_CONSTRAINTS='["CPython>=3.6,<4"]' - # TODO: Clear interpreters, otherwise this constraint does not end up applying due to a cache - # bug between the `./pants binary` and further runs. - ./pants.pex clean-all +else + banner "Setting interpreter constraints to Python 2!" + export PANTS_PYTHON_SETUP_INTERPRETER_CONSTRAINTS='["CPython>=2.7,<3"]' fi +# TODO: Clear interpreters, otherwise this constraint does not end up applying due to a cache +# bug between the `./pants binary` and further runs. +./pants.pex clean-all if [[ "${run_sanity_checks:-false}" == "true" ]]; then start_travis_section "SanityCheck" "Sanity checking bootstrapped pants and repo BUILD files" From f8799c6ade8760b38c6948ae6218b526daffb1dc Mon Sep 17 00:00:00 2001 From: Eric Arellano Date: Tue, 18 Dec 2018 09:57:27 -0700 Subject: [PATCH 03/22] Default in CI to Py3, not Py2 --- .travis.yml | 36 ++++++++++++++++++------------------ build-support/bin/ci.sh | 13 ++++++------- 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1ee7d1f5720..4bbb177bc5f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -203,92 +203,92 @@ matrix: - <<: *default_test_config name: "Py2 - Unit tests for pants and pants-plugins" script: - - ./build-support/bin/travis-ci.sh -lp + - ./build-support/bin/travis-ci.sh -2lp - <<: *default_test_config name: "Py3 - Unit tests for pants and pants-plugins" script: - - ./build-support/bin/travis-ci.sh -3lp + - ./build-support/bin/travis-ci.sh -lp - <<: *default_test_config name: "Py2 - Python contrib tests" script: - - ./build-support/bin/travis-ci.sh -n + - ./build-support/bin/travis-ci.sh -2n - <<: *default_test_config name: "Py3 - Python contrib tests" script: - - ./build-support/bin/travis-ci.sh -3n + - ./build-support/bin/travis-ci.sh -n - <<: *default_test_config name: "Integration tests for pants - shard 1" script: - - ./build-support/bin/travis-ci.sh -c3 -i 0/7 + - ./build-support/bin/travis-ci.sh -c -i 0/7 - <<: *default_test_config name: "Integration tests for pants - shard 2" script: - - ./build-support/bin/travis-ci.sh -c3 -i 1/7 + - ./build-support/bin/travis-ci.sh -c -i 1/7 - <<: *default_test_config name: "Integration tests for pants - shard 3" script: - - ./build-support/bin/travis-ci.sh -c3 -i 2/7 + - ./build-support/bin/travis-ci.sh -c -i 2/7 - <<: *default_test_config name: "Integration tests for pants - shard 4" script: - - ./build-support/bin/travis-ci.sh -c3 -i 3/7 + - ./build-support/bin/travis-ci.sh -c -i 3/7 - <<: *default_test_config name: "Integration tests for pants - shard 5" script: - - ./build-support/bin/travis-ci.sh -c3 -i 4/7 + - ./build-support/bin/travis-ci.sh -c -i 4/7 - <<: *default_test_config name: "Integration tests for pants - shard 6" script: - - ./build-support/bin/travis-ci.sh -c3 -i 5/7 + - ./build-support/bin/travis-ci.sh -c -i 5/7 - <<: *default_test_config name: "Integration tests for pants - shard 7" script: - - ./build-support/bin/travis-ci.sh -c3 -i 6/7 + - ./build-support/bin/travis-ci.sh -c -i 6/7 - <<: *default_cron_test_config name: "Integration tests for pants (Python 2) - shard 1" script: - - ./build-support/bin/travis-ci.sh -c -i 0/7 + - ./build-support/bin/travis-ci.sh -c2 -i 0/7 - <<: *default_cron_test_config name: "Integration tests for pants (Python 2) - shard 2" script: - - ./build-support/bin/travis-ci.sh -c -i 1/7 + - ./build-support/bin/travis-ci.sh -c2 -i 1/7 - <<: *default_cron_test_config name: "Integration tests for pants (Python 2) - shard 3" script: - - ./build-support/bin/travis-ci.sh -c -i 2/7 + - ./build-support/bin/travis-ci.sh -c2 -i 2/7 - <<: *default_cron_test_config name: "Integration tests for pants (Python 2) - shard 4" script: - - ./build-support/bin/travis-ci.sh -c -i 3/7 + - ./build-support/bin/travis-ci.sh -c2 -i 3/7 - <<: *default_cron_test_config name: "Integration tests for pants (Python 2) - shard 5" script: - - ./build-support/bin/travis-ci.sh -c -i 4/7 + - ./build-support/bin/travis-ci.sh -c2 -i 4/7 - <<: *default_cron_test_config name: "Integration tests for pants (Python 2) - shard 6" script: - - ./build-support/bin/travis-ci.sh -c -i 5/7 + - ./build-support/bin/travis-ci.sh -c2 -i 5/7 - <<: *default_cron_test_config name: "Integration tests for pants (Python 2) - shard 7" script: - - ./build-support/bin/travis-ci.sh -c -i 6/7 + - ./build-support/bin/travis-ci.sh -c2 -i 6/7 # Rust on linux - <<: *linux_with_fuse diff --git a/build-support/bin/ci.sh b/build-support/bin/ci.sh index f9192715270..3f61ce57c07 100755 --- a/build-support/bin/ci.sh +++ b/build-support/bin/ci.sh @@ -13,10 +13,9 @@ function usage() { cat < Date: Fri, 21 Dec 2018 21:11:58 -0700 Subject: [PATCH 04/22] Add script ./pants3 to use Python 3 under-the-hood --- build-support/pants_venv | 3 ++- build-support/virtualenv | 7 ++++--- pants3 | 9 +++++++++ 3 files changed, 15 insertions(+), 4 deletions(-) create mode 100755 pants3 diff --git a/build-support/pants_venv b/build-support/pants_venv index 4b4c3719c02..50021ac9233 100755 --- a/build-support/pants_venv +++ b/build-support/pants_venv @@ -12,7 +12,8 @@ REQUIREMENTS=( ) function venv_dir() { - echo ${REPO_ROOT}/build-support/pants_dev_deps.venv + py_version="py2"; [ "$PANTS_USE_PYTHON3" = true ] && py_version="py3" + echo ${REPO_ROOT}/build-support/pants_dev_deps.${py_version}.venv } function activate_venv() { diff --git a/build-support/virtualenv b/build-support/virtualenv index d34e285fa3d..5be2afc1c17 100755 --- a/build-support/virtualenv +++ b/build-support/virtualenv @@ -14,10 +14,11 @@ fi source ${REPO_ROOT}/build-support/common.sh if [[ -z "${PY}" ]]; then - if which python2.7 >/dev/null; then - PY=`which python2.7` + python_bin_name="python2.7"; [ "$PANTS_USE_PYTHON3" = true ] && python_bin_name="python3" + if which "${python_bin_name}" >/dev/null; then + PY=`which ${python_bin_name}` else - die 'No python2.7 interpreter found on the path. Python will not work!' + die "No ${python_bin_name} interpreter found on the path. Python will not work!" fi fi diff --git a/pants3 b/pants3 new file mode 100755 index 00000000000..be193972a4e --- /dev/null +++ b/pants3 @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +# Copyright 2018 Pants project contributors (see CONTRIBUTORS.md). +# Licensed under the Apache License, Version 2.0 (see LICENSE). + +# This bootstrap script invokes Pants using a Python 3 interpreter. + +export PANTS_USE_PYTHON3=true +./pants $@ +unset PANTS_USE_PYTHON3 From c6e2bc9da03d7de25ff0493638ed14a8aaf4d935 Mon Sep 17 00:00:00 2001 From: Eric Arellano Date: Fri, 21 Dec 2018 21:12:14 -0700 Subject: [PATCH 05/22] Revert "Default in CI to Py3, not Py2" This reverts commit f8799c6ade8760b38c6948ae6218b526daffb1dc. --- .travis.yml | 36 ++++++++++++++++++------------------ build-support/bin/ci.sh | 13 +++++++------ 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4bbb177bc5f..1ee7d1f5720 100644 --- a/.travis.yml +++ b/.travis.yml @@ -203,92 +203,92 @@ matrix: - <<: *default_test_config name: "Py2 - Unit tests for pants and pants-plugins" script: - - ./build-support/bin/travis-ci.sh -2lp + - ./build-support/bin/travis-ci.sh -lp - <<: *default_test_config name: "Py3 - Unit tests for pants and pants-plugins" script: - - ./build-support/bin/travis-ci.sh -lp + - ./build-support/bin/travis-ci.sh -3lp - <<: *default_test_config name: "Py2 - Python contrib tests" script: - - ./build-support/bin/travis-ci.sh -2n + - ./build-support/bin/travis-ci.sh -n - <<: *default_test_config name: "Py3 - Python contrib tests" script: - - ./build-support/bin/travis-ci.sh -n + - ./build-support/bin/travis-ci.sh -3n - <<: *default_test_config name: "Integration tests for pants - shard 1" script: - - ./build-support/bin/travis-ci.sh -c -i 0/7 + - ./build-support/bin/travis-ci.sh -c3 -i 0/7 - <<: *default_test_config name: "Integration tests for pants - shard 2" script: - - ./build-support/bin/travis-ci.sh -c -i 1/7 + - ./build-support/bin/travis-ci.sh -c3 -i 1/7 - <<: *default_test_config name: "Integration tests for pants - shard 3" script: - - ./build-support/bin/travis-ci.sh -c -i 2/7 + - ./build-support/bin/travis-ci.sh -c3 -i 2/7 - <<: *default_test_config name: "Integration tests for pants - shard 4" script: - - ./build-support/bin/travis-ci.sh -c -i 3/7 + - ./build-support/bin/travis-ci.sh -c3 -i 3/7 - <<: *default_test_config name: "Integration tests for pants - shard 5" script: - - ./build-support/bin/travis-ci.sh -c -i 4/7 + - ./build-support/bin/travis-ci.sh -c3 -i 4/7 - <<: *default_test_config name: "Integration tests for pants - shard 6" script: - - ./build-support/bin/travis-ci.sh -c -i 5/7 + - ./build-support/bin/travis-ci.sh -c3 -i 5/7 - <<: *default_test_config name: "Integration tests for pants - shard 7" script: - - ./build-support/bin/travis-ci.sh -c -i 6/7 + - ./build-support/bin/travis-ci.sh -c3 -i 6/7 - <<: *default_cron_test_config name: "Integration tests for pants (Python 2) - shard 1" script: - - ./build-support/bin/travis-ci.sh -c2 -i 0/7 + - ./build-support/bin/travis-ci.sh -c -i 0/7 - <<: *default_cron_test_config name: "Integration tests for pants (Python 2) - shard 2" script: - - ./build-support/bin/travis-ci.sh -c2 -i 1/7 + - ./build-support/bin/travis-ci.sh -c -i 1/7 - <<: *default_cron_test_config name: "Integration tests for pants (Python 2) - shard 3" script: - - ./build-support/bin/travis-ci.sh -c2 -i 2/7 + - ./build-support/bin/travis-ci.sh -c -i 2/7 - <<: *default_cron_test_config name: "Integration tests for pants (Python 2) - shard 4" script: - - ./build-support/bin/travis-ci.sh -c2 -i 3/7 + - ./build-support/bin/travis-ci.sh -c -i 3/7 - <<: *default_cron_test_config name: "Integration tests for pants (Python 2) - shard 5" script: - - ./build-support/bin/travis-ci.sh -c2 -i 4/7 + - ./build-support/bin/travis-ci.sh -c -i 4/7 - <<: *default_cron_test_config name: "Integration tests for pants (Python 2) - shard 6" script: - - ./build-support/bin/travis-ci.sh -c2 -i 5/7 + - ./build-support/bin/travis-ci.sh -c -i 5/7 - <<: *default_cron_test_config name: "Integration tests for pants (Python 2) - shard 7" script: - - ./build-support/bin/travis-ci.sh -c2 -i 6/7 + - ./build-support/bin/travis-ci.sh -c -i 6/7 # Rust on linux - <<: *linux_with_fuse diff --git a/build-support/bin/ci.sh b/build-support/bin/ci.sh index 3f61ce57c07..f9192715270 100755 --- a/build-support/bin/ci.sh +++ b/build-support/bin/ci.sh @@ -13,9 +13,10 @@ function usage() { cat < Date: Fri, 21 Dec 2018 21:12:30 -0700 Subject: [PATCH 06/22] Revert "Set Py2 constraint for CI if not Py3" This reverts commit 97f26bcdd1699005975898f9f76b7b41638dce13. --- build-support/bin/ci.sh | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/build-support/bin/ci.sh b/build-support/bin/ci.sh index f9192715270..b07a7515217 100755 --- a/build-support/bin/ci.sh +++ b/build-support/bin/ci.sh @@ -133,15 +133,12 @@ fi # NB: Ordering matters here. We (currently) always bootstrap a Python 2 pex. if [[ "${python_three:-false}" == "true" ]]; then - banner "Setting interpreter constraints to Python 3!" + banner "Setting interpreter constraints for 3!" export PANTS_PYTHON_SETUP_INTERPRETER_CONSTRAINTS='["CPython>=3.6,<4"]' -else - banner "Setting interpreter constraints to Python 2!" - export PANTS_PYTHON_SETUP_INTERPRETER_CONSTRAINTS='["CPython>=2.7,<3"]' + # TODO: Clear interpreters, otherwise this constraint does not end up applying due to a cache + # bug between the `./pants binary` and further runs. + ./pants.pex clean-all fi -# TODO: Clear interpreters, otherwise this constraint does not end up applying due to a cache -# bug between the `./pants binary` and further runs. -./pants.pex clean-all if [[ "${run_sanity_checks:-false}" == "true" ]]; then start_travis_section "SanityCheck" "Sanity checking bootstrapped pants and repo BUILD files" From a9b31cbb361d509bab7d9e7b71609660cd6aaeaf Mon Sep 17 00:00:00 2001 From: Eric Arellano Date: Sat, 22 Dec 2018 09:22:46 -0700 Subject: [PATCH 07/22] Update remaining references to pants_dev_deps.venv --- build-support/python/clean.sh | 1 + src/docs/export.md | 2 +- src/docs/intellij.md | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/build-support/python/clean.sh b/build-support/python/clean.sh index 65119ffb0aa..a0a0dab3bdc 100755 --- a/build-support/python/clean.sh +++ b/build-support/python/clean.sh @@ -3,5 +3,6 @@ PANTS_BASE=$(dirname $0)/../.. rm -rf ${HOME}/.pex rm -rf ${PANTS_BASE}/build-support/pants_dev_deps.venv +rm -rf ${PANTS_BASE}/build-support/pants_dev_deps.py{2,3}.venv rm -rf ${PANTS_BASE}/.pants.d find ${PANTS_BASE} -name '*.pyc' | xargs rm -f diff --git a/src/docs/export.md b/src/docs/export.md index 4902de7b38a..dc09e3128c1 100644 --- a/src/docs/export.md +++ b/src/docs/export.md @@ -101,7 +101,7 @@ The following is an abbreviated export file from a command in the pants repo: "python_setup": { "interpreters": { "CPython-2.7.10": { - "binary": "/Users/user/pants/build-support/pants_dev_deps.venv/bin/python2.7", + "binary": "/Users/user/pants/build-support/pants_dev_deps.py2.venv/bin/python2.7", "chroot": "/Users/user/pants/.pants.d/python-setup/chroots/e8da2c200f36ca0a1b8a60c12590a59209250b1a" } }, diff --git a/src/docs/intellij.md b/src/docs/intellij.md index e8f3fa0ab8f..df442bc80ed 100644 --- a/src/docs/intellij.md +++ b/src/docs/intellij.md @@ -44,7 +44,7 @@ SDK". ![image](images/intellij-new-pythonsdk.png) This will be a "local" interpreter and you'll need to select the virtual -environment bootstrapped above; it's in `build-support/pants_dev_deps.venv`. +environment bootstrapped above; it's in `build-support/pants_dev_deps.py2.venv` if you want to use Python 2 or `build-support/pants_dev_deps.py3.venv` if you want to use Python 3 for the underlying Pants engine. ![image](images/intellij-select-venv.png) From 4b46d189a116b8f5a8036f4908475ac86d19e0b9 Mon Sep 17 00:00:00 2001 From: Eric Arellano Date: Sat, 22 Dec 2018 09:55:06 -0700 Subject: [PATCH 08/22] Default to Py2.7 or Py3.6+ in python_setup.py --- src/python/pants/backend/python/subsystems/python_setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python/pants/backend/python/subsystems/python_setup.py b/src/python/pants/backend/python/subsystems/python_setup.py index 76bc246196b..b772b685c34 100644 --- a/src/python/pants/backend/python/subsystems/python_setup.py +++ b/src/python/pants/backend/python/subsystems/python_setup.py @@ -26,7 +26,7 @@ class PythonSetup(Subsystem): @classmethod def register_options(cls, register): super(PythonSetup, cls).register_options(register) - register('--interpreter-constraints', advanced=True, default=['CPython>=2.7,<3'], type=list, + register('--interpreter-constraints', advanced=True, default=['CPython>=2.7,<3', 'CPython>=3.6'], type=list, metavar='', help="Constrain the selected Python interpreter. Specify with requirement syntax, " "e.g. 'CPython>=2.7,<3' (A CPython interpreter with version >=2.7 AND version <3)" From 3d3e4b7be0e2ce19c652e8c1fc86cfe3e2021358 Mon Sep 17 00:00:00 2001 From: Eric Arellano Date: Sat, 22 Dec 2018 18:19:51 -0700 Subject: [PATCH 09/22] Review feedback Thanks Yi! --- build-support/pants_venv | 2 +- build-support/virtualenv | 2 +- pants3 | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/build-support/pants_venv b/build-support/pants_venv index 50021ac9233..566b1484489 100755 --- a/build-support/pants_venv +++ b/build-support/pants_venv @@ -12,7 +12,7 @@ REQUIREMENTS=( ) function venv_dir() { - py_version="py2"; [ "$PANTS_USE_PYTHON3" = true ] && py_version="py3" + py_version="py2"; [ "${PANTS_USE_PYTHON3}" = true ] && py_version="py3" echo ${REPO_ROOT}/build-support/pants_dev_deps.${py_version}.venv } diff --git a/build-support/virtualenv b/build-support/virtualenv index 5be2afc1c17..3478f2a704d 100755 --- a/build-support/virtualenv +++ b/build-support/virtualenv @@ -14,7 +14,7 @@ fi source ${REPO_ROOT}/build-support/common.sh if [[ -z "${PY}" ]]; then - python_bin_name="python2.7"; [ "$PANTS_USE_PYTHON3" = true ] && python_bin_name="python3" + python_bin_name="python2.7"; [ "${PANTS_USE_PYTHON3}" = true ] && python_bin_name="python3" if which "${python_bin_name}" >/dev/null; then PY=`which ${python_bin_name}` else diff --git a/pants3 b/pants3 index be193972a4e..3aaf84d992e 100755 --- a/pants3 +++ b/pants3 @@ -6,4 +6,3 @@ export PANTS_USE_PYTHON3=true ./pants $@ -unset PANTS_USE_PYTHON3 From 49418a0ded5a4ed1e0480a3a45a3eca13dc86a96 Mon Sep 17 00:00:00 2001 From: Eric Arellano Date: Sat, 22 Dec 2018 19:01:19 -0700 Subject: [PATCH 10/22] Fix .travis.yml caching old venv folder The Linux Build Engine shard was failing due to using the Python bin path stored in ~/.cache/pants before renaming pants_dev_deps.venv to pants_dev_deps.py{2,3}.venv. I realized we can get around this by deleting the cache through Travis's UI, but we need to also change what we cache for the future. --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 1ee7d1f5720..e2c7092d3a3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -50,7 +50,8 @@ cache: # using its own isolated cache: # https://github.com/pantsbuild/pants/issues/2485 - ${HOME}/.npm - - build-support/pants_dev_deps.venv + - build-support/pants_dev_deps.py2.venv + - build-support/pants_dev_deps.py3.venv - src/rust/engine/target # Stages are documented here: https://docs.travis-ci.com/user/build-stages From a591448fd08e1b66925415d85ec420c760688997 Mon Sep 17 00:00:00 2001 From: Eric Arellano Date: Sat, 22 Dec 2018 19:44:34 -0700 Subject: [PATCH 11/22] Delete `pants_dev_deps.venv` the first time new venv folder setup Now that we're using the `.py2.venv` and `.py3.venv` folders, it's confusing to keep this original one. Simply remove it the first time the user sets up the new folders. --- build-support/pants_venv | 3 +++ 1 file changed, 3 insertions(+) diff --git a/build-support/pants_venv b/build-support/pants_venv index 566b1484489..587ffc47066 100755 --- a/build-support/pants_venv +++ b/build-support/pants_venv @@ -22,6 +22,9 @@ function activate_venv() { function create_venv() { rm -rf "$(venv_dir)" + # Also delete `pants_dev_deps.venv` to remove legacy folder now that + # we use `pants_dev_deps.py2.venv` and `pants_dev_deps.py3.venv` folders + rm -rf "${REPO_ROOT}/build-support/pants_dev_deps.venv" "${REPO_ROOT}/build-support/virtualenv" "$(venv_dir)" } From 37dab44ee3bd1f56e67ec38bbcbcf8c14a72ae28 Mon Sep 17 00:00:00 2001 From: Eric Arellano Date: Sat, 22 Dec 2018 22:10:43 -0700 Subject: [PATCH 12/22] Restrict Python 3 to either 3.6 or 3.7 Failing contrib/python/../test_checkstyle.py tests raised the question of if we want to set an upper limit for compatibility, which is required for those tests to function properly. I realized an upper limit makes sense. Even though it's not yet released, Pants would not support Python 3.8 at the moment, due to several major deprecations become removals. We should only turn on Python 3.8 support when we are ready to do so (in 1 year at release, hopefully). --- pants.ini | 2 +- src/python/pants/backend/python/subsystems/python_setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pants.ini b/pants.ini index 9f6da5432b3..2d29b4dd31e 100644 --- a/pants.ini +++ b/pants.ini @@ -373,7 +373,7 @@ verify_commit: False # require Python 3.6+ to run Pants. # Note this does not mean client code has to use these specified versions, only that # an appropriate interpreter must be discoverable. -interpreter_constraints: ["CPython>=2.7,<3","CPython>=3.6"] +interpreter_constraints: ["CPython>=2.7,<3","CPython>=3.6,<3.8"] interpreter_cache_dir: %(pants_bootstrapdir)s/python_cache/interpreters resolver_cache_dir: %(pants_bootstrapdir)s/python_cache/requirements diff --git a/src/python/pants/backend/python/subsystems/python_setup.py b/src/python/pants/backend/python/subsystems/python_setup.py index b772b685c34..291114e6411 100644 --- a/src/python/pants/backend/python/subsystems/python_setup.py +++ b/src/python/pants/backend/python/subsystems/python_setup.py @@ -26,7 +26,7 @@ class PythonSetup(Subsystem): @classmethod def register_options(cls, register): super(PythonSetup, cls).register_options(register) - register('--interpreter-constraints', advanced=True, default=['CPython>=2.7,<3', 'CPython>=3.6'], type=list, + register('--interpreter-constraints', advanced=True, default=['CPython>=2.7,<3', 'CPython>=3.6,<3.8'], type=list, metavar='', help="Constrain the selected Python interpreter. Specify with requirement syntax, " "e.g. 'CPython>=2.7,<3' (A CPython interpreter with version >=2.7 AND version <3)" From 1134af5b936f6f6977242379da42359f3c206a13 Mon Sep 17 00:00:00 2001 From: Eric Arellano Date: Sat, 22 Dec 2018 22:13:07 -0700 Subject: [PATCH 13/22] Fix failing test_checkstyle.py by changing Py3 upper limit Now that we by default allow Python 3.6, the former whitelist being tested of allowing Python 3.6 became irrelevant. Instead, we must whitelist an interpreter that we do not allow by default, e.g. Python 3.8. --- .../checks/tasks/checkstyle/test_checkstyle.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/contrib/python/tests/python/pants_test/contrib/python/checks/tasks/checkstyle/test_checkstyle.py b/contrib/python/tests/python/pants_test/contrib/python/checks/tasks/checkstyle/test_checkstyle.py index 5a6f54b36eb..773673d8f32 100644 --- a/contrib/python/tests/python/pants_test/contrib/python/checks/tasks/checkstyle/test_checkstyle.py +++ b/contrib/python/tests/python/pants_test/contrib/python/checks/tasks/checkstyle/test_checkstyle.py @@ -173,7 +173,7 @@ def test_lint_runs_for_blanket_whitelist(self): print(x+7) """)) target_py3 = self.make_target('a/python:fail3', PythonLibrary, sources=['fail_py3.py'], - compatibility=['CPython>=3.6']) + compatibility=['CPython>=3.8']) self.set_options(interpreter_constraints_whitelist=[]) with self.assertRaises(TaskError) as task_error: self.execute_task(target_roots=[target_py2, target_py3]) @@ -191,7 +191,7 @@ def test_lint_runs_for_default_constraints_only(self): print(x+7) """)) target_py3 = self.make_target('a/python:fail3', PythonLibrary, sources=['fail_py3.py'], - compatibility=['CPython>=3.6']) + compatibility=['CPython>=3.8']) with self.assertRaises(TaskError) as task_error: self.execute_task(target_roots=[target_py2, target_py3]) self.assertIn('4 Python Style issues found', str(task_error.exception)) @@ -202,7 +202,7 @@ def test_lint_ignores_unwhitelisted_constraints(self): print(x+7) """)) target_py3 = self.make_target('a/python:fail3', PythonLibrary, sources=['fail_py3.py'], - compatibility=['CPython>=3.6']) + compatibility=['CPython>=3.8']) self.assertEqual(0, self.execute_task(target_roots=[target_py3])) def test_lint_runs_for_single_whitelisted_constraints(self): @@ -211,8 +211,8 @@ def test_lint_runs_for_single_whitelisted_constraints(self): print(x+7) """)) target_py3 = self.make_target('a/python:fail3', PythonLibrary, sources=['fail_py3.py'], - compatibility=['CPython>=3.6']) - self.set_options(interpreter_constraints_whitelist=["CPython>=3.6"]) + compatibility=['CPython>=3.8']) + self.set_options(interpreter_constraints_whitelist=["CPython>=3.8"]) with self.assertRaises(TaskError) as task_error: self.execute_task(target_roots=[target_py3]) self.assertIn('3 Python Style issues found', str(task_error.exception)) @@ -229,8 +229,8 @@ def test_lint_runs_for_multiple_whitelisted_constraints(self): print(x+7) """)) target_py3 = self.make_target('a/python:fail3', PythonLibrary, sources=['fail_py3.py'], - compatibility=['CPython>=3.6']) - self.set_options(interpreter_constraints_whitelist=["CPython>=2.6", "CPython>=3.6"]) + compatibility=['CPython>=3.8']) + self.set_options(interpreter_constraints_whitelist=["CPython>=2.6", "CPython>=3.8"]) with self.assertRaises(TaskError) as task_error: self.execute_task(target_roots=[target_py2, target_py3]) self.assertIn('7 Python Style issues found', str(task_error.exception)) @@ -247,8 +247,8 @@ def test_lint_runs_for_default_constraints_and_matching_whitelist(self): print(x+7) """)) target_py3 = self.make_target('a/python:fail3', PythonLibrary, sources=['fail_py3.py'], - compatibility=['CPython>=3.6']) - self.set_options(interpreter_constraints_whitelist=["CPython>=3.6"]) + compatibility=['CPython>=3.8']) + self.set_options(interpreter_constraints_whitelist=["CPython>=3.8"]) with self.assertRaises(TaskError) as task_error: self.execute_task(target_roots=[target_py2, target_py3]) self.assertIn('7 Python Style issues found', str(task_error.exception)) From f6e38169fb7a398d52a7781ace8ab15e3893afe9 Mon Sep 17 00:00:00 2001 From: Eric Arellano Date: Sun, 23 Dec 2018 09:18:58 -0700 Subject: [PATCH 14/22] Revert "Fix failing test_checkstyle.py by changing Py3 upper limit" This reverts commit 1134af5b936f6f6977242379da42359f3c206a13. Instead this problem is being addressed in https://github.com/pantsbuild/pants/pull/6983. --- .../checks/tasks/checkstyle/test_checkstyle.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/contrib/python/tests/python/pants_test/contrib/python/checks/tasks/checkstyle/test_checkstyle.py b/contrib/python/tests/python/pants_test/contrib/python/checks/tasks/checkstyle/test_checkstyle.py index 773673d8f32..5a6f54b36eb 100644 --- a/contrib/python/tests/python/pants_test/contrib/python/checks/tasks/checkstyle/test_checkstyle.py +++ b/contrib/python/tests/python/pants_test/contrib/python/checks/tasks/checkstyle/test_checkstyle.py @@ -173,7 +173,7 @@ def test_lint_runs_for_blanket_whitelist(self): print(x+7) """)) target_py3 = self.make_target('a/python:fail3', PythonLibrary, sources=['fail_py3.py'], - compatibility=['CPython>=3.8']) + compatibility=['CPython>=3.6']) self.set_options(interpreter_constraints_whitelist=[]) with self.assertRaises(TaskError) as task_error: self.execute_task(target_roots=[target_py2, target_py3]) @@ -191,7 +191,7 @@ def test_lint_runs_for_default_constraints_only(self): print(x+7) """)) target_py3 = self.make_target('a/python:fail3', PythonLibrary, sources=['fail_py3.py'], - compatibility=['CPython>=3.8']) + compatibility=['CPython>=3.6']) with self.assertRaises(TaskError) as task_error: self.execute_task(target_roots=[target_py2, target_py3]) self.assertIn('4 Python Style issues found', str(task_error.exception)) @@ -202,7 +202,7 @@ def test_lint_ignores_unwhitelisted_constraints(self): print(x+7) """)) target_py3 = self.make_target('a/python:fail3', PythonLibrary, sources=['fail_py3.py'], - compatibility=['CPython>=3.8']) + compatibility=['CPython>=3.6']) self.assertEqual(0, self.execute_task(target_roots=[target_py3])) def test_lint_runs_for_single_whitelisted_constraints(self): @@ -211,8 +211,8 @@ def test_lint_runs_for_single_whitelisted_constraints(self): print(x+7) """)) target_py3 = self.make_target('a/python:fail3', PythonLibrary, sources=['fail_py3.py'], - compatibility=['CPython>=3.8']) - self.set_options(interpreter_constraints_whitelist=["CPython>=3.8"]) + compatibility=['CPython>=3.6']) + self.set_options(interpreter_constraints_whitelist=["CPython>=3.6"]) with self.assertRaises(TaskError) as task_error: self.execute_task(target_roots=[target_py3]) self.assertIn('3 Python Style issues found', str(task_error.exception)) @@ -229,8 +229,8 @@ def test_lint_runs_for_multiple_whitelisted_constraints(self): print(x+7) """)) target_py3 = self.make_target('a/python:fail3', PythonLibrary, sources=['fail_py3.py'], - compatibility=['CPython>=3.8']) - self.set_options(interpreter_constraints_whitelist=["CPython>=2.6", "CPython>=3.8"]) + compatibility=['CPython>=3.6']) + self.set_options(interpreter_constraints_whitelist=["CPython>=2.6", "CPython>=3.6"]) with self.assertRaises(TaskError) as task_error: self.execute_task(target_roots=[target_py2, target_py3]) self.assertIn('7 Python Style issues found', str(task_error.exception)) @@ -247,8 +247,8 @@ def test_lint_runs_for_default_constraints_and_matching_whitelist(self): print(x+7) """)) target_py3 = self.make_target('a/python:fail3', PythonLibrary, sources=['fail_py3.py'], - compatibility=['CPython>=3.8']) - self.set_options(interpreter_constraints_whitelist=["CPython>=3.8"]) + compatibility=['CPython>=3.6']) + self.set_options(interpreter_constraints_whitelist=["CPython>=3.6"]) with self.assertRaises(TaskError) as task_error: self.execute_task(target_roots=[target_py2, target_py3]) self.assertIn('7 Python Style issues found', str(task_error.exception)) From 6ee312ede2ea00817d956a07adf473606ce3f04a Mon Sep 17 00:00:00 2001 From: Eric Arellano Date: Sun, 23 Dec 2018 09:20:52 -0700 Subject: [PATCH 15/22] Allow Python 3.6+ to comply with Pants policy --- pants.ini | 2 +- src/python/pants/backend/python/subsystems/python_setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pants.ini b/pants.ini index 2d29b4dd31e..50b104e6f53 100644 --- a/pants.ini +++ b/pants.ini @@ -373,7 +373,7 @@ verify_commit: False # require Python 3.6+ to run Pants. # Note this does not mean client code has to use these specified versions, only that # an appropriate interpreter must be discoverable. -interpreter_constraints: ["CPython>=2.7,<3","CPython>=3.6,<3.8"] +interpreter_constraints: ["CPython>=2.7,<3","CPython>=3.6,<4"] interpreter_cache_dir: %(pants_bootstrapdir)s/python_cache/interpreters resolver_cache_dir: %(pants_bootstrapdir)s/python_cache/requirements diff --git a/src/python/pants/backend/python/subsystems/python_setup.py b/src/python/pants/backend/python/subsystems/python_setup.py index 291114e6411..4b6009db65e 100644 --- a/src/python/pants/backend/python/subsystems/python_setup.py +++ b/src/python/pants/backend/python/subsystems/python_setup.py @@ -26,7 +26,7 @@ class PythonSetup(Subsystem): @classmethod def register_options(cls, register): super(PythonSetup, cls).register_options(register) - register('--interpreter-constraints', advanced=True, default=['CPython>=2.7,<3', 'CPython>=3.6,<3.8'], type=list, + register('--interpreter-constraints', advanced=True, default=['CPython>=2.7,<3', 'CPython>=3.6,<4'], type=list, metavar='', help="Constrain the selected Python interpreter. Specify with requirement syntax, " "e.g. 'CPython>=2.7,<3' (A CPython interpreter with version >=2.7 AND version <3)" From 8e0c14902ec044cb0c93369de086fe526feb85ca Mon Sep 17 00:00:00 2001 From: Eric Arellano Date: Sun, 23 Dec 2018 09:21:33 -0700 Subject: [PATCH 16/22] Quotes around arg --- pants3 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pants3 b/pants3 index 3aaf84d992e..0675a2e6738 100755 --- a/pants3 +++ b/pants3 @@ -5,4 +5,4 @@ # This bootstrap script invokes Pants using a Python 3 interpreter. export PANTS_USE_PYTHON3=true -./pants $@ +./pants "$@" From 911fc784c615bf97b155ed10a86994db2e290feb Mon Sep 17 00:00:00 2001 From: Eric Arellano Date: Sun, 23 Dec 2018 15:22:48 -0700 Subject: [PATCH 17/22] Remove bad trailing whitespace --- build-support/pants_venv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-support/pants_venv b/build-support/pants_venv index 587ffc47066..23f4b9e61b1 100755 --- a/build-support/pants_venv +++ b/build-support/pants_venv @@ -22,7 +22,7 @@ function activate_venv() { function create_venv() { rm -rf "$(venv_dir)" - # Also delete `pants_dev_deps.venv` to remove legacy folder now that + # Also delete `pants_dev_deps.venv` to remove legacy folder now that # we use `pants_dev_deps.py2.venv` and `pants_dev_deps.py3.venv` folders rm -rf "${REPO_ROOT}/build-support/pants_dev_deps.venv" "${REPO_ROOT}/build-support/virtualenv" "$(venv_dir)" From 3940331f8b0fe4eb39b89e2d6ff4a32aa0060357 Mon Sep 17 00:00:00 2001 From: Eric Arellano Date: Wed, 9 Jan 2019 06:38:20 -0700 Subject: [PATCH 18/22] Rebuild native engine when interpreter changes This fixes the _Py_Dealloc issue when changing between `./pants` and `./pants3`, as the native engine does not work with Python 2 when it was built using Python 3. --- src/rust/engine/src/cffi_build.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/rust/engine/src/cffi_build.rs b/src/rust/engine/src/cffi_build.rs index 0c81313bf68..a865ddbe30c 100644 --- a/src/rust/engine/src/cffi_build.rs +++ b/src/rust/engine/src/cffi_build.rs @@ -109,6 +109,13 @@ fn main() -> Result<(), CffiBuildError> { // (which is equivalent to `-ldylib=stdc++`). // * Specifying `rustc-link-lib=stdc++` // (which is equivalent to `rustc-link-lib=dylib=stdc++). + + // NB: When built with Python 3, `native_engine.so` only works with a Python 3 interpreter. + // When built with Python 2, it works with both Python 2 and Python 3. + // So, we check to see if the under-the-hood interpreter has changed and rebuild the native engine + // when needed. + println!("rerun-if-env-changed=PANTS_USE_PYTHON3"); + if cfg!(target_os = "linux") { println!("cargo:rustc-link-lib=static=stdc++"); } From 68ad660dae967038104c913a8325ad9004d5397c Mon Sep 17 00:00:00 2001 From: Eric Arellano Date: Wed, 9 Jan 2019 08:03:58 -0700 Subject: [PATCH 19/22] Delete python_cache/interpreters first time changing to new venv folder name scheme --- build-support/pants_venv | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/build-support/pants_venv b/build-support/pants_venv index 23f4b9e61b1..47a344549e9 100755 --- a/build-support/pants_venv +++ b/build-support/pants_venv @@ -22,9 +22,15 @@ function activate_venv() { function create_venv() { rm -rf "$(venv_dir)" - # Also delete `pants_dev_deps.venv` to remove legacy folder now that - # we use `pants_dev_deps.py2.venv` and `pants_dev_deps.py3.venv` folders - rm -rf "${REPO_ROOT}/build-support/pants_dev_deps.venv" + # If `pants_dev_deps.venv` still exists, delete both its legacy folder and the cached + # Python interpreter folder, which contains problematic symlinks. + # Note we only perform these removals for the first time, to avoid continually deleting + # the cache when switching between using `pants_dev_deps.py2.venv` and `pants_dev_deps.py3.venv`. + legacy_venv_dir="${REPO_ROOT}/build-support/pants_dev_deps.venv" + if [ -d "${legacy_venv_dir}" ]; then + rm -rf "${legacy_venv_dir}" + rm -rf "${HOME}/.cache/pants/python_cache/interpreters" + fi "${REPO_ROOT}/build-support/virtualenv" "$(venv_dir)" } From 5583d8c79ca17f3b5762310bc604ce6c7c9a890b Mon Sep 17 00:00:00 2001 From: Eric Arellano Date: Wed, 9 Jan 2019 09:06:33 -0700 Subject: [PATCH 20/22] Use Python 3 for subprocesses There is a matrix of what interpreter we use for under-the-hood and what we use for subprocesses. Presumably, when calling `./pants3`, you would expect to also run your tests and subprocesses with Py3. This change is not only nice-to-have but also required because the native engine does not work when bootstrapped with Python 3 and running a Python 2 subprocess *if* that subprocess uses `native_engine.so`, as several of our tests do. This may result in conflicts when trying to run Py2-only targets, e.g. python_antlr_library.py. If this is the case, we can resort to https://github.com/pantsbuild/pants/pull/7048 as an alternative solution. --- pants3 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pants3 b/pants3 index 0675a2e6738..cd5d1f5f068 100755 --- a/pants3 +++ b/pants3 @@ -4,5 +4,10 @@ # This bootstrap script invokes Pants using a Python 3 interpreter. +# Use Py3 under-the-hood export PANTS_USE_PYTHON3=true + +# Use Py3 for subprocesses +export PANTS_PYTHON_SETUP_INTERPRETER_CONSTRAINTS='["CPython>=3.6,<4"]' + ./pants "$@" From 0f5e4105337f0be83e7972279642904713a9d8d2 Mon Sep 17 00:00:00 2001 From: Eric Arellano Date: Sat, 12 Jan 2019 23:32:12 -0700 Subject: [PATCH 21/22] Update copyright for pants3 to 2019 --- pants3 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pants3 b/pants3 index cd5d1f5f068..750b829ad09 100755 --- a/pants3 +++ b/pants3 @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# Copyright 2018 Pants project contributors (see CONTRIBUTORS.md). +# Copyright 2019 Pants project contributors (see CONTRIBUTORS.md). # Licensed under the Apache License, Version 2.0 (see LICENSE). # This bootstrap script invokes Pants using a Python 3 interpreter. From 4217dd48cb404f29f519b7a44449c9a1d5867085 Mon Sep 17 00:00:00 2001 From: Eric Arellano Date: Sun, 13 Jan 2019 09:38:58 -0700 Subject: [PATCH 22/22] Actually rebuild engine when changing interpreter Leaving off the `cargo:` part meant this line was ignored. Now we can consistently switch between `./pants` and `./pants3`, and we won't get the _Py_Dealloc issue. Note that it does not always rebuild, as we seem to cache the interpreter-specific native_engine.so after the first time it's built (in ~/.cache/pants/bin/native-engine), which is neat! So we can safely switch between `./pants` and `./pants3`, without having to wait for it to always recompile! I also checked to make sure it's idempotent, i.e. it doesn't recompile when you keep doing `./pants3` or keep doing `./pants`. This was tested a few times on macOS and Ubuntu. --- src/rust/engine/src/cffi_build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rust/engine/src/cffi_build.rs b/src/rust/engine/src/cffi_build.rs index a865ddbe30c..9a6e67124e9 100644 --- a/src/rust/engine/src/cffi_build.rs +++ b/src/rust/engine/src/cffi_build.rs @@ -114,7 +114,7 @@ fn main() -> Result<(), CffiBuildError> { // When built with Python 2, it works with both Python 2 and Python 3. // So, we check to see if the under-the-hood interpreter has changed and rebuild the native engine // when needed. - println!("rerun-if-env-changed=PANTS_USE_PYTHON3"); + println!("cargo:rerun-if-env-changed=PANTS_USE_PYTHON3"); if cfg!(target_os = "linux") { println!("cargo:rustc-link-lib=static=stdc++");