Hi all, I wonder if there is a way for Pants to ru...
# general
f
Hi all, I wonder if there is a way for Pants to run some commands like
./pants fmt ::
and
./pants test
for multiple Python versions? Something equivalent to Nox sessions.
h
Hi, yes, one way to do that is to parametrize the underlying targets on the
interpreter_constraints
But how feasible that is depends on how many targets you have
You can also do this with a macro
Note that while
./pants lint ::
makes sense, running
./pants fmt ::
multiple times on the same files with different interpreter constraints may get confusing, if the same formatter does different things to the same file when run on different interpreters
So is your question around running on different sets of files with different interpreters?
Or the same files multiple times?
f
Cool, that’s what I have been looking for. And to confirm, I can use
parameterize()
only in a high-level
tests
folder, or do I need to add it to every BUILD file in the folder?
Or the same files multiple times
This one. Same files, but diff Python versions.
h
No you'd need to add it to every
python_tests
where you want to run those tests with multiple interpreters
Which you can do with a macro if you want
but there is a simpler way
Everything I said above is for running the same tests on multiple interpreters in a single Pants run, concurrently
But if you're happy for each Pants run to use a single interpreter and you run Pants N times to run tests for N interpreters, then you should usually be able do that by changing the global interpreter constraints:
./pants --python-interpreter-constraints="['==3.8.*']" test ::
for example
e
Presumably @full-student-91825 wants to be able to do something like this:
Copy code
tox -p -epy{py{27,3{6,7,8,9}},27,3{5,6,7,8,9,10,11}}-integration
I can do that in the Pex project using tox to run tests against all supported interpreters in parallel. But its nice and ad-hoc. I can leave off some if I want. The definition for all those interpreters resides in 1 spot in my tox.ini.
☝️ 2
Ah - it looks like nox sessions are less ad-hoc. They bake the interprter set into pytest marks in the test source code.
Ah no, that's not pytest, its just python. Right, nox uses a plain old python file, tox uses ini. Ok, so ~same thing IIUC.
f
@enough-analyst-54434 yup, that’s right. Looks like we could use tox+pants instead of nox. Thanks!
e
I have not used nox, but my vague understading is its ~interchangeable with tox and grew from tox to make configuration easier / programmable.
h
So the equivalent of that is, roughly, parametrizing the targets, but that is not ideal in some cases
e
@happy-kitchen-89482 so say you went through the effort of parameterizing all your test targets for the ~10 interpreters you target. What is the equivalent pants command line to the tox example I gave? The docs you linked show how to select 1 parameter but not 10 permutations.
h
./pants test ::
will run all the permutations
e
What about just 5?
h
Yeah, that example sucks
You'd have to enumerate the parameterized targets
e
I don't want to run my PyPy interpreters, just my CPython.
Ok, yeah, that is no bueno.
h
Yeah we have no good solution for that
I have added it to my mental list of things to think about when we figure out what the "target" UX should be like, since right now it's bogged down by the legacy of Pants v1, which was bogged down by the legacy of Blaze, which was ...
👍 1
We'd want something like
./pants test ::@interpreter_constraints=py39
to work, but it doesn't
e
Yeah,
./pants test ::@interpreter_constraints={py39,py38}
Do me two.
h
I guess if you have one test target (possibly with overrides) then this works:
./pants test src/tests@interpreter_constraints=py38 src/tests@interpreter_constraints=py39
But in a 111 world it would be really laborious to do this for every target
e
Yeah, well, the 111 world is just plain laborious straight up.
h
Yep