TACC / Lmod

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

purge in a module #657

Closed smithsp closed 1 year ago

smithsp commented 1 year ago

I have a module (call it module1) for which I would like to purge any other modules if they are loaded, as part of module1. In TCL, I could put in a module purge. However, I can't find the similar function in the lua documentation. Any suggestions? Or should I just continue to use TCL?

smithsp commented 1 year ago

Actually, with this version of lmod: Modules based on Lua: Version 8.7.20 2023-03-16 11:43 -05:00 the module purge command in a TCL module file no longer purges the modules in the subsequent environment:

$ module purge
$ module load defaults
$ module list

Currently Loaded Modules:
  1) default-paths               9) mse/V3_07-pgf20.11
  2) gcc/8.x                    10) idl_tools/css/1.0
  3) nvidia_hpc_sdk/20.11       11) idl_tools/4dlib/1.0
  4) env/gcc8.x-pgf20.11        12) python/3.7.9
  5) d3lib/gcc                  13) matlab/2022b
  6) libidl_ga/pgf              14) efit/gnu
  7) mdsplus/d3d/alpha-7.130.1  15) defaults
  8) idl/8.8
$ module load omfit
Module purge
$ module list

Currently Loaded Modules:
  1) default-paths          7) mdsplus/d3d/alpha-7.130.1  13) matlab/2022b
  2) gcc/8.x                8) idl/8.8                    14) efit/gnu
  3) nvidia_hpc_sdk/20.11   9) mse/V3_07-pgf20.11         15) defaults
  4) env/gcc8.x-pgf20.11   10) idl_tools/css/1.0          16) VScode/default
  5) d3lib/gcc             11) idl_tools/4dlib/1.0        17) omfit/master_v3
  6) libidl_ga/pgf         12) python/3.7.9
$ cat omfit/master_v3
#%Module
#
# Module file for loading paths and environment for OMFIT
#

# Purge... unless $OMFIT_TMPDIR is set
if { ! [ info exists env(OMFIT_TMPDIR) ] } { 
  if { [ module-info mode load ] } { 
  module purge
  puts stderr "Module purge"
  } 
}
smithsp commented 1 year ago

Mention @modestmc and @arewedreaming

rtmclay commented 1 year ago

There are a couple of issues that you have found. One "module purge" inside a TCL module does not do anything. It should producing an error since it is not currently supported. The other is that "module purge" in a TCL modulefile and purge() inside a Lua module needs to be supported.

These issues will get fixed. However, in the mean time, you can modify your module to get $LOADEDMODULES env. var. and unload each module in reverse order. As you will see $LOADEDMODULES is a colon separated list in load order. Please unload each one from the end of the list to the front of the list.

rtmclay commented 1 year ago

Please test Lmod 8.7.29. It supports the "purge()" function in Lua modulefiles and "module purge" in TCL modulefiles in our tests. Please test to see if it works for you.

smithsp commented 1 year ago

@rtmclay Thanks for your efforts. We are figuring out how to test this version.

rtmclay commented 1 year ago

O.K. to close this issue?

smithsp commented 1 year ago

We are testing the new release this week. It has not slipped by us. Thanks for checking.

ModestMC commented 1 year ago

I can't speak to the error raising aspect, but I can confirm that purge() now works correctly for us with lua modulefiles.