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

Remove deprecated default ICs. #18627

Merged
merged 12 commits into from
Apr 10, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
46 changes: 25 additions & 21 deletions src/python/pants/backend/python/subsystems/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand All @@ -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",)
Comment on lines +86 to +91
Copy link
Member

Choose a reason for hiding this comment

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

Maybe you could include another (longer) deprecation here, to commit us to doing that on some timeframe? Maybe 4 releases or something.

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.
"""
),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down
7 changes: 7 additions & 0 deletions src/python/pants/testutil/pants_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,<3.10']")

pants_script = [sys.executable, "-m", "pants"]

# Permit usage of shell=True and string-based commands to allow e.g. `./pants | head`.
Expand Down