Skip to content

Commit

Permalink
Move back to member method to avoid cyclic imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Flamefire committed Oct 23, 2024
1 parent a48c6bb commit bebf90a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
31 changes: 16 additions & 15 deletions easybuild/framework/easyblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,6 @@
_log = fancylogger.getLogger('easyblock')


def make_extension_string(app, name_version_sep='-', ext_sep=', ', sort=True):
"""
Generate a string with a list of extensions of the given EasyBlock instance.
The name and version are separated by name_version_sep and each extension is separated by ext_sep
"""
exts_list = (name_version_sep.join(ext) for ext in app.make_extension_list())
if sort:
exts_list = sorted(exts_list, key=str.lower)
return ext_sep.join(exts_list)


class EasyBlock(object):
"""Generic support for building and installing software, base class for actual easyblocks."""

Expand Down Expand Up @@ -1531,7 +1519,7 @@ def make_module_extra_extensions(self):

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

Expand Down Expand Up @@ -1812,6 +1800,18 @@ def load_dependency_modules(self):
# EXTENSIONS UTILITY FUNCTIONS
#

def make_extension_string(self, name_version_sep='-', ext_sep=', ', sort=True):
"""
Generate a string with a list of extensions returned by make_extension_list.
The name and version are separated by name_version_sep and each extension is separated by ext_sep.
For customization of extensions the make_extension_list method should be used.
"""
exts_list = (name_version_sep.join(ext) for ext in self.make_extension_list())
if sort:
exts_list = sorted(exts_list, key=str.lower)
return ext_sep.join(exts_list)

def make_extension_list(self):
"""
Return a list of extension names and their versions included in this installation
Expand All @@ -1823,8 +1823,9 @@ def make_extension_list(self):
# As name can be a templated value we must resolve templates
if hasattr(self, '_make_extension_list'):
self.log.nosupport("self._make_extension_list is replaced by self.make_extension_list", '5.0')
if hasattr(self, 'make_extension_string'):
self.log.nosupport("self.make_extension_string was removed in favor of the free function", '5.0')
if type(self).make_extension_string != EasyBlock.make_extension_string:
self.log.nosupport("self.make_extension_string should not be overridden", '5.0')

exts_list = []
for ext in self.cfg.get_ref('exts_list'):
if isinstance(ext, str):
Expand Down
5 changes: 2 additions & 3 deletions easybuild/tools/module_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
from textwrap import wrap

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

# Extensions (if any)
extensions = make_extension_string(self.app)
extensions = self.app.make_extension_string()
lines.extend(self._generate_section("Included extensions", '\n'.join(wrap(extensions, 78))))

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

extensions = make_extension_string(self.app)
extensions = self.app.make_extension_string()
if extensions:
whatis.append("Extensions: %s" % extensions)

Expand Down

0 comments on commit bebf90a

Please sign in to comment.