peremir
peremir

Reputation: 1

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!

Upvotes: 0

Views: 310

Answers (2)

peremir
peremir

Reputation: 1

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 :)

Upvotes: 0

AndyT
AndyT

Reputation: 541

Lmod supports sourcing of shell scripts via the source_sh function:

https://lmod.readthedocs.io/en/latest/260_sh_to_modulefile.html#using-source-sh

Upvotes: 0

Related Questions