@@ -364,6 +364,14 @@ def comment(self, msg):
364364 """Return given string formatted as a comment."""
365365 raise NotImplementedError
366366
367+ def check_version (self , minimal_version_maj , minimal_version_min ):
368+ """
369+ Check the minimal version of the modules tool in the module file
370+ :param minimal_version_maj: the major version to check
371+ :param minimal_version_min: the minor version to check
372+ """
373+ raise NotImplementedError
374+
367375 def conditional_statement (self , conditions , body , negative = False , else_body = None , indent = True ,
368376 cond_or = False , cond_tmpl = None ):
369377 """
@@ -520,6 +528,16 @@ def _generate_extension_list(self):
520528
521529 return extensions
522530
531+ def _generate_extensions_list (self ):
532+ """
533+ Generate a list of all extensions in name/version format
534+ """
535+ exts_list = self .app .cfg ['exts_list' ]
536+ # the format is extension_name/extension_version
537+ exts_ver_list = sorted (['%s/%s' % (ext [0 ], ext [1 ]) for ext in exts_list ], key = str .lower )
538+
539+ return exts_ver_list
540+
523541 def _generate_help_text (self ):
524542 """
525543 Generate syntax-independent help text used for `module help`.
@@ -738,7 +756,7 @@ def get_description(self, conflict=True):
738756 # - 'conflict Compiler/GCC/4.8.2/OpenMPI' for 'Compiler/GCC/4.8.2/OpenMPI/1.6.4'
739757 lines .extend (['' , "conflict %s" % os .path .dirname (self .app .short_mod_name )])
740758
741- whatis_lines = ["module-whatis {%s}" % re .sub ('([{}\[\]])' , r'\\\1' , l ) for l in self ._generate_whatis_lines ()]
759+ whatis_lines = ["module-whatis {%s}" % re .sub (r '([{}\[\]])' , r'\\\1' , l ) for l in self ._generate_whatis_lines ()]
742760 txt += '\n ' .join (['' ] + lines + ['' ]) % {
743761 'name' : self .app .name ,
744762 'version' : self .app .version ,
@@ -1017,6 +1035,18 @@ def __init__(self, *args, **kwargs):
10171035 if self .modules_tool .version and LooseVersion (self .modules_tool .version ) >= LooseVersion ('7.7.38' ):
10181036 self .DOT_MODULERC = '.modulerc.lua'
10191037
1038+ def check_version (self , minimal_version_maj , minimal_version_min ):
1039+ """
1040+ Check the minimal version of the moduletool in the module file
1041+ :param minimal_version_maj: the major version to check
1042+ :param minimal_version_min: the minor version to check
1043+ """
1044+ lmod_version_check_expr = 'convertToCanonical(LmodVersion()) > convertToCanonical("%(ver_maj)s.%(ver_min)s")'
1045+ return lmod_version_check_expr % {
1046+ 'ver_maj' : minimal_version_maj ,
1047+ 'ver_min' : minimal_version_min ,
1048+ }
1049+
10201050 def check_group (self , group , error_msg = None ):
10211051 """
10221052 Generate a check of the software group and the current user, and refuse to load the module if the user don't
@@ -1129,6 +1159,14 @@ def get_description(self, conflict=True):
11291159 for line in self ._generate_whatis_lines ():
11301160 whatis_lines .append ("whatis(%s%s%s)" % (self .START_STR , self .check_str (line ), self .END_STR ))
11311161
1162+ extensions_list = self ._generate_extensions_list ()
1163+
1164+ if extensions_list :
1165+ extensions_stmt = 'extensions(%s)' % ', ' .join (['"%s"' % x for x in extensions_list ])
1166+ # put this behind a Lmod version check as 'extensions' is only supported since Lmod 8.2.0,
1167+ # see https://lmod.readthedocs.io/en/latest/330_extensions.html#module-extensions
1168+ lines .extend (['' , self .conditional_statement (self .check_version ("8" , "2" ), extensions_stmt )])
1169+
11321170 txt += '\n ' .join (['' ] + lines + ['' ]) % {
11331171 'name' : self .app .name ,
11341172 'version' : self .app .version ,
0 commit comments