Howdie, folks! Hope you're all having a great Mon...
# general
b
Howdie, folks! Hope you're all having a great Monday 🙂 I'm running into an error after upgrading my
pants
configuration from python
3.10.*
to
3.12.*
. Essentially, when I run either the
fmt
or the
lint
goals,
pip==23.0.1
is used, which doesn't work with the new interpreter version (
3.12.*
), causing an error to bubble up.
Copy code
$ pants --print-stacktrace --no-pantsd --no-local-cache fmt ::

16:59:06.94 [INFO] Completed: Building docformatter.pex from <resource://pants.backend.python.lint.docformatter/docformatter.lock>
16:59:06.95 [ERROR] 1 Exception encountered:

Engine traceback:
  in select
    ..
  in pants.core.goals.fmt.fmt
    `fmt` goal

Traceback (most recent call last):
  File "/Users/erickrocha/Library/Caches/nce/0bb9722222f003de9629623179038ecab5b6bd747796b95272e1d271dba00578/bindings/venvs/2.19.0/lib/python3.9/site-packages/pants/core/goals/fmt.py", line 77, in fmt
    return await _do_fix(
  File "/Users/erickrocha/Library/Caches/nce/0bb9722222f003de9629623179038ecab5b6bd747796b95272e1d271dba00578/bindings/venvs/2.19.0/lib/python3.9/site-packages/pants/core/goals/fix.py", line 322, in _do_fix
    all_results = await MultiGet(
  File "/Users/erickrocha/Library/Caches/nce/0bb9722222f003de9629623179038ecab5b6bd747796b95272e1d271dba00578/bindings/venvs/2.19.0/lib/python3.9/site-packages/pants/engine/internals/selectors.py", line 374, in MultiGet
    return await _MultiGet(tuple(__arg0))
  File "/Users/erickrocha/Library/Caches/nce/0bb9722222f003de9629623179038ecab5b6bd747796b95272e1d271dba00578/bindings/venvs/2.19.0/lib/python3.9/site-packages/pants/engine/internals/selectors.py", line 172, in __await__
    result = yield self.gets
pants.engine.process.ProcessExecutionFailure: Process 'Building docformatter.pex from <resource://pants.backend.python.lint.docformatter/docformatter.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.2 at /Users/erickrocha/.pyenv/versions/3.12.2/bin/python3.12. Pip 23.0.1 requires Python <3.12,>=3.7.



Use `--keep-sandboxes=on_failure` to preserve the process chroot for inspection.
What I think is the relevant portion of my
lock-file
looks like this:
Copy code
"path_mappings": {},
  "pex_version": "2.1.148",
  "pip_version": "23.2",
  "prefer_older_binary": false,
  "requirements": [
    "PyJWT==2.8.0",
    "SQLAlchemy==2.0.27",
    "alembic==1.13.1",
    "fastapi==0.109.2",
    "psycopg2-binary==2.9.9",
    "psycopg2==2.9.9",
    "pydantic-settings==2.2.1",
    "pydantic==2.6.1",
    "uvicorn==0.27.1",
    "workos==2.2.0"
  ],
  "requires_python": [
    "==3.12.*"
  ],
  "resolver_version": "pip-2020-resolver",
  "style": "universal",
  "target_systems": [
    "linux",
    "mac"
  ],
  "transitive": true,
  "use_pep517": null
Note that the
pip
version is set to
23.2
, which leads me to believe that the
fmt
goal is either caching this information somewhere or that it doesn't retrieve that information from there at all. I attempted to execute the command without cache and without the daemon as per the docs, but alas, to no avail. It's worth mentioning that I'm able to execute the
run
goal without any issues. Last, but not least, I'm fairly new to
pants
and there's a lot to learn still, so apologies if I missed something obvious in the docs; I spent some time searching but didn't come across anything that helped me out.
b
I think that’s related to this issue: https://github.com/pantsbuild/pants/issues/20354
h
Which Pants version is this? Try using this option to bump the pip version that Pants (via Pex) uses
Depending on the Pants version you may first need to upgrade Pex to a version that supports the Pip you need
See the pex-cli subsystem docs for how to do that
b
Benjy, I believe the built-in lockfiles need to be updated to use reference newer pips for that to work. https://github.com/pantsbuild/pants/pull/20365 is my attempt at solving 20354 but has been sitting around blocked (https://github.com/pantsbuild/pants/pull/20365#issuecomment-1965530466).
Erick, sorry for the trouble. I think a workaround is to install docformatter and other tools from a custom resolve: https://www.pantsbuild.org/2.18/docs/python/overview/lockfiles#lockfiles-for-tools Doing this lets you generate your own lockfiles which reference the pip you've selected, rather than using Pants' default lockfiles for the tool, which reference a different pip version.
b
Hi guys, thank you very much for your replies! I was OOO today, so couldn't tinker with your suggestions, but I'll find some time to do that tomorrow and let you know! Thank you again 🙏
s
Hi guys. I'm having the same issue trying to use ruff with python 3.12:
Copy code
ProcessExecutionFailure: Process 'Building ruff.pex from <resource://pants.backend.python.lint.ruff/ruff.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.2 at /Users/jperez/.pyenv/versions/3.12.2/bin/python3.12. Pip 23.0.1 requires Python <3.12,>=3.7.
c
@swift-dawn-80732 I think per the above workaround, you will need to create your own resolve for ruff +3.12 instead of relying on
<resource://pants.backend.python.lint.ruff/ruff.lock>'
(most/all? Pants lockfiles need to be updated)
s
thank you, but I don't understand how that works
c
s
yes, tried to emulate it, but getting this error:
Copy code
$ pants --print-stacktrace generate-lockfiles --resolve=ruff -ldebug
17:54:39.32 [ERROR] Invalid section [ruff] in /Users/jperez/demoda/repos/backend/pants.toml
17:54:39.32 [ERROR] Invalid config entries detected. See log for details on which entries to update or remove.

(Specify --no-verify-config to disable this check.)


Use --print-stacktrace for more error details and/or -ldebug for more logs. 
See <https://www.pantsbuild.org/v2.19/docs/troubleshooting> for common issues.
Consider reaching out for help: <https://www.pantsbuild.org/v2.19/docs/getting-help>
not sure which entries are invalid.. adding
--print-stacktrace
and
-ldebug
made no difference
pants.toml looks like this:
Copy code
[python.resolves]
ruff = "3rdparty/python/ruff.lock"

[ruff]
install_from_resolve = "ruff"
requirements =["//3rdparty/python:ruff"]
c
17:54:39.32 [ERROR] Invalid section [ruff] in /Users/jperez/demoda/repos/backend/pants.toml
hmm, do you have
pants.backend.experimental.python.lint.ruff
enabled?
s
ohh, I was missing that, sorry
now it didn't fail, but it also didn't generate the lock file
ruff-requirements.txt has this:
Copy code
ruff==0.2.2
and 3rdparty/python/BUILD this:
Copy code
python_requirements(
    name="ruff",
    source="ruff-requirements.txt",
    resolve="ruff",
)
c
pants generate-lockfiles --resolve=my-new-one
is an explicit user step, there isn't an implicit lockfile generate on first use (FWIW I suspect the most common way to use tool resolves when not working around this issue is to roll everything into One Big Lockfile)
s
I did run generate-lockfiles manually, but nothing happened
c
I need to sign off soon and this may be exceeding chat style debugabilty. if you can post the example pants.toml and requirements in a snippet/pastbin I can probably take a look tomorrow.
s
thanks you for your time! I'll do that
@curved-manchester-66006 thanks for your help yesterday! this PR just got approved: https://github.com/pantsbuild/pants/pull/20365 it solves all these issues
1