moduleluahpcspack

Source a shell script when loading a modulefile in lua


I am writing some .lua files for loading modules in a HPC system.

Basically the application I want to make a module is Spack, and it has an autocompletion shell script for sourcing it in linux with:

source /apps/spack/share/spack/setup-env.sh

I want to run this command in my .lua file when loading the spack module into the system, I can't get it to work by doing the following:

os.execute('source /apps/spack/share/spack/setup-env.sh')

Note that the module loads fine and I can use spack without any problems, I just want the autocompletion feature to work when loading the module.

Any help is welcome, thank you!


Solution

  • I have managed to do it with this function.

    execute{cmd="source /apps/spack/share/spack/setup-env.sh", modeA={"load"}}
    

    Basically it does the source as expected after the module load and it works perfectly.

    Just for the record:

    I was using this command before but only the autocomplete command worked in spack and when I did a spack load I got the error that I needed to do the source to get the environment variables right.

    source_sh("bash", "/apps/spack/share/spack/spack/setup-env.sh")
    

    And the error:

    ==> Error: spack load requires Spack's shell support. 
    To set up shell support, run the command below for your shell. 
    For bash/zsh/sh: . /apps/spack/share/spack/
    

    Thanks for all the help provided from everyone :)