I have a question about conditionally determining ...
# general
s
I have a question about conditionally determining requirements with Pants. We have a
Makefile
that checks
UNAME
and installs either
tensorflow
or
tensorflow-macos
into our
venv
. This isn’t an ideal situation but some of the engineers laptops are M1s while others aren't. I'd like to be able to run something like
./pants test ::
and have the right dependency determined automatically
e
Luckily the answer is not specific to Pants, just add 2 requirements with mutually exclusive environment markers: https://peps.python.org/pep-0508/#environment-markers
s
Thanks for the quick answer!
e
Pants ships with a lot of module mappings, but you may need to add one for tensorflow-macos (presumably it ships a top level package of tensorflow): https://www.pantsbuild.org/docs/reference-python_requirements#codemodule_mappingcode
1
s
I have
"tensorflow-macos": ["tensorflow"]
in
module_mapping
and when I include just
tensorflow-macos~=2.11.0;platform_machine=='arm64'
things work as expected. However if I have both
Copy code
tensorflow~=2.11.0;platform_machine=='x86_64'
tensorflow-macos~=2.11.0;platform_machine=='arm64'
I see
ModuleNotFoundError: No module named 'tensorflow'
e
Have you tried adding an explicit identity module mapping as well?
If that doesn't work you may need to break the pair into a single
python_requirement
target and remove them from the requirements file: https://www.pantsbuild.org/docs/reference-python_requirement
c