https://pantsbuild.org/ logo
s

silly-queen-7197

02/13/2023, 11:41 PM
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

enough-analyst-54434

02/14/2023, 12:02 AM
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

silly-queen-7197

02/14/2023, 12:03 AM
Thanks for the quick answer!
e

enough-analyst-54434

02/14/2023, 12:04 AM
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

silly-queen-7197

02/14/2023, 1:08 AM
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

enough-analyst-54434

02/14/2023, 1:42 AM
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

curved-television-6568

02/14/2023, 1:57 AM
5 Views