pythongoogle-cloud-platformuv

Issues with Using `--extra-index-url` in `uv` with Google Cloud Artifact Registry


I'm trying to create a uv project that uses an --extra-index-url with Google Cloud Artifact Registry. According to the uv documentation, this should be possible. I am using uv 0.4.18. Here's what I've tried so far:

gcloud auth application-default login --project ${PROJECT_ID}                      
uv venv
source .venv/bin/activate
uv pip install keyring keyrings.google-artifactregistry-auth
uv pip install --keyring-provider subprocess ${MY_PACKAGE} --extra-index-url https://${REGION}-python.pkg.dev/${PROJECT_ID}/${REPOSITORY_ID}/simple                            

However, it returns an error indicating that my package can't be found. Interestingly, when I use standard Python, I can install my private package without any issues. Here's the code that works:

gcloud auth application-default login --project ${PROJECT_ID}                      
python -m venv .venv
source .venv/bin/activate
pip install keyring keyrings.google-artifactregistry-auth
pip install ${MY_PACKAGE} --extra-index-url https://${REGION}-python.pkg.dev/${PROJECT_ID}/${REPOSITORY_ID}/simple                            

It seems like others have faced this issue before, as mentioned in this closed GitHub issue. Has anyone else encountered this problem or found a workaround? Any help would be appreciated!


Solution

  • Pointing to the solution of the issue here:

    The code that works is:

    gcloud auth application-default login --project ${PROJECT_ID}                      
    uv venv
    source .venv/bin/activate
    uv pip install keyring keyrings.google-artifactregistry-auth
    uv pip install ${MY_PACKAGE} --keyring-provider subprocess --extra-index-url https://oauth2accesstoken@${REGION}-python.pkg.dev/${PROJECT_ID}/${REPOSITORY_ID}/simple
    
    

    The addition of the oauth2accesstoken string in the URL is necessary for the keyring CLI to retrieve a password, as pointed out in uv's GitHub issue 1520.