setup-micromamba icon indicating copy to clipboard operation
setup-micromamba copied to clipboard

Activate environment directly

Open artemisart opened this issue 8 months ago β€’ 3 comments

Hello, setup-micromamba needs a login shell to activate its env with bash -l, however I found out this makes any change to $GITHUB_PATH ineffective, which are needed to add directories to PATH (echo "some/dir" >> $GITHUB_PATH https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#adding-a-system-path). Would it be possible to activate the env directly instead? (I guess we only need the env dir in PATH + CONDA_PREFIX env). Thanks!

artemisart avatar Apr 24 '25 23:04 artemisart

Conda environments can have arbitrary activation scripts as well that set other env variables. So to properly set those, we need to take those into account as well and write them to GITHUB_ENV.

Setup-pixi has such a feature by calling pixi shell-hook --json and then parsing that accordingly, see https://github.com/prefix-dev/setup-pixi?tab=readme-ov-file#environment-activation

I think there is something similar to pixi shell-hook for micromamba as well (do you know if that's true @jjerphan?). One would need to parse that (ideally json) in some way and could steal the code from setup-pixi.

pavelzw avatar Apr 25 '25 07:04 pavelzw

Hi @artemisart,

Long time no see. I hope you have enjoyed your time at NUS, lah! πŸ‡Έβ€πŸ‡¬ 🦁

You can have a look at using:

# `micromamba shell hook` has a few options you can use if needed. 
eval $(micromamba shell hook)
micromamba activate env_name

at the start of new shell session.

jjerphan avatar Apr 28 '25 08:04 jjerphan

a micromamba shell hook --json would be nice that outputs something like

{
  "environment_variables": {
    "CONDA_PREFIX": "/home/user/mircomamba/envs/my-env",
    "CONDA_DEFAULT_ENV": "my-env",
    "PATH": "/home/user/mircomamba/envs/my-env/bin:...:/usr/local/bin:/bin"
  }
}

then we could also use this in setup-micromamba and write the corresponding variables to $GITHUB_ENV and $GITHUB_PATH. that works quite well in setup-pixi

pavelzw avatar Apr 28 '25 20:04 pavelzw