'How to generate a token using bash-like command when creating a conda environment using a yaml requirement file?

I need to generate a token on the fly (short lived token) to access a python package on some Artifact Registry (Google Cloud Platform). The best is to run a bask-like command. It seems that conda only support environment variable with value (no bash-like command and only available when the env is created environment variable). I need to have the enviroment variable defined when creating the conda env. Also it seems that when creating a conda env, conda cannot access "global" environment variable. This is my requirements.yaml:

name: env_private_package
channels:
- defaults
- conda-forge
dependencies:
- python=3.8
- pip=22.0
- pip:
   - --extra-index-url https://oauth2accesstoken:[email protected]/yyyy/simple/
   - my-package==0.2.1  # private package on GCP Artifact Registry
variables:
  MYTOKEN: gcloud auth print-access-token
  ENV_NAME: env_private_package

Conda environment is created in the following way:

conda env created -f requirement.yaml

Any idea how I could do that in the conda environment yaml file or pip config file pip.conf or in any kind of pre-script.sh that conda could execute. I am using the latest version of miniconda 4.11.0.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source