TACC / Lmod

Lmod: An Environment Module System based on Lua, Reads TCL Modules, Supports a Software Hierarchy
http://lmod.readthedocs.org
Other
489 stars 128 forks source link

`isloaded` returning true during load? #615

Closed camillescott closed 1 year ago

camillescott commented 1 year ago

Describe the bug

When checking isloaded within a module file, the result appears to be true even when the module was not previously loaded.

To Reproduce

Using this simple modulefile:

whatis([[Name : testmod]])
whatis([[Version : 1.0]])

if not isloaded("testmod") then
    LmodMessage("testmod loaded.")
end

Produces no output. Removing the not produces output every time; in fact, after the first load, it produces the output twice. Same behavior when also wrapped in an if mode() == "load" clause.

Expected behavior

I was under the impression that the loaded status wasn't set until after the module had completed its load. I've seen the above example use of isloaded in a bunch of places, so perhaps I'm simply misunderstanding something.

Desktop (please complete the following information):

Modules based on Lua: Version 8.7.14  2022-11-01 10:59 -05:00
    by Robert McLay mclay@tacc.utexas.edu

Changes from Default Configuration
----------------------------------

Name                         Where Set  Default      Value
----                         ---------  -------      -----
LFS_VERSION                  D          1.6.3        1.8.0
LMOD_LANG                    E          en           C.UTF-8
LMOD_PACKAGE_PATH            D          nil          <empty>
LMOD_PAGER                   C          less         /usr/bin/less
LMOD_SYSTEM_DEFAULT_MODULES  E          __unknown__  StdEnv
LMOD_TCLSH                   C          tclsh        /share/apps/spack/spack-v0.19/opt/spack/linux-ubuntu22.04-x86_64/gcc-11.3.0/tcl-8.6.12-qaafd7blsox3cglwvvx6kczlp6zyx6um/bin/tclsh
MODULEPATH_ROOT              E                       /share/apps/spack/modulefiles/
PATH_TO_LUA                  C          lua          /share/apps/spack/spack-v0.19/opt/spack/linux-ubuntu22.04-x86_64/gcc-11.3.0/lua-5.4.4-xegzarxwzy7l6xcvxwknnebei6oyrvdw/bin/lua

Additional context

Our lmod is installed by spack; the spack package applies no patches to this version of lmod.

rtmclay commented 1 year ago

You are correct. isloaded() returns true if a module is pending or loaded. Please use isPending() to separate between the two cases. I have updated the docs to point this out.

camillescott commented 1 year ago

Thanks for the response. I was hoping to give my users some feedback similar to environment modules on module load and reload; in particular, it appears that lmod unloads and reloads the module every time you run module load nameofmodule, as opposed to environment modules which no-ops unless you explicitly unload or call reload, and I was hoping to produce a "module reloaded" message when they call module load a second time. Is there a good way to differentiate whether the module is being reloaded short of defining an environment variable for each module and checking it at the beginning?

rtmclay commented 1 year ago

I know of no way to do that inside a module. Even setting a unique env. var inside a module won't work. If A/1.0 is loaded and a user does:

$ module load A/1.0

All env vars set in A/1.0 would have been unset by the time A/1.0 is reloaded. You'd have to modify Lmod to print a message to do that. Consider submitting a PR to provide an optional message to report reloading an already loaded module. See src/Hub.lua for where you might to this.