different resolves & interpreter constraints a...
# general
a
different resolves & interpreter constraints are doing my noggin in. previously, both my (embedded) runtime and pants were running python3.9, which was convenient. But now my runtime has upgraded to 3.10, and pants 3.11. which made having in-repo plugins a bit ... painful. I ended up with a macro
pants_plugin_sources
that sets the resolve & interpreter constraints to the right one for pants. and a
runtime_sources
that sets the resolve & interpreter for my runtime. everything seems to work. Until you add a
match/case
statement, and then it's a bit ... weird. i.e. today
black
failed with "Invalid syntax <unknown>, line <match statement>... blablabla older Python version." when doing
fmt ::
Then doing
pants fmt a/b/c/file.py
on that same file worked fine. and then subsequent calls to
fmt ::
work fine. It's like, pants is picking an old 3.9 version of Python to use sometimes. Despite not having 3.9 as a resolve or interpreter any more
c
p
I use
__defaults__
to set pants-plugins to a different interpreter constraint than the rest of the repo. I keep the pants-plugins code isolated from the rest of the code in the repo - so the pants-plugins code does not import the rest of the app code. It can run specific targets (say a script) that is in the default resolve, but it does not import that script. You can see that here: https://github.com/StackStorm/st2/blob/master/pants-plugins/BUILD And these two blocks are how I run a script from the other resolve within one of the pants plugins: • https://github.com/StackStorm/st2/blob/master/pants-plugins/sample_conf/subsystem.py#L37-L43https://github.com/StackStorm/st2/blob/master/pants-plugins/sample_conf/rules.py#L61-L72
Also, here's my def of the interpreter_constraints for internal code (st2 resolve), pants-plugins code, and for tools like black: • https://github.com/StackStorm/st2/blob/master/pants.toml#L110-L149 Note: I don't use the pants-provided lock for tools like black. For tool interpreter constraints, I expand the interpreter_constraints so it is a superset of all the other interpreter constraints. This is where I populate the
black
resolve with deps: https://github.com/StackStorm/st2/blob/master/BUILD.tools#L28-L35
Does that help at all? Admittedly, that repo has a somewhat complex set of BUILD metadata.
a
this might, yes
examples definitely help
cheers
aha. I think I've narrowed the problem... maybe? set up a new resolve for black with the right interpreter-constraints.
pants fmt ::
fails with
dependency on black not satisfied, 1 incompatible candidate found... requires python>=3.9
, as it can't install black, because something (pants?) is falling back to using the system python3.8 interpreter when installing things
pants fmt path/to/file.py
still works fine.
ah! ding! found it.
[black].interpreter_constraints
will silently ignore the resolve interpreter constraints if they're incompatible.