fresh-cat-90827
06/30/2021, 9:10 PMtox before using Pants. Pants doesn’t mention tox in the docs and I didn’t find any related issues on GitHub. The interpreter_constraints option (docs) will resolve to a single Python interpreter version (so interpreter_constraints = ["CPython==3.6.9", "CPython==3.8.5"] wouldn’t make sense).
My use case is as follows. I generate two PEX files — one for Python 3.6 and one for Python 3.8. It works out nicely since pex_binary provides interpreter_constraints parameter, so I have two declarations of pex_binary (in the root BUILD file) each having a distinct Python interpreter version constraint. When packaging, I do see that each PEX file (after unpacking for inspection) contains the wheels for the target Python version. I have managed to create a requirements file with pinned transitive 3rd party dependencies with the versions of Python packages that work for both 3.6 and 3.8.
Having two target runtime environments of course implies that it’s required to run tests both against 3.6 and 3.8 interpreter. However, the test goal works only against a single interpreter version:
[python-setup]
interpreter_constraints = ["CPython==3.8.5"]
Is there any way to run tests against multiple Python interpreters that I’ve missed being mentioned in the docs (without manually switching the Python versions in the pants.toml )?witty-crayon-22786
06/30/2021, 9:20 PMpython_tests targets, each with the different constraintswitty-crayon-22786
06/30/2021, 9:21 PMpython_tests targets can declare their own interpreter_constraintswitty-crayon-22786
06/30/2021, 9:22 PMhundreds-father-404
06/30/2021, 9:22 PMfresh-cat-90827
07/01/2021, 4:36 PMhundreds-father-404
07/01/2021, 4:38 PMfresh-cat-90827
07/01/2021, 4:41 PM# pants-plugins/macros.py
def python_tests_global(name, **kwargs):
kwargs.pop("interpreter_constraints", None)
python_tests(
name=f"{name}_py369",
interpreter_constraints=["==3.6.9"],
**kwargs,
)
python_tests(
name=f"{name}_py385",
interpreter_constraints=["==3.8.5"],
**kwargs,
)
in all BUILD files which declare python_tests targets, right? I assume overriding built-in python_tests target is unsupported (or is a bad idea)?hundreds-father-404
07/01/2021, 4:42 PMwitty-crayon-22786
07/01/2021, 4:43 PMI assume overriding built-init’s not the best for clarity, no… introduces some magictarget is unsupported (or is a bad idea)?python_tests
fresh-cat-90827
07/01/2021, 4:52 PM[python-setup]
interpreter_constraints = ["CPython==3.6.9", "CPython==3.8.5"]
it becomes important to make sure no-one is using the built-in python_tests target because Pants will pick either 3.6 or 3.8 when running tests whereas python_tests_global (from the macro above) would test for both versions. Would “banning” python_tests from being used be a good idea at all, if that’s possible? I am curious if there is any more effective way to make support the whole monorepo being tested against two versions, but perhaps there isn’t.hundreds-father-404
07/01/2021, 4:58 PMpants.backend.python
The best I can think of is to lint your BUILD files to not have python_tests, if that's the case every test must run w/ both interpreters. For example, you could use ./pants validate to do this: you can define regex for Pants to check. https://www.pantsbuild.org/docs/reference-sourcefile-validation. (I'm not certain the error message would be super informative tho, as it wouldn't explain the remedy to instead use your macro's name)fresh-cat-90827
07/01/2021, 5:03 PMBUILD files sounds like a fine idea to me, thank you!
The validate goal, when it says
Validate sources against regexes.does it refer to the BUILD files only (i.e. “sources of metadata for Pants”) or to any/some file(s) within the monorepo?
hundreds-father-404
07/01/2021, 5:11 PMwitty-crayon-22786
07/01/2021, 5:13 PMvalidate should move into lint)hundreds-father-404
07/01/2021, 5:17 PMlint can only operate on files owned by targets. It's key that validate can run on any file and doesn't require targetswitty-crayon-22786
07/01/2021, 6:35 PMlint should be able to operate on BUILD files, for examplewitty-crayon-22786
07/01/2021, 6:35 PM