Skip to content

Commit

Permalink
Simplify and fix module description generators
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Micket committed Apr 6, 2024
1 parent f1a5776 commit 9b45800
Showing 1 changed file with 15 additions and 38 deletions.
53 changes: 15 additions & 38 deletions easybuild/tools/module_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -816,20 +816,19 @@ def get_description(self, conflict=True):
"""
Generate a description.
"""
txt = '\n'.join([
lines = [
"proc ModulesHelp { } {",
" puts stderr {%s" % re.sub(r'([{}\[\]])', r'\\\1', self._generate_help_text()),
" }",
'}',
'',
])

lines = [
'%(whatis_lines)s',
'',
"set root %(installdir)s",
]

lines.extend([
"module-whatis {%s}" % re.sub(r'([{}\[\]])', r'\\\1', line)
for line in self._generate_whatis_lines()
])

if self.app.cfg['moduleloadnoconflict']:
cond_unload = self.conditional_statement(self.is_loaded('%(name)s'), "module unload %(name)s")
lines.extend([
Expand All @@ -845,18 +844,9 @@ def get_description(self, conflict=True):
# - 'conflict Compiler/GCC/4.8.2/OpenMPI' for 'Compiler/GCC/4.8.2/OpenMPI/1.6.4'
lines.extend(['', "conflict %s" % os.path.dirname(self.app.short_mod_name)])

whatis_lines = [
"module-whatis {%s}" % re.sub(r'([{}\[\]])', r'\\\1', line)
for line in self._generate_whatis_lines()
]
txt += '\n'.join([''] + lines + ['']) % {
'name': self.app.name,
'version': self.app.version,
'whatis_lines': '\n'.join(whatis_lines),
'installdir': self.app.installdir,
}
lines.extend(['', "set root %(installdir)s"])

return txt
return '\n'.join([''] + lines + [''])

def getenv_cmd(self, envvar, default=None):
"""
Expand Down Expand Up @@ -1261,29 +1251,24 @@ def get_description(self, conflict=True):
"""
Generate a description.
"""
txt = '\n'.join([
lines = [
'help(%s%s' % (self.START_STR, self.check_str(self._generate_help_text())),
'%s)' % self.END_STR,
'',
])

lines = [
"%(whatis_lines)s",
'',
'local root = "%(installdir)s"',
]

for line in self._generate_whatis_lines():
lines.append("whatis(%s%s%s)" % (self.START_STR, self.check_str(line), self.END_STR))

lines.extend(['', 'local root = "%(installdir)s"'])

if self.app.cfg['moduleloadnoconflict']:
self.log.info("Nothing to do to ensure no conflicts can occur on load when using Lua modules files/Lmod")

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

whatis_lines = []
for line in self._generate_whatis_lines():
whatis_lines.append("whatis(%s%s%s)" % (self.START_STR, self.check_str(line), self.END_STR))

if build_option('module_extensions'):
extensions_list = self._generate_extensions_list()

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

txt += '\n'.join([''] + lines + ['']) % {
'name': self.app.name,
'version': self.app.version,
'whatis_lines': '\n'.join(whatis_lines),
'installdir': self.app.installdir,
'homepage': self.app.cfg['homepage'],
}

return txt
return '\n'.join([''] + lines + [''])

def getenv_cmd(self, envvar, default=None):
"""
Expand Down

0 comments on commit 9b45800

Please sign in to comment.