diff --git a/src/python/pants/backend/python/subsystems/setup.py b/src/python/pants/backend/python/subsystems/setup.py index 3754807cfb6..cc3cf502f86 100644 --- a/src/python/pants/backend/python/subsystems/setup.py +++ b/src/python/pants/backend/python/subsystems/setup.py @@ -10,8 +10,8 @@ from packaging.utils import canonicalize_name -from pants.base.deprecated import warn_or_error from pants.core.goals.generate_lockfiles import UnrecognizedResolveNamesError +from pants.option.errors import OptionsError from pants.option.option_types import ( BoolOption, DictOption, @@ -60,11 +60,10 @@ class PythonSetup(Subsystem): options_scope = "python" help = "Options for Pants's Python backend." - default_interpreter_constraints = ["CPython>=3.7,<4"] default_interpreter_universe = ["2.7", "3.5", "3.6", "3.7", "3.8", "3.9", "3.10", "3.11"] _interpreter_constraints = StrListOption( - default=default_interpreter_constraints, + default=None, help=softwrap( """ The Python interpreters your codebase is compatible with. @@ -83,26 +82,31 @@ class PythonSetup(Subsystem): @memoized_property def interpreter_constraints(self) -> tuple[str, ...]: - # TODO: In 2.17.0.dev3 we should set the default above to None and tweak the message here - # appropriately. - if self.options.is_default("interpreter_constraints"): - warn_or_error( - "2.17.0.dev3", - "the factory default interpreter constraints value", + if not self._interpreter_constraints: + # TODO: This is a hacky affordance for Pants's own tests, dozens of which were + # written when Pants provided default ICs, and implicitly rely on that assumption. + # We'll probably want to find and modify all those tests to set an explicit IC, but + # that will take time. + if "PYTEST_CURRENT_TEST" in os.environ: + return (">=3.7,<4",) + raise OptionsError( softwrap( f"""\ - You're relying on the default interpreter constraints that ship with Pants - ({self._interpreter_constraints}). This default is deprecated, in favor of - explicitly specifying the interpreter versions your code is actually intended to - run against. - - You specify interpreter constraints using the `interpreter_constraints` option in - the `[python]` section of pants.toml. We recommend constraining to a single interpreter - minor version if you can, e.g., `interpreter_constraints = ['==3.11.*']`, or at - least a small number of interpreter minor versions, e.g., `interpreter_constraints - = ['>=3.10,<3.12']`. See {doc_url("python-interpreter-compatibility")} for details. - - Set explicit interpreter constraints now to get rid of this warning. + You must explicitly specify the default Python interpreter versions your code + is intended to run against. + + You specify these interpreter constraints using the `interpreter_constraints` + option in the `[python]` section of pants.toml. + + We recommend constraining to a single interpreter minor version if you can, + e.g., `interpreter_constraints = ['==3.11.*']`, or at least a small number of + interpreter minor versions, e.g., `interpreter_constraints = ['>=3.10,<3.12']`. + + Individual targets can override these default interpreter constraints, + if different parts of your codebase run against different python interpreter + versions in a single repo. + + See {doc_url("python-interpreter-compatibility")} for details. """ ), ) diff --git a/src/python/pants/backend/python/util_rules/interpreter_constraints_test.py b/src/python/pants/backend/python/util_rules/interpreter_constraints_test.py index 204e9d0341a..6be2638a187 100644 --- a/src/python/pants/backend/python/util_rules/interpreter_constraints_test.py +++ b/src/python/pants/backend/python/util_rules/interpreter_constraints_test.py @@ -296,15 +296,11 @@ def test_group_field_sets_by_constraints() -> None: MockFieldSet.create_for_test(Address("", target_name="py3"), "==3.6.*"), MockFieldSet.create_for_test(Address("", target_name="py3_second"), "==3.6.*"), ] - no_constraints_fs = MockFieldSet.create_for_test( - Address("", target_name="no_constraints"), None - ) assert InterpreterConstraints.group_field_sets_by_constraints( - [py2_fs, *py3_fs, no_constraints_fs], + [py2_fs, *py3_fs], python_setup=create_subsystem(PythonSetup, interpreter_constraints=[]), ) == FrozenDict( { - InterpreterConstraints(): (no_constraints_fs,), InterpreterConstraints(["CPython>=2.7,<3"]): (py2_fs,), InterpreterConstraints(["CPython==3.6.*"]): tuple(py3_fs), } diff --git a/src/python/pants/engine/BUILD b/src/python/pants/engine/BUILD index 802bc9fe7be..fd4c546cfe8 100644 --- a/src/python/pants/engine/BUILD +++ b/src/python/pants/engine/BUILD @@ -17,5 +17,5 @@ python_tests( # Loaded reflectively as a backend in `streaming_workunit_handler_integration_test.py`. "testprojects/pants-plugins/src/python/workunit_logger" ], - timeout=120, + timeout=240, ) diff --git a/src/python/pants/engine/streaming_workunit_handler_integration_test.py b/src/python/pants/engine/streaming_workunit_handler_integration_test.py index e24e823fae4..b6b9a423c99 100644 --- a/src/python/pants/engine/streaming_workunit_handler_integration_test.py +++ b/src/python/pants/engine/streaming_workunit_handler_integration_test.py @@ -27,6 +27,7 @@ def workunit_logger_config(log_dest: str, *, pantsd: bool = True) -> Mapping: "backend_packages.add": ["workunit_logger", "pants.backend.python"], }, "workunit-logger": {"dest": log_dest}, + "python": {"interpreter_constraints": "['>=3.7,<3.10']"}, } diff --git a/src/python/pants/testutil/pants_integration_test.py b/src/python/pants/testutil/pants_integration_test.py index a13f8b51f43..9b75b7b990b 100644 --- a/src/python/pants/testutil/pants_integration_test.py +++ b/src/python/pants/testutil/pants_integration_test.py @@ -117,6 +117,13 @@ def run_pants_with_workdir_without_waiting( fp.write(TomlSerializer(config).serialize()) args.append(f"--pants-config-files={toml_file_name}") + # The python backend requires setting ICs explicitly. + # We do this centrally here for convenience. + if any("pants.backend.python" in arg for arg in command) and not any( + "--python-interpreter-constraints" in arg for arg in command + ): + args.append("--python-interpreter-constraints=['>=3.7,<4']") + pants_script = [sys.executable, "-m", "pants"] # Permit usage of shell=True and string-based commands to allow e.g. `./pants | head`. diff --git a/tests/python/pants_test/pantsd/pantsd_integration_test_base.py b/tests/python/pants_test/pantsd/pantsd_integration_test_base.py index aed6a7be8c1..b3026fd5c68 100644 --- a/tests/python/pants_test/pantsd/pantsd_integration_test_base.py +++ b/tests/python/pants_test/pantsd/pantsd_integration_test_base.py @@ -182,7 +182,10 @@ def pantsd_test_context( "pants.backend.python", "pants.backend.python.lint.flake8", ], - } + }, + "python": { + "interpreter_constraints": "['>=3.7,<3.10']", + }, } if extra_config: