Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename unclear *run* methods to *install_extension* + rename install_extensions to install_all_extensions #4400

Merged
merged 29 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
0700f2d
rename Extension.run() method to install_extension()
lexming Dec 12, 2023
202c78e
rename ExtensionEasyblock.run() to install_extension()"
lexming Dec 12, 2023
d9cb50e
rename Extension.prerun() method to preinstall_extension()
lexming Dec 12, 2023
f85564b
rename Extension.postrun() method to postinstall_extension()
lexming Dec 12, 2023
23446df
rename Extension.run_async() method to install_extension_async()
lexming Dec 12, 2023
845d110
rename EasyBlock.install_extensions() to install_all_extensions()
lexming Dec 12, 2023
6b00163
separate prefix in preinstall_extension and postinstall_extension met…
lexming Dec 13, 2023
9d92bce
add deprecated extension install methods with deprecation warnings
lexming Dec 13, 2023
21f1d58
fix log.deprecated statements for renamed methods for installing exte…
boegel Jan 3, 2024
274503c
Merge branch '5.0.x' into extension-run
lexming Jan 25, 2024
e91fa29
continue to execute deprecated run() methods still found on custom ea…
lexming Jan 26, 2024
cf5c10b
add Extension.install_extension_substep wrapping all substeps to dete…
lexming Jan 26, 2024
7cd6732
Extension.install_extension_substep returns outcome of install extens…
lexming Jan 26, 2024
6074b55
remove duplicate deprecation warning on Extension.run_async()
lexming Jan 26, 2024
0bee2ec
fix EasyBlock in deprecation log message produced by EasyBlock.instal…
boegel Feb 7, 2024
e384579
enhance install_extension_substep to support passing down (named) arg…
boegel Feb 7, 2024
c2298d7
Merge pull request #3 from boegel/extension-run
lexming Feb 7, 2024
1662278
fix variable rename in install_extension_substep error message
lexming Feb 7, 2024
44b2b9f
compare deprecated method qualified name instead of hashes in Extensi…
lexming Feb 8, 2024
4ded825
fix check on deprecated methods on base Extension class
lexming Feb 8, 2024
b3092bf
add unit tests for Extension.install_extension_substep
lexming Feb 18, 2024
6a1b113
fix code formatting in test easyblocks based on DummyExtension
lexming Feb 18, 2024
d31d260
also test pre- and post- install extension subteps with Extension.ins…
lexming Feb 18, 2024
fe7190a
use raw string formatting in EasyBlockTest.test_extensions_step_depre…
lexming Feb 18, 2024
3b98a92
update docs tests with easyblocks based on DummyExtension
lexming Feb 19, 2024
02810a9
replace hardcoded paths with topdir template
lexming Feb 19, 2024
1ed4efe
disable linter checks on text blocks in the docs tests
lexming Feb 19, 2024
dd2da21
update options tests with easyblocks based on DummyExtension
lexming Feb 19, 2024
8f876a5
Merge branch '5.0.x' into extension-run
boegel Mar 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 18 additions & 10 deletions easybuild/framework/easyblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -1857,7 +1857,15 @@ def skip_extensions_parallel(self, exts_filter):

self.ext_instances = retained_ext_instances

def install_extensions(self, install=True):
def install_extensions(self, *args, **kwargs):
"""[DEPRECATED] Install extensions."""
self.log.deprecated(
"EasyBlock.install_extensions() is deprecated, use EasyBlock.install_all_extensions() instead.",
'6.0',
)
self.install_all_extensions(*args, **kwargs)

def install_all_extensions(self, install=True):
"""
Install extensions.

Expand Down Expand Up @@ -1921,15 +1929,15 @@ def install_extensions_sequential(self, install=True):
ext.toolchain.prepare(onlymod=self.cfg['onlytcmod'], silent=True, loadmod=False,
rpath_filter_dirs=self.rpath_filter_dirs)

# real work
# actual installation of the extension
if install:
try:
ext.prerun()
ext.install_extension_substep("pre_install_extension")
with self.module_generator.start_module_creation():
txt = ext.run()
txt = ext.install_extension_substep("install_extension")
if txt:
self.module_extra_extensions += txt
ext.postrun()
ext.install_extension_substep("post_install_extension")
finally:
if not self.dry_run:
ext_duration = datetime.now() - start_time
Expand Down Expand Up @@ -1996,7 +2004,7 @@ def update_exts_progress_bar_helper(running_exts, progress_size):
self.log.info(f"Installation of extension {ext.name} completed!")
# run post-install method for extension from same working dir as installation of extension
cwd = change_dir(res.work_dir)
ext.postrun()
ext.install_extension_substep("post_install_extension")
change_dir(cwd)
running_exts.remove(ext)
installed_ext_names.append(ext.name)
Expand Down Expand Up @@ -2070,8 +2078,8 @@ def update_exts_progress_bar_helper(running_exts, progress_size):
ext.toolchain.prepare(onlymod=self.cfg['onlytcmod'], silent=True, loadmod=False,
rpath_filter_dirs=self.rpath_filter_dirs)
if install:
ext.prerun()
ext.async_cmd_task = ext.run_async(thread_pool)
ext.install_extension_substep("pre_install_extension")
ext.async_cmd_task = ext.install_extension_substep("install_extension_async", thread_pool)
running_exts.append(ext)
self.log.info(f"Started installation of extension {ext.name} in the background...")
update_exts_progress_bar_helper(running_exts, 0)
Expand Down Expand Up @@ -2904,7 +2912,7 @@ def extensions_step(self, fetch=False, install=True):
if self.skip:
self.skip_extensions()

self.install_extensions(install=install)
self.install_all_extensions(install=install)

# cleanup (unload fake module, remove fake module dir)
if fake_mod_data:
Expand Down Expand Up @@ -4475,7 +4483,7 @@ def copy_easyblocks_for_reprod(easyblock_instances, reprod_dir):
for easyblock_class in inspect.getmro(type(easyblock_instance)):
easyblock_path = inspect.getsourcefile(easyblock_class)
# if we reach EasyBlock, Extension or ExtensionEasyBlock class, we are done
# (Extension and ExtensionEasyblock are hardcoded to avoid a cyclical import)
# (Extension and ExtensionEasyBlock are hardcoded to avoid a cyclical import)
if easyblock_class.__name__ in [EasyBlock.__name__, 'Extension', 'ExtensionEasyBlock']:
break
else:
Expand Down
70 changes: 70 additions & 0 deletions easybuild/framework/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,29 +167,99 @@ def version(self):
return self.ext.get('version', None)

def prerun(self):
"""
[DEPRECATED][6.0] Stuff to do before installing a extension.
"""
# Deprecation warning triggered by Extension.install_extension_substep()
self.pre_install_extension()

def pre_install_extension(self):
"""
Stuff to do before installing a extension.
"""
pass

def run(self, *args, **kwargs):
"""
[DEPRECATED][6.0] Actual installation of an extension.
"""
# Deprecation warning triggered by Extension.install_extension_substep()
self.install_extension(*args, **kwargs)

def install_extension(self, *args, **kwargs):
"""
Actual installation of an extension.
"""
pass

def run_async(self, *args, **kwargs):
"""
[DEPRECATED][6.0] Asynchronous installation of an extension.
"""
# Deprecation warning triggered by Extension.install_extension_substep()
self.install_extension_async(*args, **kwargs)

def install_extension_async(self, *args, **kwargs):
"""
Asynchronous installation of an extension.
"""
raise NotImplementedError

def postrun(self):
"""
[DEPRECATED][6.0] Stuff to do after installing a extension.
"""
# Deprecation warning triggered by Extension.install_extension_substep()
self.post_install_extension()

def post_install_extension(self):
"""
Stuff to do after installing a extension.
"""
self.master.run_post_install_commands(commands=self.cfg.get('postinstallcmds', []))

def install_extension_substep(self, substep, *args, **kwargs):
"""
Carry out extension installation substep allowing use of deprecated
methods on those extensions using an older EasyBlock
"""
substeps_mapping = {
'pre_install_extension': 'prerun',
'install_extension': 'run',
'install_extension_async': 'run_async',
'post_install_extension': 'postrun',
}

deprecated_substep = substeps_mapping.get(substep)
if deprecated_substep is None:
raise EasyBuildError("Unknown extension installation substep: %s", substep)

try:
substep_method = getattr(self, deprecated_substep)
except AttributeError:
log_msg = f"EasyBlock does not implement deprecated method '{deprecated_substep}' "
log_msg += f"for installation substep {substep}"
self.log.debug(log_msg)
substep_method = getattr(self, substep)
else:
# Qualified method name contains class defining the method (PEP 3155)
substep_method_name = substep_method.__qualname__
self.log.debug(f"Found deprecated method in EasyBlock: {substep_method_name}")

base_method_name = f"Extension.{deprecated_substep}"
if substep_method_name == base_method_name:
# No custom method in child Easyblock, deprecated method is defined by base Extension class
# Switch to non-deprecated substep method
substep_method = getattr(self, substep)
else:
# Custom deprecated method used by child Easyblock
self.log.deprecated(
f"{substep_method_name}() is deprecated, use {substep}() instead.",
"6.0",
)

return substep_method(*args, **kwargs)

@property
def required_deps(self):
"""Return list of required dependencies for this extension."""
Expand Down
2 changes: 1 addition & 1 deletion easybuild/framework/extensioneasyblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def _set_start_dir(self):
self.log.warning(warn_msg)
print_warning(warn_msg, silent=build_option('silent'))

def run(self, unpack_src=False):
def install_extension(self, unpack_src=False):
"""Common operations for extensions: unpacking sources, patching, ..."""

# unpack file if desired
Expand Down