From c67172367dbcdb3b7a27e5bc3c23269c26c97e39 Mon Sep 17 00:00:00 2001 From: Matthieu Muffato Date: Sat, 19 Mar 2022 17:53:42 +0000 Subject: [PATCH] Symlink to module.lua when possible which is when default_version==True (default_version==False can't be made to work with symlinks). --- shpc/main/modules/__init__.py | 13 +++++++++++-- shpc/main/modules/templates/docker.lua | 4 ++-- shpc/main/modules/templates/singularity.lua | 4 ++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/shpc/main/modules/__init__.py b/shpc/main/modules/__init__.py index f9b3be16b..b0581afc7 100644 --- a/shpc/main/modules/__init__.py +++ b/shpc/main/modules/__init__.py @@ -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): """ @@ -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) diff --git a/shpc/main/modules/templates/docker.lua b/shpc/main/modules/templates/docker.lua index 780311678..a4b6b50a8 100644 --- a/shpc/main/modules/templates/docker.lua +++ b/shpc/main/modules/templates/docker.lua @@ -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 }}' diff --git a/shpc/main/modules/templates/singularity.lua b/shpc/main/modules/templates/singularity.lua index f50c7ec4f..84bbe1f6c 100644 --- a/shpc/main/modules/templates/singularity.lua +++ b/shpc/main/modules/templates/singularity.lua @@ -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 }}")