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

Implement hooks for failure scenarios: crash_hook, cancel_hook, fail_hook #4315

Merged
merged 34 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
ccc6ef7
Add cancel and fail hooks
Jul 25, 2023
3eee395
Run hooks in main with arguments
XavierCS-dev Jul 25, 2023
a80ac7f
Init eb_go with parse_options()
XavierCS-dev Jul 25, 2023
2ef4cf6
Merge with main
Aug 7, 2023
014fd42
Add crash hook
XavierCS-dev Aug 8, 2023
1a589dc
Remove trailing whitespace
XavierCS-dev Aug 8, 2023
565c113
Revert file permissions
XavierCS-dev Aug 8, 2023
852e4c9
Updated unit tests expected output with new hooks
XavierCS-dev Aug 8, 2023
3d61e4a
Insert missing commas
XavierCS-dev Aug 8, 2023
b880856
Replace spaces with tabs to match expected options output
XavierCS-dev Aug 8, 2023
716701d
Merge branch 'develop' into 4302_failure_hooks
XavierCS-dev Aug 8, 2023
b5ec611
Shorten long line of imports
XavierCS-dev Aug 8, 2023
f296dc5
formatting of imports
branfosj Aug 9, 2023
0e751c9
Reorder failure hooks to be in alphabetical order
XavierCS-dev Aug 10, 2023
6cb5eda
Merge branch '4302_failure_hooks' of https://github.com/XavierCS-dev/…
XavierCS-dev Aug 10, 2023
8a474bb
Fix output tests for hook order
XavierCS-dev Aug 10, 2023
ec87c86
Alter refactor to define variables
XavierCS-dev Aug 10, 2023
2e8b80f
Comment out line overriding variables defined elsewhere
XavierCS-dev Aug 10, 2023
81e5344
Fix style issues
XavierCS-dev Aug 10, 2023
0ac9daf
Update main docstring and add prepare_main docstring
XavierCS-dev Aug 10, 2023
22b4429
Remove uncessary comment
XavierCS-dev Aug 10, 2023
1751fe3
Only set eb_go and cfg_settings if not already
XavierCS-dev Aug 10, 2023
c4be4ca
Move setup config to occure before os.environ is checked
XavierCS-dev Aug 10, 2023
58623de
Change pprepare_main description
XavierCS-dev Aug 10, 2023
8148fb5
Add return to prepare_main docstring
XavierCS-dev Aug 10, 2023
f2f6b45
Move eb_go and cfg_settings to end of parameters to prevent breaking …
XavierCS-dev Aug 10, 2023
56def6b
Add init_session_state and hooks to prepare_main returns
XavierCS-dev Aug 10, 2023
d8a34e4
Update docstrings to match new parameters and return values
XavierCS-dev Aug 10, 2023
fcc6fee
Add or condition to ensure test passes
XavierCS-dev Aug 10, 2023
4146b46
Separate check on hooks to be None
XavierCS-dev Aug 11, 2023
d9b15f0
Improve clarity when checking for None values in main
XavierCS-dev Aug 11, 2023
7d31bb8
clean up passing of data produced by prepare_main into main
boegel Aug 11, 2023
20c99cd
Remove unnecessary parameter descriptions
XavierCS-dev Aug 11, 2023
746b992
Merge pull request #1 from boegel/4302_failure_hooks
XavierCS-dev Aug 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions easybuild/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@
from easybuild.tools.github import add_pr_labels, install_github_token, list_prs, merge_pr, new_branch_github, new_pr
from easybuild.tools.github import new_pr_from_branch
from easybuild.tools.github import sync_branch_with_develop, sync_pr_with_develop, update_branch, update_pr
from easybuild.tools.hooks import BUILD_AND_INSTALL_LOOP, PRE_PREF, POST_PREF, START, END, load_hooks, run_hook
from easybuild.tools.hooks import BUILD_AND_INSTALL_LOOP, PRE_PREF, POST_PREF, CRASH, START, END, CANCEL, FAIL
from easybuild.tools.hooks import load_hooks, run_hook
from easybuild.tools.modules import modules_tool
from easybuild.tools.options import opts_dict_to_eb_opts, set_up_configuration, use_color
from easybuild.tools.output import COLOR_GREEN, COLOR_RED, STATUS_BAR, colorize, print_checks, rich_live_cm
Expand Down Expand Up @@ -579,9 +580,11 @@ def process_eb_args(eb_args, eb_go, cfg_settings, modtool, testing, init_session
return overall_success


def main(args=None, logfile=None, do_build=None, testing=False, modtool=None):
def main(eb_go=None, cfg_settings=None, args=None, logfile=None, do_build=None, testing=False, modtool=None):
XavierCS-dev marked this conversation as resolved.
Show resolved Hide resolved
"""
Main function: parse command line options, and act accordingly.
:param: eb_go: easybuild general options object
:param: cfg_settings: configuration settings of easybuild
:param args: command line arguments to use
:param logfile: log file to use
:param do_build: whether or not to actually perform the build
Expand All @@ -590,6 +593,9 @@ def main(args=None, logfile=None, do_build=None, testing=False, modtool=None):

register_lock_cleanup_signal_handlers()

if not all([eb_go, cfg_settings]):
eb_go, cfg_settings = set_up_configuration(args=args, logfile=logfile, testing=testing)

# if $CDPATH is set, unset it, it'll only cause trouble...
# see https://github.com/easybuilders/easybuild-framework/issues/2944
if 'CDPATH' in os.environ:
XavierCS-dev marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -602,7 +608,6 @@ def main(args=None, logfile=None, do_build=None, testing=False, modtool=None):

# purposely session state very early, to avoid modules loaded by EasyBuild meddling in
init_session_state = session_state()
XavierCS-dev marked this conversation as resolved.
Show resolved Hide resolved
XavierCS-dev marked this conversation as resolved.
Show resolved Hide resolved
eb_go, cfg_settings = set_up_configuration(args=args, logfile=logfile, testing=testing)
options, orig_paths = eb_go.options, eb_go.args

if 'python2' not in build_option('silence_deprecation_warnings'):
Expand Down Expand Up @@ -731,10 +736,29 @@ def main(args=None, logfile=None, do_build=None, testing=False, modtool=None):
cleanup(logfile, eb_tmpdir, testing, silent=False)


def prepare_main(args=None, logfile=None, testing=None):
"""
Prepare Main: Set up eb_go and consequently, cfg_settings in order to obtain the hooks,
and prevent the configuration being set up twice.
XavierCS-dev marked this conversation as resolved.
Show resolved Hide resolved
:param args: command line arguments to take into account when parsing the EasyBuild configuration settings
:param logfile: log file to use
:param testing: enable testing mode
XavierCS-dev marked this conversation as resolved.
Show resolved Hide resolved
"""
eb_go, cfg_settings = set_up_configuration(args=args, logfile=logfile, testing=testing)
return eb_go, cfg_settings


if __name__ == "__main__":
eb_go, cfg_settings = prepare_main()
hooks = load_hooks(eb_go.options.hooks)
try:
main()
main(eb_go, cfg_settings)
XavierCS-dev marked this conversation as resolved.
Show resolved Hide resolved
except EasyBuildError as err:
run_hook(FAIL, hooks, args=[err])
print_error(err.msg)
except KeyboardInterrupt as err:
run_hook(CANCEL, hooks, args=[err])
print_error("Cancelled by user: %s" % err)
except Exception as err:
run_hook(CRASH, hooks, args=[err])
print_error("Encountered an unrecoverable error: %s" % err)
7 changes: 7 additions & 0 deletions easybuild/tools/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@
MODULE_WRITE = 'module_write'
END = 'end'

CANCEL = 'cancel'
CRASH = 'crash'
XavierCS-dev marked this conversation as resolved.
Show resolved Hide resolved
FAIL = 'fail'

PRE_PREF = 'pre_'
POST_PREF = 'post_'
HOOK_SUFF = '_hook'
Expand Down Expand Up @@ -101,6 +105,9 @@
for p in [PRE_PREF, POST_PREF]] + [
POST_PREF + BUILD_AND_INSTALL_LOOP,
END,
CANCEL,
CRASH,
XavierCS-dev marked this conversation as resolved.
Show resolved Hide resolved
FAIL,
]
KNOWN_HOOKS = [h + HOOK_SUFF for h in HOOK_NAMES]

Expand Down
3 changes: 3 additions & 0 deletions test/framework/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,9 @@ def test_avail_hooks(self):
" post_testcases_hook",
" post_build_and_install_loop_hook",
" end_hook",
" cancel_hook",
" crash_hook",
" fail_hook",
'',
])
self.assertEqual(stdout, expected)
Expand Down