Closed ModestMC closed 4 months ago
This is not a bug. Lmod unsets the environment variables when each command is happening. You have to do it this way:
local testdir = os.getenv("HOME") .. "/test"
setenv("TESTDIR", testdir)
prepend_path("TESTPATH", testdir)
Lmod will not allow you string join a nil to a string nor append/prepend a nil to a path-like variable.
The line setenv("TESTDIR", os.getenv("HOME") .. "/test")
is reversed on unload so TESTDIR is unset. This means when the next line is evaluated it becomes: prepend_path("TESTPATH", nil)
. which is an illegal command
You are correct, my apologies. If this is an illegal command, what is the intent in having this be a warning instead of an error? When the unload step occurs, the module itself unloads, the variable itself is unmodified and can only be restored by fully closing and reopening the terminal. Sorry to be a bother, thank you for the help
Because unloads must always succeed. It is an error to do prepend("PATH",nil) on load but it must be a warning when unloading a module.
Understood. I'm going to close this issue, but I do think this subject is worth understanding.
I'm guessing the reason an unload must always succeed is so that resets/purges/etc are always able to execute; when the warnings appear, the variable/path modifications made on load are still left behind, so to get a clean shell the user either has to manually undo any modifications that were unloaded or they have to close their session and open a new one.
This to me is a better outcome than a user having a module stuck in their moduletable. Is that the rationale?
Correct. Having a module a user cannot delete is bad.
Describe the bug Setting an environment variable with an internal os.getenv() call works correctly, however using such a call when appending or prepending to a path raises
Lmod Warning: Syntax error in file: [path to file] with command prepend_path, one or more arguments are not strings.
The error occurs when unloading.To Reproduce Steps to reproduce the behavior:
Here is a short modulefile which should replicate the bug:
Expected behavior Either when loading the module such a call should not be allowed or it correctly pulls the variables used in the paths.
Desktop (please complete the following information):
module --miniConfig
output:Name Where Set Default
Value
LMOD_AUTO_SWAP E yes
no LMOD_DISABLE_SAME_NAME_AUTOSWAP E no
yes LMOD_HAVE_LUA_TERM C no
yes LMOD_PACKAGE_PATH D nil