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

Most built-in tool lockfiles do not work with Python 3.12 #20354

Closed
huonw opened this issue Dec 31, 2023 · 1 comment · Fixed by #20365
Closed

Most built-in tool lockfiles do not work with Python 3.12 #20354

huonw opened this issue Dec 31, 2023 · 1 comment · Fixed by #20365
Labels
backend: Python Python backend-related issues bug
Milestone

Comments

@huonw
Copy link
Contributor

huonw commented Dec 31, 2023

Describe the bug

The built-in lockfiles for tools like: pytest, mypy, ..., use pip 23.0.1, which doesn't work with Python 3.12:

13:28:11.08 [INFO] Completed: Building pytest.pex from resource://pants.backend.python.subsystems/pytest.lock
13:28:11.09 [ERROR] 1 Exception encountered:

Engine traceback:
  in `test` goal

ProcessExecutionFailure: Process 'Building pytest.pex from resource://pants.backend.python.subsystems/pytest.lock' failed with exit code 1.
stdout:

stderr:
The Pip requested was pip==23.0.1 but it does not work with the interpreter selected which is CPython 3.12.0 at /Users/huon/.pyenv/versions/3.12.0/bin/python3.12. Pip 23.0.1 requires Python <3.12,>=3.7.

Reproducer:

cd $(mktemp -d)

cat > pants.toml <<EOF
[GLOBAL]
pants_version = "2.19.0rc2"

backend_packages = [
  "pants.backend.python",
]

[python]
interpreter_constraints = ["==3.12.*"]
EOF

echo 'python_tests(name="t")' > BUILD
echo 'def test_foo(): pass' > test_example.py

# BUG: fails by default with Python 3.12
pants test ::
#> The Pip requested was pip==23.0.1 but it does not work with the interpreter selected which is CPython 3.12.0 at /Users/huon/.pyenv/versions/3.12.0/bin/python3.12. Pip 23.0.1 requires Python <3.12,>=3.7.

# OKAY: works fine
pants test --python-interpreter-constraints='["==3.11.*"]' ::

Workaround: use custom lockfiles, with python_requirements/install_from_resolve.

Pants version

2.19.0rc2

(NB. 2.18.1 uses a version of pex that doesn't support Python 3.12 by default, but would likely be still affected by this if one specifies a newer pex in [pex-cli].)

OS

macOS

Additional info
Discussed in #20310 (review)

Details of pip version support in https://github.com/pantsbuild/pex/blob/4eb5c9aa25c6a695bf55263ab239189b720cebaf/pex/pip/version.py#L128-L233

See https://github.com/search?q=repo%3Apantsbuild%2Fpants%20pip_version%2023.0.1&type=code for 27 current lock files using pip version 23.0.1.

@huonw huonw added bug backend: Python Python backend-related issues labels Dec 31, 2023
@huonw huonw added this to the 2.18.x milestone Dec 31, 2023
@huonw
Copy link
Contributor Author

huonw commented Dec 31, 2023

The lockfiles are mostly using 23.0.1, and that has a version range of >=3.7,<3.12: https://github.com/pantsbuild/pex/blob/4eb5c9aa25c6a695bf55263ab239189b720cebaf/pex/pip/version.py#L182-L187

Thus, I imagine it's not a problem to regenerate to a newer versions that just increase this range, while still supporting 3.7: https://github.com/pantsbuild/pex/blob/4eb5c9aa25c6a695bf55263ab239189b720cebaf/pex/pip/version.py#L210-L233

That said, pip suggests that pants' default pip version (23.1.2) doesn't work with python 3.12 (this seems potentially incorrect? pex-tool/pex#2314), so we might need to leap to an even newer pip and/or bump the default pip version too.

huonw added a commit that referenced this issue Feb 29, 2024
…ip_version = 24.0, for Py 3.12 support (#20365)

This does three things to fix #20354 and give Pants Python 3.12 support
by default:

- update the default `[python].pip_version` value to `24.0` (from
`23.1.2`), which is the current latest and is after 23.2, which is the
first that supports Python 3.12
- run `pants run build-support/bin/generate_builtin_lockfiles.py --
--all-python` to update all tool lockfiles... this involves updating
many tools, as a Big Bang, which is potentially unhelpful.
- to make this work, `docformatter` has to be restricted to the current
version 1.4: 1.5.1 (the newest version that satisfies the old
constraints) crashes on Pants itself
(PyCQA/docformatter#151), while 1.7.5 (the
newest version) also doesn't work on Pants (#20498)

Here's a list of (as best I can tell), the changes in versions for the
"main" requirement for each subsystem:

| subsystem options scope | main requirement | old version | new version |
|-------------------------|------------------|-------------|-------------|
| `helm-k8s-parser`       | `hikaru`         | 0.11.0b0    | 0.16.0b0    |
| `helm-post-renderer`    | `yamlpath`       | 3.7.0       | 3.8.1       |
| `autoflake`             | `autoflake`      | 2.0.1       | 2.1.1       |
| `bandit`                | `bandit`         | 1.7.4       | 1.7.5       |
| `black`                 | `black`          | 23.1.0      | 23.3.0      |
| `pyupgrade`             | `pyupgrade`      | 3.3.1       | 3.3.2       |
| `ruff`                  | `ruff`           | 0.2.1       | 0.2.2       |
| `yapf`                  | `yapf`           | 0.32.0      | 0.40.2      |
| `coverage-py`           | `coverage`       | 7.2.1       | 7.2.7       |
| `debugpy`               | `debugpy`        | 1.6.6       | 1.6.7.post1 |
| `mypy`                  | `mypy`           | 1.1.1       | 1.4.1       |
| `terraform-hcl2-parser` | `python-hcl2`    | 4.3.0       | 4.3.2       |
| `yamllint`              | `yamllint`       | 1.29.0      | 1.32.0      |

There's numerous other transitive dependencies updated too, including in
subsystems for which the main requirement hasn't changed and aren't
listed above.

I haven't checked changelogs for any of these.

I've confirmed that running the reproducer from #20354 with this code
now works. The commits are 'sensible'.
huonw added a commit that referenced this issue Apr 27, 2024
This adds Python 3.13 to the default interpreter universe, so that we're
more ready to hit the ground running when it is eventually released.

https://peps.python.org/pep-0719/ suggests the plan is 3.13.0 stable
release on 2024-10-01. This PR will flow into Pants 2.22.0. We won't be
releasing 2.22.0 before 2024-07-09 (12 weeks after 2.20.0, on
2024-04-16), so there's a bit of slack even if 2.21 and 2.22 take longer
than 6 weeks to get out the door.

It looks like we won't be perfectly ready, because there's a similar
lockfile issue to #20354 for Python 3.12: our lockfiles use pip 24.0
which apparently doesn't support Python 3.13 (needs
pypa/pip#12462). Thus, we'll need to regenerate
our lockfiles once there's a pex release with a pip release with
pypa/pip#12462. I've filed
#20852 to track this.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend: Python Python backend-related issues bug
Projects
None yet
1 participant