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

Add pants_runtime_python_version global option #7363

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 16 additions & 1 deletion src/python/pants/init/options_initializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import logging
import sys
from builtins import object
from builtins import map, object

import pkg_resources

Expand Down Expand Up @@ -108,6 +108,21 @@ def create(cls, options_bootstrapper, build_configuration, init_subsystems=True)
.format(global_bootstrap_options.pants_version, pants_version())
)

pants_runtime_python_version = global_bootstrap_options.pants_runtime_python_version
current_python_version = '.'.join(map(str, sys.version_info[0:2]))
if pants_runtime_python_version and pants_runtime_python_version != current_python_version:
raise BuildConfigurationError(
'Running Pants with a different Python interpreter version than requested. '
'You requested {}, but are running with {}.\n\n'
'Note that Pants cannot use the value you give for `--pants-engine-python-version` to '
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is using the previous option name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oof. I thought I had fixed all the instances of this. Will hotfix this as part of #7365. Thanks for the catch!

'dynamically change the interpreter it uses, as it is too late for it to change once the program '
'is already running. Instead, your setup script (e.g. `./pants`) must configure which Python '
'interpreter and virtualenv to use. For example, the setup script we distribute '
'at https://www.pantsbuild.org/install.html#recommended-installation will read the '
'`pants_runtime_python_version` defined in your pants.ini to determine which Python '
'version to run with.'.format(pants_runtime_python_version, current_python_version)
)

# Parse and register options.
options = cls._construct_options(options_bootstrapper, build_configuration)

Expand Down
27 changes: 22 additions & 5 deletions src/python/pants/option/global_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,29 @@ def register_bootstrap_options(cls, register):
register('--colors', type=bool, default=sys.stdout.isatty(), recursive=True, daemon=False,
help='Set whether log messages are displayed in color.')

# Pants code uses this only to verify that we are of the requested version. However
# setup scripts, runner scripts, IDE plugins, etc., may grep this out of pants.ini
# and use it to select the right version.
# Note that to print the version of the pants instance you're running, use -v, -V or --version.
register('--pants-version', advanced=True, default=pants_version(),
help='Use this pants version.')
help='Use this pants version. Note Pants code only uses this to verify that you are '
'using the requested version, as Pants cannot dynamically change the version it '
'is using once the program is already running. This option is useful to set in '
'your pants.ini, however, and then you can grep the value to select which '
'version to use for setup scripts (e.g. `./pants`), runner scripts, IDE plugins, '
'etc. For example, the setup script we distribute at https://www.pantsbuild.org/install.html#recommended-installation '
'uses this value to determine which Python version to run with. You may find the '
'version of the pants instance you are running using -v, -V, or --version.')

register('--pants-runtime-python-version', advanced=True,
help='Use this Python version to run Pants. The option expects the major and minor '
'version, e.g. 2.7 or 3.6. Note Pants code only uses this to verify that you are '
'using the requested interpreter, as Pants cannot dynamically change the '
'interpreter it is using once the program is already running. This option is '
'useful to set in your pants.ini, however, and then you can grep the value to '
'select which interpreter to use for setup scripts (e.g. `./pants`), runner '
'scripts, IDE plugins, etc. For example, the setup script we distribute at '
'https://www.pantsbuild.org/install.html#recommended-installation uses this '
'value to determine which Python version to run with. Also note this does not mean '
'your own code must use this Python version. See '
'https://www.pantsbuild.org/python_readme.html#configure-the-python-version '
'for how to configure your code\'s compatibility.')

register('--plugins', advanced=True, type=list, help='Load these plugins.')
register('--plugin-cache-dir', advanced=True,
Expand Down