boa icon indicating copy to clipboard operation
boa copied to clipboard

[FeatureRequest] Automatic generation of basic activate/deactivate scripts

Open dhirschfeld opened this issue 3 years ago • 7 comments

Fairly often I need to create activate/deactivate scripts to do 2 common things:

  1. Set an env var
  2. Add an entry to the path

It would be great if these 2 common requirements could be declaratively specified in the recipe.yaml and have boa automatically generate the necessary activate/dectivate scripts

dhirschfeld avatar Mar 09 '22 10:03 dhirschfeld

Doing 1 correctly is slightly tricky and very verbose to do manually (particularly for multiple variables). To do it correctly you want to save the original value on activate and restore it on deactivate.

Similarly for 2, adding to the path is easy enough but robustly removing it again on deactivate whilst seamlessly handling other path changes in-between is tedious.

This is the sort of thing automation could (fairly) easily handle and would generally improve the robustness of most activate/deactivate scripts.

dhirschfeld avatar Mar 09 '22 11:03 dhirschfeld

@dhirschfeld one approach is https://github.com/mamba-org/multisheller

This has been used in the community, e.g. in this recipe: https://github.com/conda-forge/icub-models-feedstock/blob/main/recipe/activate.msh

wolfv avatar Mar 09 '22 11:03 wolfv

It works for exactly the use cases you are describing (special function to add & remove path from PATH and setting / unsetting some env vars).

wolfv avatar Mar 09 '22 11:03 wolfv

Also, I imagine most activate/deactivate scripts only work with bash. Automating this process would let you use multisheller to ensure conda packages worked for all shells.

dhirschfeld avatar Mar 09 '22 11:03 dhirschfeld

one approach is https://github.com/mamba-org/multisheller

Yep - my thoughts exactly! 😄

...it would just be nice if you could somehow automate the generation of the activate/deactivate scripts - e.g.

env_vars:
  - DOTNET_ROOT: {{ PREFIX }}/dotnet

...and have that automatically generate activate/deactivate scripts for all supported shells

dhirschfeld avatar Mar 09 '22 11:03 dhirschfeld

Anyway, just something I've been pondering so I thought I'd write it up for reference.

Prompted by having to maintain 6 env vars and 2 path entries for 3 different shells over in the dotnet feedstock.

I would like to use multisheller for this now, but have only had a quick look at it so far - it's on my TODO list to investigate 😔

dhirschfeld avatar Mar 09 '22 11:03 dhirschfeld

This has been used in the community, e.g. in this recipe

Awesome, thanks for the ref! That'll be a huge help in figuring out how to port to multisheller!

dhirschfeld avatar Mar 09 '22 11:03 dhirschfeld