narrow-activity-17405
02/23/2023, 8:05 AMpants.toml
to get all tools (most importantly mypy) and tests running with the specific version of Python? Is that possible? I would like to catch problems that are specific for a specific version of Python. From docs I'm not sure whether this is possible with mypy. The repo is https://github.com/5G-ERA/era-5g-clientrefined-addition-53644
02/23/2023, 8:39 AMnarrow-activity-17405
02/23/2023, 10:54 AMpython_sources
with different interpreter_constraints, which, as I believe, works fine. But I'g getting warnings like "Pants cannot safely infer a dependency because more than one target owns this module, so it is ambiguous which to use". Is it safe to ignore, or should I do it differently?python_sources(
name="lib",
skip_mypy=True,
skip_black=True,
skip_flake8=True,
)
python_sources(name="lib_py38", interpreter_constraints=["==3.8.*"])
python_sources(name="lib_py39", interpreter_constraints=["==3.9.*"])
python_sources(name="lib_py310", interpreter_constraints=["==3.10.*"])
refined-addition-53644
02/23/2023, 12:24 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,
)
You can first test it without macro like you have done with the python_sources
currently and later move it to a macropython_sources(
name="lib",
skip_mypy=True,
skip_black=True,
skip_flake8=True,
)
Currently your sources are being owned by lib
and one or more of lib_py38, lib_py39, lib_py310
based on whatever is your default interpreter_constraints
Although doing it at test level makes more since that’s how you are going to check if the code works with different versions of python or not.curved-television-6568
02/23/2023, 1:27 PMparametrize
instead of the macro
https://www.pantsbuild.org/docs/targets#parametrizing-targets
Snippet from the docs:
# Creates four targets:
#
# example:tests@interpreter_constraints=py2,resolve=lock-a
# example:tests@interpreter_constraints=py2,resolve=lock-b
# example:tests@interpreter_constraints=py3,resolve=lock-a
# example:tests@interpreter_constraints=py3,resolve=lock-b
python_test(
name="tests",
source="tests.py",
interpreter_constraints=parametrize(py2=["==2.7.*"], py3=[">=3.6"]),
resolve=parametrize("lock-a", "lock-b"),
)
happy-kitchen-89482
02/23/2023, 5:20 PMnarrow-activity-17405
02/28/2023, 10:01 AMparametrize
, and it works, but... 🙂 I probably need to specify dependencies everywhere then...curved-television-6568
02/28/2023, 1:17 PM__defaults__
https://www.pantsbuild.org/docs/targets#field-default-values