Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't pipx install packages from google artifact registry. #1200

Closed
IanSmith-IonQ opened this issue Jan 10, 2024 · 1 comment
Closed

Can't pipx install packages from google artifact registry. #1200

IanSmith-IonQ opened this issue Jan 10, 2024 · 1 comment

Comments

@IanSmith-IonQ
Copy link

IanSmith-IonQ commented Jan 10, 2024

Describe the bug

Im trying to use Google artifact registry (GAR) with pipx, but can't seem to get the authentication to work as expected. I can get it to work with pip in a virtual environment when keyring is "imported", but not with pipx or pip with keyring as "subprocess". My end goal is to use pipx, but the fact that pip doesn't work with a subprocess keyring might be part of my issue.

What i think some of my issues are....

  1. PIP_FORCE_KEYRING doesn't seem to be working as I don't see pip (through pipx) trying to authenticate to GAR. If I rerun pipx's commands, but remove the --no-input flag authentication will be attempted ... but fails, see next.
  2. I don't think Im correctly using keyring via "subprocess", and can't seem to figure out how to make it work. Do I need to set the user in the extra-index-url to a oauth2 access token? How would I generate that (ive tried a few from gcloud without success).

How to reproduce the issue
My setup.

FAILS: pipx install with GAR authentication via subprocess keyring-provider

pipx install keyring
pipx inject keyring keyrings.google-artifactregistry-auth
gcloud auth application-default login

which pipx
<</c/Python311/Scripts/pipx

which keyring
<</c/users/****/.local/bin/keyring

keyring --list-backends
<<keyrings.gauth.GooglePythonAuth (priority: 9)
<<keyring.backends.fail.Keyring (priority: 0)
<<keyring.backends.chainer.ChainerBackend (priority: 10)
<<keyring.backends.Windows.WinVaultKeyring (priority: 5)

set PIP_KEYRING_PROVIDER=subprocess
set PIP_FORCE_KEYRING=1
set PIP_EXTRA_INDEX_URL=https://***/simple/

pipx install --verbose ******

pipx >(setup:850): pipx version is 1.4.1
pipx >(setup:851): Default python interpreter is 'C:\Python311\python.exe'
pipx >(package_name_from_spec:370): Determined package name: ***
pipx >(package_name_from_spec:371): Package name determined in 0.0s
creating virtual environment...
pipx >(run_subprocess:168): running C:\Python311\python.exe -m venv --without-pip C:\Users\***\AppData\Local\pipx\pipx\venvs\***
pipx >(run_subprocess:168): running <checking pip's availability>
pipx >(run_subprocess:168): running C:\Users\***\AppData\Local\pipx\pipx\venvs\***\Scripts\python.exe -c import sysconfig; print(sysconfig.get_path('purelib'))
pipx >(run_subprocess:168): running C:\Users\***\AppData\Local\pipx\pipx\shared\Scripts\python.exe -c import sysconfig; print(sysconfig.get_path('purelib'))
pipx >(run_subprocess:168): running C:\Users\***\AppData\Local\pipx\pipx\venvs\***l\Scripts\python.exe --version
pipx >(_parsed_package_to_package_or_url:137): cleaned package spec: *****
installing *** from spec '******'...
pipx >(run_subprocess:168): running C:\Users\***\AppData\Local\pipx\pipx\venvs\***\Scripts\python.exe -m pip --no-input install ******
pipx >(subprocess_post_check_handle_pip_error:327): 'C:\\Users\\***\\AppData\\Local\\pipx\\pipx\\venvs\\***\\Scripts\\python.exe -m pip --no-input install ******' failed
pipx >(subprocess_post_check_handle_pip_error:342): Fatal error from pip prevented installation. Full pip output in file:
    C:\Users\***\AppData\Local\pipx\pipx\Logs\cmd_2024-01-10_14.23.14_pip_errors.log

Some possibly relevant errors from pip install:
    ERROR: Could not find a version that satisfies the requirement ****** (from versions: none)
    ERROR: No matching distribution found for ******

pipx >(rmdir:55): removing directory C:\Users\***\AppData\Local\pipx\pipx\venvs\***
Error installing *** from spec '******'.

pip_errors.log

PIP STDOUT
----------
Looking in indexes: https://pypi.org/simple, https://***/simple/

PIP STDERR
----------
ERROR: Could not find a version that satisfies the requirement ****** (from versions: none)
ERROR: No matching distribution found for ******

FAILS: Run without --no-input
Using the same method as pipx to setup a venv and ru-run the failing command but without --no-input.

C:\Users*\AppData\Local\pipx\pipx\venvs*\Scripts\python.exe -m pip install ******
<<Looking in indexes: https://pypi.org/simple, https://***/simple/
<<User for ***: <---Wants user input for user name

WORKS: Run without --no-input and with keyring-provider as import
I'm adding the keyring package to this venv and forcing keyring-provider to be import.

C:\Users*\AppData\Local\pipx\pipx\venvs*\Scripts\python.exe -m pip install keyring keyrings.google-artifactregistry-auth
C:\Users*\AppData\Local\pipx\pipx\venvs*\Scripts\python.exe -m pip install ****** --keyring-provider import
The package is installed as expected here.

Expected behavior

I think pipx should install the package from GAR with the environment variable overrides and setup used.

@IanSmith-IonQ
Copy link
Author

IanSmith-IonQ commented Jan 11, 2024

Figured it out. All I needed to do was modify my index url to include the username: oauth2accesstoken. 🤦

So for GAR ... the url format needed is: https://oauth2accesstoken@LOCATION-python.pkg.dev/PROJECT/REPOSITORY/simple

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant