Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Pants to run with Python 3 via ./pants3 script #6959

Merged
merged 25 commits into from
Jan 14, 2019
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0ba3758
Allow Pants to use Python 2 or Python 3
Eric-Arellano Dec 18, 2018
97f26bc
Set Py2 constraint for CI if not Py3
Eric-Arellano Dec 18, 2018
f8799c6
Default in CI to Py3, not Py2
Eric-Arellano Dec 18, 2018
b242609
Add script ./pants3 to use Python 3 under-the-hood
Eric-Arellano Dec 22, 2018
c6e2bc9
Revert "Default in CI to Py3, not Py2"
Eric-Arellano Dec 22, 2018
1644cd5
Revert "Set Py2 constraint for CI if not Py3"
Eric-Arellano Dec 22, 2018
a9b31cb
Update remaining references to pants_dev_deps.venv
Eric-Arellano Dec 22, 2018
4b46d18
Default to Py2.7 or Py3.6+ in python_setup.py
Eric-Arellano Dec 22, 2018
3d3e4b7
Review feedback
Eric-Arellano Dec 23, 2018
49418a0
Fix .travis.yml caching old venv folder
Eric-Arellano Dec 23, 2018
a591448
Delete `pants_dev_deps.venv` the first time new venv folder setup
Eric-Arellano Dec 23, 2018
37dab44
Restrict Python 3 to either 3.6 or 3.7
Eric-Arellano Dec 23, 2018
1134af5
Fix failing test_checkstyle.py by changing Py3 upper limit
Eric-Arellano Dec 23, 2018
f6e3816
Revert "Fix failing test_checkstyle.py by changing Py3 upper limit"
Eric-Arellano Dec 23, 2018
6ee312e
Allow Python 3.6+ to comply with Pants policy
Eric-Arellano Dec 23, 2018
8e0c149
Quotes around arg
Eric-Arellano Dec 23, 2018
6ede681
Merge branch 'master' of github.com:pantsbuild/pants into py3
Eric-Arellano Dec 23, 2018
911fc78
Remove bad trailing whitespace
Eric-Arellano Dec 23, 2018
54e10bf
Merge branch 'master' of github.com:pantsbuild/pants into py3
Eric-Arellano Jan 8, 2019
3940331
Rebuild native engine when interpreter changes
Eric-Arellano Jan 9, 2019
68ad660
Delete python_cache/interpreters first time changing to new venv fold…
Eric-Arellano Jan 9, 2019
5583d8c
Use Python 3 for subprocesses
Eric-Arellano Jan 9, 2019
647bd8b
Merge branch 'master' of github.com:pantsbuild/pants into py3
Eric-Arellano Jan 13, 2019
0f5e410
Update copyright for pants3 to 2019
Eric-Arellano Jan 13, 2019
4217dd4
Actually rebuild engine when changing interpreter
Eric-Arellano Jan 13, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion build-support/pants_venv
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions build-support/python/clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 4 additions & 3 deletions build-support/virtualenv
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 5 additions & 4 deletions pants.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions pants3
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion src/docs/export.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/docs/intellij.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/backend/python/subsystems/python_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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='<requirement>',
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)"
Expand Down