doc: howto configure bazel downloader with pip.parse
I think I've seen this question a few times: I want to customize where wheels are downloaded from. What parameters do I set in (pip.parse or compile_pip_requirements) to do that?
When the answer is non-obvious: use bazel downloader to redirect the url requests.
This is mentioned in the regular pypi docs, but only briefly; it's easy to overlook.
We should give an example in the docs on how to do this.
A dedicated "how to" sub-directory of docs is probably a good idea. It'll be a good place to put prose documentation that draws people in, and we can easily expand it with arbitrary topics and content without it feeling out of place or bloating the more dry/technical/reference docs.
I have some experience here - we pull our all python wheels from internal Airlock and a private GAR. Please at least CC me on the PR.
@dougthor42 here we have a scenary where we need to pull a wheel from Google Artifact Registry. I tried using credential helper, but didnt get lucky. Since this how to doc is still not ready, would you mind share how you made it work?
Here's a quick summary example, specific to Google Artifact Registry ("GAR").
#!/bin/bash
# Credential helper
# ./cred_helper.sh
TOKEN=$(gcloud auth application-default print-access-token)
readonly TOKEN
# Note: pretty-printing the JSON is optional
echo '{'
echo ' "headers": {'
echo ' "Authorization": ['
echo ' "Bearer '"${TOKEN}"'"'
echo ' ]'
echo ' }'
echo '}'
# MODULE.bazel
pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
pip.parse(
experimental_index_url = YOUR_GAR_INDEX_URL,
experimental_index_url_overrides = {"foo": OTHER_INDEX_URL},
hub_name = "pypi",
python_version = PYTHON_VERSION,
requirements_lock = "//:requirements.txt",
)
use_repo(pip, "pypi")
# .bazelrc
common --credential_helper=us-west2-python.pkg.dev=%workspace%/cred_helper.sh
common --credential_helper=us-python.pkg.dev=%workspace%/cred_helper.sh
# requirements.txt
# This file was autogenerated by uv via the following command:
# uv pip compile --python-version=3.12 --output-file=requirements.txt requirements.in
--index-url https://[email protected]/REDACTED/simple
--extra-index-url https://[email protected]/REDACTED/simple
absl-py==2.3.0 \
--hash=sha256:9824a48b654a306168f63e0d97714665f8490b8d89ec7bf2efc24bf67cf579b3 \
--hash=sha256:d96fda5c884f1b22178852f30ffa85766d50b99e00775ea626c23304f582fc4f
# via
# dm-tree
...
Thank you @dougthor42