Skip to content

Commit 03d0c5f

Browse files
Revert unnecessary runtime check for valid Python interpreter (#7451)
### Problem Pants developers run Pants differently than end users do. Whereas they either download the wheel from PyPi or use a Pex, developers build from source. This allows us to run Pants with any Python version we'd like. Due to a misunderstanding thinking this meant end users could also run Pants with any Python interpreter they wanted, we added in #7365 a runtime check to ensure they use 2.7 or 3.6+. However, we realized it is impossible (or at least extremely unlikely) that end users will run Pants with an invalid interpreter, due to install time checks, as follows: * Pip will not resolve for invalid interpreters like 3.5, as it will not be able to find a valid wheel. * Pex includes interpreter constraints when being built, so the Pex cannot be ran with an invalid interpreter. Thus, the runtime check is unnecessary. ### Solution Remove the runtime check. ### Result Less code and slightly faster performance due to one less check.
1 parent 4a6fc72 commit 03d0c5f

File tree

3 files changed

+0
-76
lines changed

3 files changed

+0
-76
lines changed

src/python/pants/bin/pants_loader.py

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import importlib
88
import locale
99
import os
10-
import sys
1110
import warnings
1211
from builtins import object
1312
from textwrap import dedent
@@ -20,19 +19,10 @@ class PantsLoader(object):
2019
DEFAULT_ENTRYPOINT = 'pants.bin.pants_exe:main'
2120

2221
ENCODING_IGNORE_ENV_VAR = 'PANTS_IGNORE_UNRECOGNIZED_ENCODING'
23-
INTERPRETER_IGNORE_ENV_VAR = 'PANTS_IGNORE_UNSUPPORTED_PYTHON_INTERPRETER'
2422

2523
class InvalidLocaleError(Exception):
2624
"""Raised when a valid locale can't be found."""
2725

28-
class InvalidInterpreter(Exception):
29-
"""Raised when trying to run Pants with an unsupported Python version."""
30-
31-
@staticmethod
32-
def is_supported_interpreter(major_version, minor_version):
33-
return (major_version == 2 and minor_version == 7) \
34-
or (major_version == 3 and minor_version >= 6)
35-
3626
@staticmethod
3727
def setup_warnings():
3828
# We want to present warnings to the user, set this up before importing any of our own code,
@@ -72,27 +62,6 @@ def ensure_locale(cls):
7262
""".format(encoding, cls.ENCODING_IGNORE_ENV_VAR)
7363
))
7464

75-
@classmethod
76-
def ensure_valid_interpreter(cls):
77-
"""Runtime check that user is using a supported Python version."""
78-
py_major, py_minor = sys.version_info[0:2]
79-
if not PantsLoader.is_supported_interpreter(py_major, py_minor) and os.environ.get(cls.INTERPRETER_IGNORE_ENV_VAR, None) is None:
80-
raise cls.InvalidInterpreter(dedent("""
81-
You are trying to run Pants with Python {}.{}, which is unsupported.
82-
Pants requires a Python 2.7 or a Python 3.6+ interpreter to be
83-
discoverable on your PATH to run.
84-
85-
If you still get this error after ensuring at least one of these interpreters
86-
is discoverable on your PATH, you may need to modify your build script
87-
(e.g. `./pants`) to properly set up a virtual environment with the correct
88-
interpreter. We recommend following our setup guide and using our setup script
89-
as a starting point: https://www.pantsbuild.org/setup_repo.html.
90-
91-
Alternatively, you may bypass this error by setting the below environment variable.
92-
{}=1
93-
Note: we cannot guarantee consistent behavior with this bypass enabled.
94-
""".format(py_major, py_minor, cls.INTERPRETER_IGNORE_ENV_VAR)))
95-
9665
@staticmethod
9766
def determine_entrypoint(env_var, default):
9867
return os.environ.pop(env_var, default)
@@ -109,7 +78,6 @@ def load_and_execute(entrypoint):
10978
@classmethod
11079
def run(cls):
11180
cls.setup_warnings()
112-
cls.ensure_valid_interpreter()
11381
cls.ensure_locale()
11482
entrypoint = cls.determine_entrypoint(cls.ENTRYPOINT_ENV_VAR, cls.DEFAULT_ENTRYPOINT)
11583
cls.load_and_execute(entrypoint)

tests/python/pants_test/bin/BUILD

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
11
# Copyright 2015 Pants project contributors (see CONTRIBUTORS.md).
22
# Licensed under the Apache License, Version 2.0 (see LICENSE).
33

4-
python_tests(
5-
sources='test_loader.py',
6-
dependencies=[
7-
'src/python/pants/bin',
8-
'3rdparty/python:future',
9-
'3rdparty/python:mock',
10-
],
11-
)
124

135
python_tests(
14-
name='integration',
15-
sources='test_loader_integration.py',
166
dependencies=[
177
'src/python/pants/bin',
188
'tests/python/pants_test:int-test',

tests/python/pants_test/bin/test_loader.py

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)