Skip to content

Commit

Permalink
Symlink to module.lua when possible
Browse files Browse the repository at this point in the history
which is when default_version==True (default_version==False can't be
made to work with symlinks).
  • Loading branch information
muffato committed Mar 20, 2022
1 parent f469cb7 commit c671723
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
13 changes: 11 additions & 2 deletions shpc/main/modules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,15 @@ def get_symlink_path(self, module_dir):
"""
if not self.settings.symlink_base:
return
return os.path.join(self.settings.symlink_base, *module_dir.split(os.sep)[-2:])

symlink_base_name = os.path.join(self.settings.symlink_base, *module_dir.split(os.sep)[-2:])

# With Lmod and default_version==True, the symlinks points to module.lua itself,
# and its name needs to end with `.lua` too
if self.module_extension == "lua" and self.settings.default_version == True:
return symlink_base_name + ".lua"
else:
return symlink_base_name

def create_symlink(self, module_dir):
"""
Expand All @@ -193,7 +201,8 @@ def create_symlink(self, module_dir):
if not os.path.exists(symlink_dir):
utils.mkdirp([symlink_dir])

if self.module_extension == "lua":
# With Lmod, default_version==False can't be made to work with symlinks at the module.lua level
if self.module_extension == "lua" and self.settings.default_version == False:
symlink_target = module_dir
else:
symlink_target = os.path.join(module_dir, self.modulefile)
Expand Down
4 changes: 2 additions & 2 deletions shpc/main/modules/templates/docker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ For each of the above, you can export:
if not os.getenv("PODMAN_OPTS") then setenv ("PODMAN_OPTS", "") end
if not os.getenv("PODMAN_COMMAND_OPTS") then setenv ("PODMAN_COMMAND_OPTS", "") end

-- directory containing this modulefile (dynamically defined)
local moduleDir = myFileName():match("(.*[/])") or "."
-- directory containing this modulefile, once symlinks resolved (dynamically defined)
local moduleDir = subprocess("realpath " .. myFileName()):match("(.*[/])") or "."

-- interactive shell to any container, plus exec for aliases
local containerPath = '{{ image }}'
Expand Down
4 changes: 2 additions & 2 deletions shpc/main/modules/templates/singularity.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ For each of the above, you can export:

{% if settings.singularity_module %}load("{{ settings.singularity_module }}"){% endif %}

-- directory containing this modulefile (dynamically defined)
local moduleDir = myFileName():match("(.*[/])") or "."
-- directory containing this modulefile, once symlinks resolved (dynamically defined)
local moduleDir = subprocess("realpath " .. myFileName()):match("(.*[/])") or "."

-- singularity environment variable to set shell
setenv("SINGULARITY_SHELL", "{{ settings.singularity_shell }}")
Expand Down

0 comments on commit c671723

Please sign in to comment.