Skip to content

Commit 7af1150

Browse files
AmjadhpcAmjadUEA
andauthored
Introducing version_naming property that makes modulefile as version … (#679)
* Introducing version_naming property that makes modulefile as version number * Ran black to format the indenting * Adding version_naming test * Adding in pytest.mark.parametize for disable install testing * removing the private class variable forgot to cleanup * Bump to 0.1.31 --------- Co-authored-by: amjadhpc <[email protected]>
1 parent 3678a82 commit 7af1150

File tree

6 files changed

+117
-3
lines changed

6 files changed

+117
-3
lines changed

CHANGELOG.md

+1
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+
- Adding in version_naming feature (0.1.31)
1718
- Fix `module-info shell` Tcl test for Lmod<=8.7.55 (0.1.30)
1819
- Allow import of LooseVersion from packaging (bug) (0.1.29)
1920
- use quay.io api to list tags since does not conform to oci (0.1.28)

shpc/main/modules/base.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,10 @@ def install(
458458
module.load_override_file()
459459

460460
# Create the module and container directory
461-
utils.mkdirp([module.module_dir, module.container_dir])
461+
if self.settings.version_naming:
462+
utils.mkdirp([os.path.dirname(module.module_dir), module.container_dir])
463+
else:
464+
utils.mkdirp([module.module_dir, module.container_dir])
462465

463466
# Add a .version file to indicate the level of versioning
464467
self.versionfile.write(
@@ -470,7 +473,12 @@ def install(
470473

471474
# Get the template based on the module and container type
472475
template = self.template.load(self.templatefile)
473-
module_path = os.path.join(module.module_dir, self.modulefile)
476+
if self.settings.version_naming:
477+
module_path = os.path.join(
478+
os.path.dirname(module.module_dir), name.split(":")[1]
479+
)
480+
else:
481+
module_path = os.path.join(module.module_dir, self.modulefile)
474482

475483
# Install the container
476484
# This could be simplified to take the module

shpc/main/schemas.py

+1
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@
170170
"wrapper_shell": {"type": "string", "enum": shells},
171171
"module_sys": {"type": "string", "enum": ["lmod", "tcl", None]},
172172
"container_features": container_features,
173+
"version_naming": {"type": "boolean"},
173174
}
174175

175176
settings = {

shpc/settings.yml

+4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ module_name: '{{ parsed_name.tool }}'
3838
# first_installed: use the first installed
3939
default_version: module_sys
4040

41+
#Experimental version naming tag so that modulefile is changed to version number . Default value is false. Issue number 26
42+
version_naming: false
43+
4144
# store containers separately from module files
4245
# It's recommended to do this for faster loading
4346
container_base: $root_dir/containers
@@ -68,6 +71,7 @@ singularity_shell: /bin/sh
6871
podman_shell: /bin/sh
6972
docker_shell: /bin/sh
7073

74+
7175
# shell for test.sh file
7276
test_shell: /bin/bash
7377

shpc/tests/test_version_naming.py

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#!/usr/bin/python
2+
3+
# Copyright (C) 2021-2023 Vanessa Sochat.
4+
5+
# This Source Code Form is subject to the terms of the
6+
# Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed
7+
# with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
8+
9+
import io
10+
import os
11+
import shutil
12+
13+
import pytest
14+
15+
import shpc.main.registry as registry
16+
import shpc.utils
17+
18+
from .helpers import here, init_client
19+
20+
21+
@pytest.mark.parametrize(
22+
"module_sys,module_file,container_tech",
23+
[
24+
("lmod", "module.lua", "singularity"),
25+
("lmod", "module.lua", "podman"),
26+
("tcl", "module.tcl", "singularity"),
27+
("tcl", "module.tcl", "podman"),
28+
("lmod", "module.lua", "singularity"),
29+
("lmod", "module.lua", "podman"),
30+
("tcl", "module.tcl", "singularity"),
31+
(
32+
"tcl",
33+
"module.tcl",
34+
"podman",
35+
),
36+
],
37+
)
38+
def test_version_naming_install(tmp_path, module_sys, module_file, container_tech):
39+
40+
"""
41+
Test that version naming install makes module file as version number
42+
"""
43+
client = init_client(str(tmp_path), module_sys, container_tech)
44+
45+
client.settings.set("version_naming", True)
46+
assert client.settings.get("version_naming") == True
47+
# Install known tag
48+
client.install("python:3.9.2-alpine")
49+
50+
# Modules folder is created
51+
assert os.path.exists(client.settings.module_base)
52+
53+
module_dir = os.path.join(client.settings.module_base, "python")
54+
55+
assert os.path.exists(module_dir)
56+
57+
module_file = os.path.join(module_dir, "3.9.2-alpine")
58+
59+
assert os.path.exists(module_file)
60+
61+
@pytest.mark.parametrize(
62+
"module_sys,module_file,container_tech",
63+
[
64+
("lmod", "module.lua", "singularity"),
65+
("lmod", "module.lua", "podman"),
66+
("tcl", "module.tcl", "singularity"),
67+
("tcl", "module.tcl", "podman"),
68+
("lmod", "module.lua", "singularity"),
69+
("lmod", "module.lua", "podman"),
70+
("tcl", "module.tcl", "singularity"),
71+
(
72+
"tcl",
73+
"module.tcl",
74+
"podman",
75+
),
76+
],
77+
)
78+
79+
def test_disabled_version_naming_install(
80+
tmp_path, module_sys, module_file, container_tech
81+
):
82+
83+
"""
84+
Test that version naming install makes module file as version number
85+
"""
86+
client = init_client(str(tmp_path), module_sys, container_tech)
87+
88+
client.settings.set("version_naming", False)
89+
assert client.settings.get("version_naming") == False
90+
# Install known tag
91+
client.install("python:3.9.2-alpine")
92+
93+
# Modules folder is created
94+
assert os.path.exists(client.settings.module_base)
95+
96+
module_dir = os.path.join(client.settings.module_base, "python", "3.9.2-alpine")
97+
98+
assert os.path.exists(module_dir)
99+
module_file = os.path.join(module_dir, module_file)
100+
assert os.path.exists(module_file)

shpc/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
__copyright__ = "Copyright 2021-2025, Vanessa Sochat"
33
__license__ = "MPL 2.0"
44

5-
__version__ = "0.1.30"
5+
__version__ = "0.1.31"
66
AUTHOR = "Vanessa Sochat"
77
88
NAME = "singularity-hpc"

0 commit comments

Comments
 (0)