Skip to content

Commit

Permalink
inject keyrings.google-artifactregistry-auth for GCP PyPI (#1782)
Browse files Browse the repository at this point in the history
* inject keyrings.google-artifactregistry-auth for GCP PyPI

* add comment
  • Loading branch information
madhur-ob committed Mar 29, 2024
1 parent 47c205c commit e577781
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
9 changes: 9 additions & 0 deletions metaflow/plugins/pypi/conda_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,15 @@ def get_environment(self, step):
# Match PyPI and Conda python versions with the resolved environment Python.
environment["pypi"]["python"] = environment["conda"]["python"] = env_python

# When using `Application Default Credentials` for private GCP
# PyPI registries, the usage of environment variable `GOOGLE_APPLICATION_CREDENTIALS`
# demands that `keyrings.google-artifactregistry-auth` has to be installed
# and available in the underlying python environment.
if os.getenv("GOOGLE_APPLICATION_CREDENTIALS"):
environment["conda"]["packages"][
"keyrings.google-artifactregistry-auth"
] = ">=1.1.1"

# Z combinator for a recursive lambda
deep_sort = (lambda f: f(f))(
lambda f: lambda obj: (
Expand Down
10 changes: 9 additions & 1 deletion metaflow/plugins/pypi/pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,17 @@ def _call(self, prefix, args, env=None, isolated=True):
prefix,
"pip3",
"--disable-pip-version-check",
"--no-input",
"--no-color",
]
# credentials are being determined from the JSON file referenced by
# the GOOGLE_APPLICATION_CREDENTIALS environment variable and are
# probably injected dynamically via `keyrings.google-artifactregistry-auth`
# Thus, we avoid passing `--no-input` in this case.
+ (
["--no-input"]
if os.getenv("GOOGLE_APPLICATION_CREDENTIALS") is None
else []
)
+ (["--isolated"] if isolated else [])
+ args,
stderr=subprocess.PIPE,
Expand Down

0 comments on commit e577781

Please sign in to comment.