rules_pip
rules_pip copied to clipboard
can't load modules on python2/3 container
WORKSPACE stuff:
pip_repository(
name = "requirements_py3",
python_interpreter = "python3",
requirements = "//lib/kubernetes:requirements.lock.txt",
)
I have this defined in my BUILD:
# Image for the API
py3_image(
name = "api_docker",
srcs = [":api"],
base = ":python3.7_image",
main = "main.py",
visibility = ["//visibility:public"],
)
py_binary(
name = "api",
srcs = glob(
["*.py"],
),
main = "main.py",
python_version = "PY3",
srcs_version = "PY3",
deps = [
"//lib/kubernetes:kubernetes_util",
"@requirements_py3//docopt",
"@requirements_py3//dulwich",
"@requirements_py3//flask",
"@requirements_py3//gevent",
"@requirements_py3//prometheus_client",
],
)
The first thing in main.py is
from gevent import monkey
monkey.patch_all()
When I try to bazel run the docker image, I get this:
Traceback (most recent call last):
File "/app/apps/switchboard/api/api_docker.binary.runfiles/com_something/apps/switchboard/api/main.py", line 10, in <module>
from gevent import monkey
ImportError: cannot import name 'monkey' from 'gevent' (/app/apps/switchboard/api/api_docker.binary.runfiles/requirements_py3/gevent/__init__.py)
The application works as expected when running the py_binary with bazel run
Any known issues regarding using a container with pip_repository?
It looks to me that this is because all libraries are in requirements_py3 folder and python_stub from bazel loads only directories inside .binary.runfiles. So it will load the requirements_py3 folder, but nothing inside it.
All libraries should go to binary.runfiles dir instead, I think.
In bazel python stub libraries are read here and module_space is the runfile directory