quaint-telephone-89068
02/06/2023, 1:35 PMproject
- pants.toml
- module_A
- requirements.txt
- src/script_A.py # imports tensorflow
- tests
- test_A.py # imports a function from script_A.py
- BUILD
- BUILD
- utils
- requirements.txt
- src/utils.py
- tests
- test_utils.py
- BUILD
- BUILD
module_A/requirements.txt sources all the requirements from utils and also adds tensorflow, which is installed in its regular version on Linux and MacOS with Intel chip, and in ints special build for Macs with the M1 chip:
-r ../utils/requirements.txt
tensorflow==2.9.1; sys_platform == "linux" or platform_machine == "x86_64"
tensorflow-macos==2.9.1; platform_machine == "arm64"
module_A/BUILD specifies the python requirements:
python_requirements(
name="reqs",
source="requirements.txt",
)
and module_A/tests/BUILD specifies the test to be run:
python_sources(name="module-a-tests", sources=["test_*.py"])
python_tests(name="test-module-a")
I am using the outermost directory (project) as the source root.
When I run pants test ::, it fails with ModuleNotFoundError: No module named 'tensorflow'. If I comment-out the line tensorflow==2.9.1; sys_platform == "linux" or platform_machine == "x86_64" from requirements.txt and only install the MacOS version, than it works. But I need to have both these line there so that it also works for teammates using linux and MacOS with the Intel chip.
I am also able to make it work by setting python_sources(dependencies=["module_A:reqs#tensorflow-macos"]) in its BUILD file but this still forces me to manually set which package build I want to use.
I expected to be able to solve the problem by adding module_mapping to module_A/BUILD (since both tensorflow and tensorflow-macos are importable as tensorflow) but I could not make it work. Can you please tell me what I am doing wrong?
Pants version
2.14.1
OS
MacOS 12.5.1 with M1 chip
pantsbuild/pantsuser
02/06/2023, 10:54 PM