I'm very confused about how pants finds the python...
# general
b
I'm very confused about how pants finds the python versions. It looks to me that the problem is that pants is latching on to the asdf global python version, and ignoring both the local version and the venv version. Is this expected. • I use asdf, set
search_path = ["<ASDF>"]
in pants.toml. I have python 3.11.6 and 3.12.0 installed with asdf, but set the version locally in the directory of the pants workspace to be 3.11.6. • In my pants workspace, I have a venv that uses 3.11.6, and I activated it. • But when I do a
pants run
it some how latches on to 3.12.0 and gave me the following error:
Copy code
09:49:00.10 [ERROR] 1 Exception encountered:

Engine traceback:
  in `run` goal

ProcessExecutionFailure: Process 'Find interpreter for constraints: CPython<=3.12,>=3.11' failed with exit code 102.
stdout:

stderr:
Could not find a compatible interpreter.

Interpreters were found but they all appear to be broken:
1.) /Users/joe/.asdf/installs/python/3.12.0/bin/python3.12:
Traceback (most recent call last):
  File "<string>", line 4, in <module>
  File "/Users/joe/.cache/pants/named_caches/pex_root/isolated/3754108aac57ec0c996f3414782585924aee601c/pex/atomic_directory.py", line 23, in <module>
    from pex.third_party import attr
ImportError: cannot import name 'attr' from 'pex.third_party' (/Users/joe/.cache/pants/named_caches/pex_root/isolated/3754108aac57ec0c996f3414782585924aee601c/pex/third_party/__init__.py)

(See <https://github.com/pantsbuild/pex/issues/1027> for a list of known breaks and workarounds.)
l
Joe, first, I don't expect that activating the venv before running pants should do all that much since pants has its own mechanisms to decide which python to run pants itself in and which python to run goals and such with. As for asdf, if you want to restrict to the version you have set in .tool-versions you probably need ASDF_LOCAL rather than ASDF for search path • <ASDF_LOCAL>, the ASDF interpreter with the version in <BUILD_ROOT>/.tool-versions.
That said, your error looks odd.
ah, so the error at least has been seen before: https://pantsbuild.slack.com/archives/C046T6T9U/p1697022915641629
If you can provide more details to reproduce the issue, like all relevant parts of the pants.toml. etc, and preferably reported as an issue, I will take a look, because it seems we keep hitting this.
b
My pants.toml looks like this:
Copy code
[GLOBAL]
pants_version = "2.17.0"
backend_packages = [
	"pants.backend.build_files.fmt.black",
	"pants.backend.python",
	"pants.backend.python.lint.autoflake",
	"pants.backend.python.lint.black",
	"pants.backend.python.lint.flake8",
	"pants.backend.python.lint.docformatter",
	"pants.backend.python.lint.isort",
	"pants.backend.python.typecheck.mypy",
]

[source]
root_patterns = ["/"]

[python]
interpreter_constraints = [">=3.11,<=3.12"]
enable_resolves = true
default_resolve = "reqs"

[python.resolves]
reqs = "3rdparty/python/python-default.lock"

[python-bootstrap]
search_path = ["<ASDF>"]

[python-infer]
string_imports = true
use_rust_parser = true

[pytest]
install_from_resolve = "reqs"

[mypy]
install_from_resolve = "reqs"
interpreter_constraints = [">=3.10,<=3.12"]
Report it as a bug?
And how do I describe what is "strange" about it in the bug title? I'd like to make it at least more informative than saying it's strange 🙂
b
The interpreter constraints there permit 3.12.0 as a compatible version due to the
<=
, do you maybe mean
<3.12
to restrict to only
3.11.x
versions?
b
That's part of it (I previously downgraded to 3.11.6 to workaround the pex problem). But I also missed the ASDF_LOCAL bit in the docs.