Another question with pants plugins development — ...
# general
r
Another question with pants plugins development — I'm using Python 3.12 for our codebase while Pants itself uses Python 3.9, so I've separated the resolves with different interpreter constraints following https://www.pantsbuild.org/stable/docs/writing-plugins/overview#building-in-repo-plugins-with-pants. The issue is that when I run
mypy
(
pants check ::
to include both the main codebase and the pants-plugins) against the pants-plugins target, it breaks up with:
Copy code
Dependency on tomli (via: mypy==1.14.1 -> tomli>=1.1.0; python_version < "3.11") not satisfied, no candidates found.
Pants seems to try make an isolated pex environment for Python 3.9 (pants-plugins) with the
mypy
resolve locks generated for Python 3.12 (main codebase). How could I resolve this issue? For instance, could I have two lock files for a single resolve targetting different Python interpreter versions?
Previously I've set the pants-plugin resolves in a wrong way, so it didn't have any required dependencies. I'm trying to fix it now. 🥹
I just added
tomli
to the mypy's own requirements and lock (regardless of the target Python version), and also added explicit
interpreter_constraints = ["==3.9.*", "==3.12.*"]
to pants.toml's
[mypy]
section. It no longer says the above error, but just hangs while creating a mypy pex environment:
hmmmm... The partitions look correctly configured, but the second partition says it's not in Python 3.12.
The original question seems to be resolved by introducing: •
[resolves_to_interpreter_constraints]
mypy = ["==3.9.*", "==3.12.*"]
(making the lockfile to have both 3.9/3.12 dependencies) •
[mypy]
interpreter_constraints = ["==3.9.*", "==3.12.*"]
(allows having two different interpreters)
Now the remaining issue is the wrong target Python version recognized by running mypy for the Python 3.12.8 partition.
Hm.. another problem:
pants export --resolve=mypy
only creates the venv for Python 3.9.... T_T
I think it should create for both partitions
ah....... removing
[mypy] interpreter_constraints = ...
but keeping
[resolves_to_interpreter_constraints]  mypy = ...
resolves the Python version issue when checking the main codebase partition. ;;;
but still
pants export --resolve=mypy
only creates venv for 3.9... (the interim progress message says that it's running for
==3.9.* OR == 3.12.*
)
hmmm
This looks like the same that I want to achieve..
image.png
but I get this..
r
I don’t think this is quite the same issue, but do you have
[mypy].install_from_resolve = “mypy”
and
[mypy].requirements = [“tomli”]
?
Also, note that plug-ins are kind of special. Even if you have a resolve set for your plug-ins, that resolve is only used when testing those plug-ins. When using plug-ins, they will run in the python you’re using to bootstrap, which sounds like is 3.9