Skip to content

Commit 3170d9f

Browse files
committed
Simplify and fix module description generators
Old method needlessly involved template resolutions, duplicating the template resolving code, but only partially and would break if anything but the 4 most common templates were used.
1 parent a508adb commit 3170d9f

File tree

1 file changed

+15
-38
lines changed

1 file changed

+15
-38
lines changed

easybuild/tools/module_generator.py

+15-38
Original file line numberDiff line numberDiff line change
@@ -816,20 +816,19 @@ def get_description(self, conflict=True):
816816
"""
817817
Generate a description.
818818
"""
819-
txt = '\n'.join([
819+
lines = [
820820
"proc ModulesHelp { } {",
821821
" puts stderr {%s" % re.sub(r'([{}\[\]])', r'\\\1', self._generate_help_text()),
822822
" }",
823823
'}',
824824
'',
825-
])
826-
827-
lines = [
828-
'%(whatis_lines)s',
829-
'',
830-
"set root %(installdir)s",
831825
]
832826

827+
lines.extend([
828+
"module-whatis {%s}" % re.sub(r'([{}\[\]])', r'\\\1', line)
829+
for line in self._generate_whatis_lines()
830+
])
831+
833832
if self.app.cfg['moduleloadnoconflict']:
834833
cond_unload = self.conditional_statement(self.is_loaded('%(name)s'), "module unload %(name)s")
835834
lines.extend([
@@ -845,18 +844,9 @@ def get_description(self, conflict=True):
845844
# - 'conflict Compiler/GCC/4.8.2/OpenMPI' for 'Compiler/GCC/4.8.2/OpenMPI/1.6.4'
846845
lines.extend(['', "conflict %s" % os.path.dirname(self.app.short_mod_name)])
847846

848-
whatis_lines = [
849-
"module-whatis {%s}" % re.sub(r'([{}\[\]])', r'\\\1', line)
850-
for line in self._generate_whatis_lines()
851-
]
852-
txt += '\n'.join([''] + lines + ['']) % {
853-
'name': self.app.name,
854-
'version': self.app.version,
855-
'whatis_lines': '\n'.join(whatis_lines),
856-
'installdir': self.app.installdir,
857-
}
847+
lines.extend(['', "set root %(installdir)s"])
858848

859-
return txt
849+
return '\n'.join([''] + lines + [''])
860850

861851
def getenv_cmd(self, envvar, default=None):
862852
"""
@@ -1261,29 +1251,24 @@ def get_description(self, conflict=True):
12611251
"""
12621252
Generate a description.
12631253
"""
1264-
txt = '\n'.join([
1254+
lines = [
12651255
'help(%s%s' % (self.START_STR, self.check_str(self._generate_help_text())),
12661256
'%s)' % self.END_STR,
12671257
'',
1268-
])
1269-
1270-
lines = [
1271-
"%(whatis_lines)s",
1272-
'',
1273-
'local root = "%(installdir)s"',
12741258
]
12751259

1260+
for line in self._generate_whatis_lines():
1261+
lines.append("whatis(%s%s%s)" % (self.START_STR, self.check_str(line), self.END_STR))
1262+
1263+
lines.extend(['', 'local root = "%(installdir)s"'])
1264+
12761265
if self.app.cfg['moduleloadnoconflict']:
12771266
self.log.info("Nothing to do to ensure no conflicts can occur on load when using Lua modules files/Lmod")
12781267

12791268
elif conflict:
12801269
# conflict on 'name' part of module name (excluding version part at the end)
12811270
lines.extend(['', 'conflict("%s")' % os.path.dirname(self.app.short_mod_name)])
12821271

1283-
whatis_lines = []
1284-
for line in self._generate_whatis_lines():
1285-
whatis_lines.append("whatis(%s%s%s)" % (self.START_STR, self.check_str(line), self.END_STR))
1286-
12871272
if build_option('module_extensions'):
12881273
extensions_list = self._generate_extensions_list()
12891274

@@ -1294,15 +1279,7 @@ def get_description(self, conflict=True):
12941279
# https://github.com/TACC/Lmod/issues/428
12951280
lines.extend(['', self.conditional_statement(self.check_version("8", "2", "8"), extensions_stmt)])
12961281

1297-
txt += '\n'.join([''] + lines + ['']) % {
1298-
'name': self.app.name,
1299-
'version': self.app.version,
1300-
'whatis_lines': '\n'.join(whatis_lines),
1301-
'installdir': self.app.installdir,
1302-
'homepage': self.app.cfg['homepage'],
1303-
}
1304-
1305-
return txt
1282+
return '\n'.join([''] + lines + [''])
13061283

13071284
def getenv_cmd(self, envvar, default=None):
13081285
"""

0 commit comments

Comments
 (0)