-
Notifications
You must be signed in to change notification settings - Fork 30
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
Add support for Python 3 #30
Comments
For background, pantsbuild/pants#7151 is where we have previously used the |
And this sounds like a plan! |
FYI the proposal has changed from the original one of using a |
For the record, we could definitely turn: Lines 69 to 72 in 6dfccab
pants_version=$(
# use extended regexps, don't print every line
# when a `pants_version: ` line is found,
# replace all the text from the start of the line up to `: ` with an empty string, and print
sed -rne '/\s*pants_version: / s#^.*: ##p' pants.ini 2>/dev/null
# could add `| head -n1` if there might be multiple such lines
) which I personally find easier to read. |
### Problem As discussed in pantsbuild/setup#30, we decided to add support for using Python 3 to every day user's setup script `./pants` by having them pin the interpreter version they want to use in `pants.ini`, and then grepping that value to choose the relevant interpreter. However, this currently results in this error: ``` ERROR] Invalid option 'pants_runtime_python_version' under [GLOBAL] in /Users/eric/DocsLocal/code/projects/setup/pants.ini Exception caught: (<class 'pants.option.config.ConfigValidationError'>) Exception message: Invalid config entries detected. See log for details on which entries to update or remove. (Specify --no-verify-config to disable this check.) ``` ### Solution Exactly how we handle `--pants-version`, introduce a new global option `--pants-runtime-python-version` that allows users to set `pants_runtime_python_version` in their `pants.ini`. Even though Pants code cannot dynamically change the interpreter it runs with—as it is too late to change the interpreter once the process is already running—we can check that Pants is running with the intended interpreter and print a helpful message if it is not. You can leave off the option, and you'll get no runtime check. Setup scripts are free to implement Python interpreter resolution in another way if they prefer. ### Result * Including `pants_runtime_python_version` in `pants.ini` no longer results in an error. * Running `./pants --pants-runtime-python-version=2.6` will error out. Running `./pants2 --pants-runtime-python-version=2.7` will work normally.
### Problem Now that we're releasing Pants with Python 3 wheels (pantsbuild/pants#7197, overall migration tracked by pantsbuild/pants#6062), we need to add a way for every day Pants users to consume the upgrade. See #30 for more context, including the design goals. ### Solution Parse the `pants_runtime_python_version` from `pants.ini` to determine which Python interpreter to use. If it's missing, default to Python 2.7. This requires modifying the venv folders to support multiple Python versions. Rather than using the naming scheme `${pants_version}`, we now consistently use `${pants_version}_py{py_major_minor}`, regardless of if the user is using `pants_runtime_python_version`. It also requires upgrading virtualenv to avoid a deprecation warning when running with Python 3. Finally, we add tests to ensure this all works. ### Result Running `./pants` like normal for the first time will bootstrap Pants again and create the new folder `1.15.dev3_py{27,36,37}`. Changing the `$PYTHON` env var or the `pants_runtime_python_version` in `pants.ini` will change which Python version is used to run Pants. When changing interpreters for the first time, it will bootstrap Pants again. After that, you can change without issue.
This was closed by #32. |
With Pants soon to be released with Python 3 wheels pantsbuild/pants#7197 and the Python 3 migration nearing completion pantsbuild/pants#6062, we need to modify this setup script to allow Pants end users to consume the upgrade.
Goals for an ideal solution
.bashrc
with their individual preference. It should be an organization-level decision set for the whole repo.rm -rf
their cache../pants2
and./pants
. We are not expecting the average Pants user to worry about which Python interpreter they use to run Pants as both should work equally as well and it is more cognitive load than necessary.Proposed solution
Users should add
pants_runtime_python_version: {2.7,3.6,3.7}
to theirpants.ini
[GLOBAL]
entry, just as they setpants_version
.We would update the website at https://www.pantsbuild.org/install.html to provide instructions, along the lines of:
Tasks
pants.ini
. Use this to set$PYTHON
and determinebootstrap_venv
.The text was updated successfully, but these errors were encountered: