Lmod icon indicating copy to clipboard operation
Lmod copied to clipboard

Reusing environment variables defined by other modules

Open AreWeDreaming opened this issue 9 months ago • 1 comments

I have encountered the following situation and I could not find an immediate solution in the documentation. Assume I have a module A:

setenv("NETCDF_DIR","<path to NetCDF>")

and a module B for a legacy application that depends on A :

depends_on("A")
setenv("NETCDF_BUILD_ARG","-L" .. os.getenv("NETCDF_DIR") .. "/lib")

Now I can module load B just fine, but when I module purge $NETCDF_BUILD_ARG remains defined because $NETCDF_DIR becomes undefined before $NETCDF_BUILD_ARG can be unset. I understand that this problem could be solved by modifying module A such that it reads

setenv("NETCDF_DIR","<path to NetCDF>")
prepend_path("MODULEPATH", "<path containing module B>")

and isolate B to a separate folder and remove the depends_on statement, but unfortunately this solution would be difficult to implement in our current circumstances.

So my question is, if structuring modules hierarchically is not an option, is there a recommended way of how modules can use environment variables that have been defined by other modules? Thank you for your help in advance!

AreWeDreaming avatar May 10 '24 00:05 AreWeDreaming