Skip to content
Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and **Merged pull requests**. Critical items to know are:
The versions coincide with releases on pip. Only major versions will be released as tags on Github.

## [0.0.x](https://github.com/singularityhub/singularity-hpc/tree/main) (0.0.x)
- Adding in version_naming feature (0.1.31)
- Fix `module-info shell` Tcl test for Lmod<=8.7.55 (0.1.30)
- Allow import of LooseVersion from packaging (bug) (0.1.29)
- use quay.io api to list tags since does not conform to oci (0.1.28)
Expand Down
12 changes: 10 additions & 2 deletions shpc/main/modules/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,10 @@ def install(
module.load_override_file()

# Create the module and container directory
utils.mkdirp([module.module_dir, module.container_dir])
if self.settings.version_naming:
utils.mkdirp([os.path.dirname(module.module_dir), module.container_dir])
else:
utils.mkdirp([module.module_dir, module.container_dir])

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

# Get the template based on the module and container type
template = self.template.load(self.templatefile)
module_path = os.path.join(module.module_dir, self.modulefile)
if self.settings.version_naming:
module_path = os.path.join(
os.path.dirname(module.module_dir), name.split(":")[1]
)
else:
module_path = os.path.join(module.module_dir, self.modulefile)

# Install the container
# This could be simplified to take the module
Expand Down
1 change: 1 addition & 0 deletions shpc/main/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@
"wrapper_shell": {"type": "string", "enum": shells},
"module_sys": {"type": "string", "enum": ["lmod", "tcl", None]},
"container_features": container_features,
"version_naming": {"type": "boolean"},
}

settings = {
Expand Down
4 changes: 4 additions & 0 deletions shpc/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ module_name: '{{ parsed_name.tool }}'
# first_installed: use the first installed
default_version: module_sys

#Experimental version naming tag so that modulefile is changed to version number . Default value is false. Issue number 26
version_naming: false

# store containers separately from module files
# It's recommended to do this for faster loading
container_base: $root_dir/containers
Expand Down Expand Up @@ -68,6 +71,7 @@ singularity_shell: /bin/sh
podman_shell: /bin/sh
docker_shell: /bin/sh


# shell for test.sh file
test_shell: /bin/bash

Expand Down
100 changes: 100 additions & 0 deletions shpc/tests/test_version_naming.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#!/usr/bin/python

# Copyright (C) 2021-2023 Vanessa Sochat.

# This Source Code Form is subject to the terms of the
# Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed
# with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

import io
import os
import shutil

import pytest

import shpc.main.registry as registry
import shpc.utils

from .helpers import here, init_client


@pytest.mark.parametrize(
"module_sys,module_file,container_tech",
[
("lmod", "module.lua", "singularity"),
("lmod", "module.lua", "podman"),
("tcl", "module.tcl", "singularity"),
("tcl", "module.tcl", "podman"),
("lmod", "module.lua", "singularity"),
("lmod", "module.lua", "podman"),
("tcl", "module.tcl", "singularity"),
(
"tcl",
"module.tcl",
"podman",
),
],
)
def test_version_naming_install(tmp_path, module_sys, module_file, container_tech):

"""
Test that version naming install makes module file as version number
"""
client = init_client(str(tmp_path), module_sys, container_tech)

client.settings.set("version_naming", True)
assert client.settings.get("version_naming") == True
# Install known tag
client.install("python:3.9.2-alpine")

# Modules folder is created
assert os.path.exists(client.settings.module_base)

module_dir = os.path.join(client.settings.module_base, "python")

assert os.path.exists(module_dir)

module_file = os.path.join(module_dir, "3.9.2-alpine")

assert os.path.exists(module_file)

@pytest.mark.parametrize(
"module_sys,module_file,container_tech",
[
("lmod", "module.lua", "singularity"),
("lmod", "module.lua", "podman"),
("tcl", "module.tcl", "singularity"),
("tcl", "module.tcl", "podman"),
("lmod", "module.lua", "singularity"),
("lmod", "module.lua", "podman"),
("tcl", "module.tcl", "singularity"),
(
"tcl",
"module.tcl",
"podman",
),
],
)

def test_disabled_version_naming_install(
tmp_path, module_sys, module_file, container_tech
):

"""
Test that version naming install makes module file as version number
"""
client = init_client(str(tmp_path), module_sys, container_tech)

client.settings.set("version_naming", False)
assert client.settings.get("version_naming") == False
# Install known tag
client.install("python:3.9.2-alpine")

# Modules folder is created
assert os.path.exists(client.settings.module_base)

module_dir = os.path.join(client.settings.module_base, "python", "3.9.2-alpine")

assert os.path.exists(module_dir)
module_file = os.path.join(module_dir, module_file)
assert os.path.exists(module_file)
2 changes: 1 addition & 1 deletion shpc/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
__copyright__ = "Copyright 2021-2025, Vanessa Sochat"
__license__ = "MPL 2.0"

__version__ = "0.1.30"
__version__ = "0.1.31"
AUTHOR = "Vanessa Sochat"
EMAIL = "vsoch@users.noreply.github.com"
NAME = "singularity-hpc"
Expand Down
Loading