rules_python
rules_python copied to clipboard
Best way to install / use build dependencies before / during pip_install
🚀 feature request
Relevant Rules
pip_install, pip_parse
Description
Imagine following setup:
# WORKSPACE
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "rules_python",
sha256 = "c03246c11efd49266e8e41e12931090b613e12a59e6f55ba2efd29a7cb8b4258",
strip_prefix = "rules_python-0.11.0",
url = "https://github.com/bazelbuild/rules_python/archive/refs/tags/0.11.0.tar.gz",
)
load("@rules_python//python:repositories.bzl", "python_register_toolchains")
python_register_toolchains(
name = "python39",
python_version = "3.9",
)
load("@python39//:defs.bzl", "interpreter")
load("@rules_python//python:pip.bzl", "pip_parse", "pip_install")
pip_parse(
name = "pip",
python_interpreter_target = interpreter,
requirements_lock = "//:requirements_lock.txt",
)
load("@pip//:requirements.bzl", "install_deps")
install_deps()
# BUILD
load("@rules_python//python:pip.bzl", "compile_pip_requirements")
compile_pip_requirements(
name = "requirements",
extra_args = ["--allow-unsafe"],
requirements_in = "requirements.in",
requirements_txt = "requirements_lock.txt",
)
# requirements.in
numpy==1.20.2
scikit-image==0.16.2
Now I'm running following command bazel run //:requirements.update and getting an error like this:
Traceback (most recent call last):
File "<string>", line 2, in <module>
File "<pip-setuptools-caller>", line 34, in <module>
File "/private/var/folders/_6/s8d7xtw94t7gk408d0x6zhxc0000gn/T/pip-resolver-df78cmep/scikit-image/setup.py", line 243, in <module>
'build_ext': openmp_build_ext(),
File "/private/var/folders/_6/s8d7xtw94t7gk408d0x6zhxc0000gn/T/pip-resolver-df78cmep/scikit-image/setup.py", line 71, in openmp_build_ext
from numpy.distutils.command.build_ext import build_ext
ModuleNotFoundError: No module named 'numpy'
This is because numpy cannot found by the python interpreter during pip install. Now I'm wondering what is the best way to solve this? Using a virtualenv or ist it possible the patch the prebuild python interpreter?
Describe the solution you'd like
In my opinion the best way would be to add additional packages to the python toolchain.
Describe alternatives you've considered
Alternative would be the enrich the documentations / examples how to do this in an alternative way with virtualenvs.