Skip to content

Commit

Permalink
Skip module.tcl in the symlinks
Browse files Browse the repository at this point in the history
This is done by symlinking `<software>/<version>` itself to
`<namespace>/<software>/<version>/module.tcl`.
For the directory of the wrapper scripts to be correctly found, the
symlink has to be resolved, but TCL's `file normalize` won't normalise
the filename. So, we need to use `file readlink` instead, but only on
real symlinks because it raises an error.
  • Loading branch information
muffato committed Mar 20, 2022
1 parent 2ea12ac commit f469cb7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
9 changes: 7 additions & 2 deletions shpc/main/modules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,20 @@ def create_symlink(self, module_dir):
symlink_path = self.get_symlink_path(module_dir)
if os.path.exists(symlink_path):
os.unlink(symlink_path)
logger.info("Creating link %s -> %s" %(module_dir, symlink_path))
symlink_dir = os.path.dirname(symlink_path)

# If the parent directory doesn't exist, make it
if not os.path.exists(symlink_dir):
utils.mkdirp([symlink_dir])

if self.module_extension == "lua":
symlink_target = module_dir
else:
symlink_target = os.path.join(module_dir, self.modulefile)
logger.info("Creating link %s -> %s" % (symlink_target, symlink_path))

# Create the symbolic link!
os.symlink(module_dir, symlink_path)
os.symlink(symlink_target, symlink_path)

# Create .version
self.write_version_file(os.path.dirname(symlink_path))
Expand Down
4 changes: 2 additions & 2 deletions shpc/main/modules/templates/docker.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ set helpcommand "This module is a {{ docker }} container wrapper for {{ name }}
{% if labels %}{% for key, value in labels.items() %}set {{ key }} "{{ value }}"
{% endfor %}{% endif %}

# directory containing this modulefile (dynamically defined)
set moduleDir "[file dirname ${ModulesCurrentModulefile}]"
# directory containing this modulefile, once symlinks resolved (dynamically defined)
set moduleDir [file dirname [expr { [string equal [file type ${ModulesCurrentModulefile}] "link"] ? [file readlink ${ModulesCurrentModulefile}] : ${ModulesCurrentModulefile} }]]

# conflict with modules with the same alias name
conflict {{ parsed_name.tool }}
Expand Down
4 changes: 2 additions & 2 deletions shpc/main/modules/templates/singularity.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ set helpcommand "This module is a singularity container wrapper for {{ name }} v
{% if labels %}{% for key, value in labels.items() %}set {{ key }} "{{ value }}"
{% endfor %}{% endif %}

# directory containing this modulefile (dynamically defined)
set moduleDir "[file dirname ${ModulesCurrentModulefile}]"
# directory containing this modulefile, once symlinks resolved (dynamically defined)
set moduleDir [file dirname [expr { [string equal [file type ${ModulesCurrentModulefile}] "link"] ? [file readlink ${ModulesCurrentModulefile}] : ${ModulesCurrentModulefile} }]]

# conflict with modules with the same alias name
conflict {{ parsed_name.tool }}
Expand Down

0 comments on commit f469cb7

Please sign in to comment.