Skip to content

Commit 00b99bd

Browse files
committed
Move back to member method to avoid cyclic imports
1 parent a48c6bb commit 00b99bd

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

easybuild/framework/easyblock.py

+16-15
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,6 @@
120120
_log = fancylogger.getLogger('easyblock')
121121

122122

123-
def make_extension_string(app, name_version_sep='-', ext_sep=', ', sort=True):
124-
"""
125-
Generate a string with a list of extensions of the given EasyBlock instance.
126-
127-
The name and version are separated by name_version_sep and each extension is separated by ext_sep
128-
"""
129-
exts_list = (name_version_sep.join(ext) for ext in app.make_extension_list())
130-
if sort:
131-
exts_list = sorted(exts_list, key=str.lower)
132-
return ext_sep.join(exts_list)
133-
134-
135123
class EasyBlock(object):
136124
"""Generic support for building and installing software, base class for actual easyblocks."""
137125

@@ -1531,7 +1519,7 @@ def make_module_extra_extensions(self):
15311519

15321520
# set environment variable that specifies list of extensions
15331521
# We need only name and version, so don't resolve templates
1534-
exts_list = make_extension_string(self, ext_sep=',', sort=False)
1522+
exts_list = self.make_extension_string(ext_sep=',', sort=False)
15351523
env_var_name = 'EBEXTSLIST' + convert_name(self.name, upper=True)
15361524
lines.append(self.module_generator.set_environment(env_var_name, exts_list))
15371525

@@ -1812,6 +1800,18 @@ def load_dependency_modules(self):
18121800
# EXTENSIONS UTILITY FUNCTIONS
18131801
#
18141802

1803+
def make_extension_string(self, name_version_sep='-', ext_sep=', ', sort=True):
1804+
"""
1805+
Generate a string with a list of extensions returned by make_extension_list.
1806+
1807+
The name and version are separated by name_version_sep and each extension is separated by ext_sep.
1808+
For customization of extensions the make_extension_list method should be used.
1809+
"""
1810+
exts_list = (name_version_sep.join(ext) for ext in self.make_extension_list())
1811+
if sort:
1812+
exts_list = sorted(exts_list, key=str.lower)
1813+
return ext_sep.join(exts_list)
1814+
18151815
def make_extension_list(self):
18161816
"""
18171817
Return a list of extension names and their versions included in this installation
@@ -1823,8 +1823,9 @@ def make_extension_list(self):
18231823
# As name can be a templated value we must resolve templates
18241824
if hasattr(self, '_make_extension_list'):
18251825
self.log.nosupport("self._make_extension_list is replaced by self.make_extension_list", '5.0')
1826-
if hasattr(self, 'make_extension_string'):
1827-
self.log.nosupport("self.make_extension_string was removed in favor of the free function", '5.0')
1826+
if type(self).make_extension_string != EasyBlock.make_extension_string:
1827+
self.log.nosupport("self.make_extension_string should not be overridden", '5.0')
1828+
18281829
exts_list = []
18291830
for ext in self.cfg.get_ref('exts_list'):
18301831
if isinstance(ext, str):

easybuild/tools/module_generator.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
from textwrap import wrap
4646

4747
from easybuild.base import fancylogger
48-
from easybuild.framework.easyblock import make_extension_string
4948
from easybuild.tools.build_log import EasyBuildError, print_warning
5049
from easybuild.tools.config import build_option, get_module_syntax, install_path
5150
from easybuild.tools.filetools import convert_name, mkdir, read_file, remove_file, resolve_path, symlink, write_file
@@ -657,7 +656,7 @@ def _generate_help_text(self):
657656
lines.extend(self._generate_section("Compatible modules", compatible_modules_txt))
658657

659658
# Extensions (if any)
660-
extensions = make_extension_string(self.app)
659+
extensions = self.app.make_extension_string()
661660
lines.extend(self._generate_section("Included extensions", '\n'.join(wrap(extensions, 78))))
662661

663662
return '\n'.join(lines)
@@ -714,7 +713,7 @@ def _generate_whatis_lines(self):
714713
if multi_deps:
715714
whatis.append("Compatible modules: %s" % ', '.join(multi_deps))
716715

717-
extensions = make_extension_string(self.app)
716+
extensions = self.app.make_extension_string()
718717
if extensions:
719718
whatis.append("Extensions: %s" % extensions)
720719

@@ -1270,9 +1269,9 @@ def get_description(self, conflict=True):
12701269
elif conflict:
12711270
# conflict on 'name' part of module name (excluding version part at the end)
12721271
lines.extend(['', 'conflict("%s")' % os.path.dirname(self.app.short_mod_name)])
1273-
extensions_list = self.app.make_extension_list()
1272+
extensions_list = self.app.make_extension_string(name_version_sep='/', ext_sep=',')
12741273
if extensions_list:
1275-
extensions_stmt = 'extensions("%s")' % ','.join(['/'.join(x) for x in extensions_list])
1274+
extensions_stmt = 'extensions("%s")' % extensions_list
12761275
# put this behind a Lmod version check as 'extensions' is only (well) supported since Lmod 8.2.8,
12771276
# see https://lmod.readthedocs.io/en/latest/330_extensions.html#module-extensions and
12781277
# https://github.com/TACC/Lmod/issues/428

0 commit comments

Comments
 (0)