conda / conda-build

Commands and tools for building conda packages
https://docs.conda.io/projects/conda-build/
Other
384 stars 424 forks source link

Simpler/alternative way to set environment variables (than activate/deactivate scripts) #4833

Open jakirkham opened 1 year ago

jakirkham commented 1 year ago

Checklist

What is the idea?

Much like we have script_env to pass or set environment variables into the package build process, it would be handy to have a run_env (or similar) to allow setting environment variables during package activation. This could handle backup environment variables and restoring them in a uniform way.

Some other things we might consider:

Why is this needed?

Many (de)activation scripts do little more than (un)set environment variables. For example here are some (de)activation scripts from conda-forge that mainly manage environment variables. While there can be the occasional (de)activate script that does a bit more (like prepend/append to the PATH or run some code). Most (de)activation scripts don't need this.

Despite this relatively simple use case (de)activation scripts can wind up becoming quite complicated as they may need to check if a variable is already set before setting it and keep backups of environment variables, which they then need to restore later. As a result of this complexity, relatively simple shell scripts end up with bash-ism or other shell specific behavior making them non-portable ( https://github.com/conda-forge/r-base-feedstock/issues/221 ). This in turn leads to maintenance complexity ( https://github.com/conda/conda-build/issues/3880 ) ( https://github.com/conda/conda-build/issues/4012 ) ( https://github.com/conda/conda/issues/7993 ).

Providing a simple path to set environment variables in a platform and shell agnostic manner would go a long way towards eliminating these kind of pain points before they show up.

What should happen?

No response

Additional Context

No response

jakirkham commented 1 year ago

cc @jezdez @wolfv (as we briefly discussed this at today's community call)

jakirkham commented 1 year ago

It's worth noting there may already be a basis for building this kind of functionality using existing package metadata ( https://github.com/conda/conda/issues/6820#issuecomment-1269581626 ). That said, there is a bug we'd likely want to fix as part of that work ( https://github.com/conda/conda/issues/11726 )

github-actions[bot] commented 6 months ago

Hi there, thank you for your contribution!

This issue has been automatically marked as stale because it has not had recent activity. It will be closed automatically if no further activity occurs.

If you would like this issue to remain open please:

  1. Verify that you can still reproduce the issue at hand
  2. Comment that the issue is still reproducible and include:
    • What OS and version you reproduced the issue on
    • What steps you followed to reproduce the issue

NOTE: If this issue was closed prematurely, please leave a comment.

Thanks!

jakirkham commented 6 months ago

(not stale)