Skip to content

Commit 21370ba

Browse files
authored
test support for custom wrapper install directory (#654)
* test support for custom wrapper install directory * cleanup wrappers too * remove extra erroneous } * set wrapper base to null * restore default wrapper bin * clean up wrappers testing logic * use wrapperDir instead of wrapper_bin for wrapper templates * update environment test and wrapper templates we have more cases than I anticipated - using a custom wrapper, the default wrapper ($root/modules), havint it unset (empty string) and then entirely disabled. * try removing quotes around moduleDir for singularity lua * clean up testing logic and wrapperDir/bin with quotes * remove erroneous $ for lua module setting * fix tcl wrapperDir to have {} and be in quotes Signed-off-by: vsoch <[email protected]>
1 parent c407e02 commit 21370ba

File tree

29 files changed

+217
-57
lines changed

29 files changed

+217
-57
lines changed

.github/dev-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
pre-commit
2-
black
2+
black==23.3.0
33
isort
44
flake8

.github/workflows/test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ jobs:
9797
printf "\n\nmodule help ============================================\n"
9898
module help python/3.9.5-alpine
9999
100+
script_path=$(which python-exec)
101+
cat $script_path
100102
set -x
101103
python-exec echo donuts >test_output
102104
cat test_output

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and **Merged pull requests**. Critical items to know are:
1414
The versions coincide with releases on pip. Only major versions will be released as tags on Github.
1515

1616
## [0.0.x](https://github.com/singularityhub/singularity-hpc/tree/main) (0.0.x)
17+
- Allow custom location for wrapper scripts (0.1.24)
1718
- Labels with newlines need additional parsing (0.1.23)
1819
- Do not write directly to output with shpc show (0.1.22)
1920
- Podman template bug (0.1.21)

docs/getting_started/user-guide.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ variable replacement. A summary table of variables is included below, and then f
176176
* - module_base
177177
- The install directory for modules
178178
- $root_dir/modules
179+
* - wrapper_base
180+
- The install directory for script wrappers
181+
- $root_dir/modules
179182
* - container_base
180183
- Where to install containers. If not defined, they are installed in "containers" in the install root
181184
- $root_dir/containers
@@ -347,6 +350,20 @@ Singularity Registry HPC uses this simple directory structure to ensure
347350
a unique namespace.
348351

349352

353+
Wrapper Base
354+
------------
355+
356+
By default, if you do not set a wrapper script base they will be stored alongside
357+
modules. However, for large installations, we recommend you customize this path
358+
to be somewhere else. This way, you can avoid warnings from your module software
359+
about having too many files.
360+
361+
.. code-block:: console
362+
363+
# an absolute path
364+
$ shpc config set wrapper_base /opt/lmod/wrappers
365+
366+
350367
Container Images Folder
351368
-----------------------
352369

shpc/main/container/base.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,16 @@ def add(self, sif, module_name, modulefile, template, **kwargs):
6666
"""
6767
logger.warning("Add is not supported for %s" % self)
6868

69-
def add_environment(self, module_dir, envars, environment_file):
69+
def add_environment(self, env_dir, envars, environment_file):
7070
"""
7171
Given one or more environment variables in a dictionary, write to file.
72+
73+
The environment file goes in the wrapper directory, which can default
74+
to the module directory if the value uses the default or is unset.
7275
"""
7376
# Podman envars are written directly to the module file
7477
out = Template(shpc.main.templates.environment_file).render(envars=envars)
75-
env_file = os.path.join(module_dir, environment_file)
78+
env_file = os.path.join(env_dir, environment_file)
7679
shpc.utils.write_file(env_file, out)
7780

7881
def delete(self, image):

shpc/main/container/docker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def install(self, module_path, template, module, features=None):
218218
if self.settings.wrapper_scripts["enabled"] is True:
219219
wrapper_scripts = shpc.main.wrappers.generate(
220220
aliases=aliases,
221-
module_dir=module.module_dir,
221+
wrapper_dir=module.wrapper_dir,
222222
features=features,
223223
container=self,
224224
image=module.container_path,

shpc/main/container/singularity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,9 @@ def install(self, module_path, template, module, features=None):
211211
if self.settings.wrapper_scripts["enabled"] is True:
212212
wrapper_scripts = shpc.main.wrappers.generate(
213213
aliases=aliases,
214-
module_dir=module.module_dir,
215214
features=features,
216215
container=self,
216+
wrapper_dir=module.wrapper_dir,
217217
image=module.container_path,
218218
config=module.config,
219219
)

shpc/main/container/update/versions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def _cmp(self, other):
155155
this_version = self.version[i]
156156
other_version = other.version[i]
157157

158-
if type(this_version) != type(other_version):
158+
if type(this_version) is not type(other_version):
159159
continue
160160

161161
if this_version == other_version:

shpc/main/modules/base.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,14 @@ def uninstall(self, name, force=False):
130130
"$module_base/%s" % module.name,
131131
)
132132

133+
# If we have a wrapper
134+
if module.wrapper_dir != module.module_dir:
135+
self._uninstall(
136+
module.wrapper_dir,
137+
self.settings.wrapper_base,
138+
"$wrapper_base/%s" % module.name,
139+
)
140+
133141
# If uninstalling the entire module, clean up symbolic links in all views
134142
for view_name in views_with_module:
135143
self.views[view_name].uninstall(module.module_dir)

shpc/main/modules/module.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def add_environment(self):
3636
Write the environment to the module directory.
3737
"""
3838
self.container.add_environment(
39-
self.module_dir,
39+
self.wrapper_dir,
4040
envars=self.config.get_envars(),
4141
environment_file=self.settings.environment_file,
4242
)
@@ -165,6 +165,14 @@ def uri(self):
165165
"""
166166
return self._uri
167167

168+
@property
169+
def wrapper_dir(self):
170+
"""
171+
Full path to the wrapper directory
172+
"""
173+
wrapper_dir = self.settings.wrapper_base or self.settings.module_base
174+
return os.path.join(wrapper_dir, self.module_basepath)
175+
168176
@property
169177
def module_dir(self):
170178
"""

0 commit comments

Comments
 (0)