Skip to content

Commit edecf40

Browse files
georgiastuartvsoch
andauthored
Fix views system module loading (#600)
* Fix systems modules in views * Fix .view_module(.lua) in test and name * Add CHANGELOG line and bump version * add shared function to derive view module name and expose as a variable on the view class so we do not need to redundantly define it! I also had added some redundancy to testing, so I migrated that into one shared function Signed-off-by: Georgia Stuart <[email protected]> Co-authored-by: vsoch <[email protected]>
1 parent 6b553c9 commit edecf40

File tree

7 files changed

+58
-51
lines changed

7 files changed

+58
-51
lines changed

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+
- fix views .view_module modulefile and loading (0.1.14)
1718
- support for system modules, depends on, in views and editor envars (0.1.13)
1819
- Wrappers now supported for shell/exec/run container commands (0.1.12)
1920
- Update add to return container yaml (0.1.11)

shpc/main/modules/templates/includes/load_view.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
local view_dir = string.gsub(myFileName():match("(.*[/])") or ".","/%a*/$","")
22
local view_name = string.gsub(view_dir,".*/","")
3-
local view_module = '.view_' .. view_name
3+
local view_module = '.view_module'
44
local view_modulefile = view_dir .. '/' .. view_module .. '.lua'
55

66
if isFile(view_modulefile) then

shpc/main/modules/templates/includes/load_view.tcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
set view_dir "[file dirname [file dirname ${ModulesCurrentModulefile}] ]"
22
set view_name "[file tail ${view_dir}]"
3-
set view_module ".view_${view_name}"
3+
set view_module ".view_module"
44
set view_modulefile "${view_dir}/${view_module}"
55

66
if {[file exists ${view_modulefile}]} {

shpc/main/modules/templates/view_module.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
--
44

55
{% for module in system_modules %}
6-
module load("{{ module }}"){% endfor %}{% for depends in depends_on %}
6+
load("{{ module }}"){% endfor %}{% for depends in depends_on %}
77
depends_on("{{ depends }}"){% endfor %}

shpc/main/modules/views.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@
1919
supported_view_variables = {"system_modules": [], "depends_on": []}
2020

2121

22+
# Shared functions
23+
def get_view_module_path(extension):
24+
"""
25+
Get a view module file name based on an extension
26+
"""
27+
modulefile_extension = ".lua" if extension == "lua" else ""
28+
return ".view_module%s" % modulefile_extension
29+
30+
2231
class ViewModule:
2332
"""
2433
A ViewModule is a .view_module written to the base of a view.
@@ -39,13 +48,20 @@ def write(self, view_dir, view_config):
3948
if not os.path.exists(view_dir):
4049
return
4150
template = self.template.load("view_module.%s" % self.module_extension)
42-
view_module_file = os.path.join(view_dir, ".view_module")
51+
52+
# Assemble the .view_module.<extension> full path
53+
view_module_file = os.path.join(
54+
view_dir, get_view_module_path(self.module_extension)
55+
)
4356
out = template.render(
4457
system_modules=view_config["view"].get("system_modules", []),
4558
depends_on=view_config["view"].get("depends_on", []),
4659
)
4760
utils.write_file(view_module_file, out)
48-
logger.info("Wrote updated .view_module: %s" % view_module_file)
61+
logger.info(
62+
"Wrote updated .view_module.%s: %s"
63+
% (self.module_extension, view_module_file)
64+
)
4965

5066

5167
class ViewsHandler:
@@ -292,6 +308,13 @@ def path(self):
292308
"""
293309
return os.path.join(self.settings.views_base, self.name)
294310

311+
@property
312+
def module_path(self):
313+
"""
314+
Path to view module, with needed extension.
315+
"""
316+
return os.path.join(self.path, get_view_module_path(self.module_extension))
317+
295318
def reload(self):
296319
"""
297320
Reload the view's config (given a change)

shpc/tests/test_views.py

Lines changed: 28 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -108,36 +108,10 @@ def test_views(tmp_path, module_sys, module_file, container_tech, remote):
108108
)
109109

110110
# Before adding any attributes, this file should not exist
111-
view_module = os.path.join(view.path, ".view_module")
112-
assert not os.path.exists(view_module)
111+
assert not os.path.exists(view.module_path)
113112

114-
# Try adding valid attributes
115-
for attribute, check_content in [
116-
["system_modules", "module"],
117-
["depends_on", "depends"],
118-
]:
119-
assert not view._config["view"][attribute]
120-
view_handler.add_variable(view_name, attribute, "openmpi")
121-
assert os.path.exists(view_module)
122-
123-
# Make sure we have openmpi in the content
124-
content = utils.read_file(view_module)
125-
assert "openmpi" in content and check_content in content
126-
127-
# Reload the view config file
128-
view.reload()
129-
assert "openmpi" in view._config["view"][attribute]
130-
131-
# We can't add unknown variables
132-
with pytest.raises(SystemExit):
133-
view_handler.add_variable(view_name, attribute.replace("_", "-"), [1, 2, 3])
134-
135-
# Try removing now
136-
view_handler.remove_variable(view_name, attribute, "openmpi")
137-
view.reload()
138-
assert not view._config["view"][attribute]
139-
content = utils.read_file(view_module)
140-
assert "openmpi" not in content and check_content not in content
113+
# Shared function to check view and handler
114+
check_view(view, view_handler)
141115

142116
# Ensure we can uninstall
143117
view_handler.delete(view_name, force=True)
@@ -185,38 +159,47 @@ def test_view_components(tmp_path, module_sys, module_file, container_tech, remo
185159

186160
# Before adding any attributes, this file should not exist
187161
view = client.views[view_name]
188-
view_module = os.path.join(view.path, ".view_module")
189-
assert not os.path.exists(view_module)
162+
assert not os.path.exists(view.module_path)
163+
164+
check_view(view, view_handler)
165+
166+
# Ensure we can uninstall
167+
view_handler.delete(view_name, force=True)
168+
assert not os.path.exists(view.path)
190169

170+
171+
def check_view(view, view_handler):
172+
"""
173+
Shared function for checking content of view.
174+
"""
191175
# Try adding valid attributes
192176
for attribute, check_content in [
193-
["system_modules", "module"],
177+
["system_modules", None],
194178
["depends_on", "depends"],
195179
]:
196180
assert not view._config["view"][attribute]
197-
view_handler.add_variable(view_name, attribute, "openmpi")
198-
assert os.path.exists(view_module)
181+
view_handler.add_variable(view.name, attribute, "openmpi")
182+
assert os.path.exists(view.module_path)
199183

200184
# Make sure we have openmpi in the content
201-
content = utils.read_file(view_module)
202-
print(content)
203-
assert "openmpi" in content and check_content in content
185+
content = utils.read_file(view.module_path)
186+
assert "openmpi" in content
187+
if check_content:
188+
assert check_content in content
204189

205190
# Reload the view config file
206191
view.reload()
207192
assert "openmpi" in view._config["view"][attribute]
208193

209194
# We can't add unknown variables
210195
with pytest.raises(SystemExit):
211-
view_handler.add_variable(view_name, attribute.replace("_", "-"), [1, 2, 3])
196+
view_handler.add_variable(view.name, attribute.replace("_", "-"), [1, 2, 3])
212197

213198
# Try removing now
214-
view_handler.remove_variable(view_name, attribute, "openmpi")
199+
view_handler.remove_variable(view.name, attribute, "openmpi")
215200
view.reload()
216201
assert not view._config["view"][attribute]
217-
content = utils.read_file(view_module)
218-
assert "openmpi" not in content and check_content not in content
219-
220-
# Ensure we can uninstall
221-
view_handler.delete(view_name, force=True)
222-
assert not os.path.exists(view.path)
202+
content = utils.read_file(view.module_path)
203+
assert "openmpi" not in content
204+
if check_content:
205+
assert check_content not in content

shpc/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
__copyright__ = "Copyright 2021-2022, Vanessa Sochat"
33
__license__ = "MPL 2.0"
44

5-
__version__ = "0.1.13"
5+
__version__ = "0.1.14"
66
AUTHOR = "Vanessa Sochat"
77
88
NAME = "singularity-hpc"

0 commit comments

Comments
 (0)