rules_python icon indicating copy to clipboard operation
rules_python copied to clipboard

doc: howto configure bazel downloader with pip.parse

Open rickeylev opened this issue 6 months ago • 4 comments

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.

rickeylev avatar Jul 17 '25 17:07 rickeylev

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 avatar Jul 18 '25 16:07 dougthor42

@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?

AFMiziara avatar Sep 22 '25 23:09 AFMiziara

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
...

dougthor42 avatar Oct 06 '25 17:10 dougthor42

Thank you @dougthor42

AFMiziara avatar Oct 07 '25 21:10 AFMiziara