feat/fix(pip): enable local paths for experimental_index_url by adrianimboden · Pull Request #3312 · bazel-contrib/rules_python
Hi rules_python team
I use your rules for a long time now. With WORKSPACE style, I use pip as follows:
pip_parse(
name = "py_deps",
extra_pip_args = [
"--index-url=/home/user/local_pip_mirror",
"--no-cache-dir",
],
python_interpreter = "python3",
python_interpreter_target = interpreter,
requirements_lock = ":requirements_lock.txt",
)
The folder /home/user/local_pip_mirror gets populated with pypi-mirror download --requirement requirements_lock.txt
So I have a nice and clean way to use offline build. I could never get it running directly with bazel fetch and stuff. But this solution was very nice because no internet was involved at all.
I am in the way of upgrading to bzlmod. I saw many bug reports for making offline build work, but I honestly gave up with bazel vendor and stuff again. The simplest way in my opinion is to just use a local pip mirror. For that I tried the following:
pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
pip.parse(
experimental_index_url = "/home/user/local_pip_mirror",
hub_name = "py_deps",
python_version = python_version,
requirements_lock = "//:requirements_lock.txt",
)
use_repo(pip, "py_deps")
at the moment, experimental_index_url must be a https:// url to work.
This MR changes it so that local paths are also a possible experimental_index_url.
For my project, the proposed changes are in effect and working great.
It is not perfect, but I think it is an important addition to aid the bzlmod migration.