Does anyone know what the mechanism is to default ...
# development
w
Does anyone know what the mechanism is to default to having tests run on a specific Python version? Pylint's default_interpreter_constraints start at 3.10 - but, I have 3.9 installed on my machine, and for some reason, that keeps getting used to run my tests by default I don't want to decorate every function, so should I override at the BUILD level? I have explicitly backported tests to run too, for 3.8/3.9
p
If tests don't specify their constraints, like I do here: https://github.com/pantsbuild/pants/pull/22873/files#diff-bb2cf38bcbdadbc043547eff384ecdefda3a8624ba6c6b77032c64a2a191aad4R56-R61 Then, they're subject to the default interpreter_constraints here: https://github.com/pantsbuild/pants/blob/main/src/python/pants/testutil/python_rule_runner.py#L19-L25 And then pex picks the oldest compatible version within the interpreter-constraints range it receives from the given search paths. (iirc)
At least, that's how it works for
RuleRunner
(actually for
PythonRuleRunner
). The
run_pants
style integration tests probably have to include the interpreter constraints in a
pants.toml
file, or cli flag, or env var.
Also, if pex does pick a python that is too old initially, and then finds that it is not compatible with the requested interpreter constraints, it should reexec with an appropriate python version.
w
Okay, so, the most reasonable approach seems to be to default a python version, and then override it as necessary. That’s what I was doing, but it didn’t really feel right - given that I’m sending in the pylint interpreter constraints. Thought that would be enough to ensure we used AT LEAST that one in the rule runner
p
The tests can also modify the python search paths. For my personal use, I added these alias flags to force using a particular python version, so tests could do something similar:
Copy code
$ cat ~/.pants.rc 
[cli.alias]
--py36 = "--python-bootstrap-search-path=[] --python-bootstrap-search-path=/home/cognifloyd/.pyenv/versions/3.6.15/bin/python3.6"
--py37 = "--python-bootstrap-search-path=[] --python-bootstrap-search-path=/home/cognifloyd/.pyenv/versions/3.7.17/bin/python3.7"
--py38 = "--python-bootstrap-search-path=[] --python-bootstrap-search-path=/home/cognifloyd/.pyenv/versions/3.8.18/bin/python3.8"
--py39 = "--python-bootstrap-search-path=[] --python-bootstrap-search-path=/home/cognifloyd/.pyenv/versions/3.9.18/bin/python3.9"
--py310 = "--python-bootstrap-search-path=[] --python-bootstrap-search-path=/usr/bin/python3.10"
--py311 = "--python-bootstrap-search-path=[] --python-bootstrap-search-path=/home/cognifloyd/.pyenv/versions/3.11.8/bin/python3.11"
w
Yeah, this is for ci too - latest pylint drops 3.9
But i dont want to change our defaults yet, to avoid too much churn at once
p
oh fun. That's probably wise.
w
Even just the pyupgrade will touch every file, so I’m deferring that too
🤷 1
1