Dynamically calculating envar: My company uses GAR...
# general
h
Dynamically calculating envar: My company uses GAR artifact repository where my company hosts packages(python wheels). Primarily google recommends using
keyrings
to authenticate to GAR's https://cloud.google.com/artifact-registry/docs/python/store-python#configure However pants doesn't support keyring. I also tried. adding
keyring
to
PATH
but that didn't work. i have another workaround though,
Copy code
[python-repos]
indexes.add = [
  "<https://oauth2accesstoken>:%(env.GOOGLE_ACCESS_TOKEN)s@us-central1-python.pkg.dev/<project>/<repository>/simple",
]
however it needs google auth token, and the way i can generate these token is
gcloud auth print-access-token
which have a ttl of 5min(or so). So currently i have to run all pants related commands like
GOOGLE_ACCESS_TOKEN="$(gcloud auth print-access-token)" pants check ::
or
GOOGLE_ACCESS_TOKEN="$(gcloud auth print-access-token)" pants generate-lockfiles
. is it possible to have this
GOOGLE_ACCESS_TOKEN
also computed dynamically by
pants
itself ? maybe by definiting this as an
alias
?
c
Hi, the builtin alias support in pants is merely string substitution, so doesn’t lend itself to dynamic values. What you can do however, is use a
.pants.bootstrap
script:
Copy code
export GOOGLE_ACCESS_TOKEN="$(gcloud auth print-access-token)"
h
that worked. Thanks @curved-television-6568 is there a document or link where i can find about
.pants.bootstrap
. ? I see
python-bootstrap
but not
.pants.bootstrap
c
It’s not mentioned in the regular docs, I believe, so it’s a little known well hidden gem, briefly presented here: https://github.com/pantsbuild/pants/discussions/17633
h
this is great. super useful, thanks.
👍 1