|
69 | 69 | from easybuild.tools.github import add_pr_labels, install_github_token, list_prs, merge_pr, new_branch_github, new_pr |
70 | 70 | from easybuild.tools.github import new_pr_from_branch |
71 | 71 | from easybuild.tools.github import sync_branch_with_develop, sync_pr_with_develop, update_branch, update_pr |
72 | | -from easybuild.tools.hooks import START, END, load_hooks, run_hook |
| 72 | +from easybuild.tools.hooks import BUILD_AND_INSTALL_LOOP, PRE_PREF, POST_PREF, START, END, CANCEL, FAIL |
| 73 | +from easybuild.tools.hooks import load_hooks, run_hook |
73 | 74 | from easybuild.tools.modules import modules_tool |
74 | 75 | from easybuild.tools.options import opts_dict_to_eb_opts, set_up_configuration, use_color |
75 | 76 | from easybuild.tools.output import COLOR_GREEN, COLOR_RED, STATUS_BAR, colorize, print_checks, rich_live_cm |
@@ -545,8 +546,10 @@ def process_eb_args(eb_args, eb_go, cfg_settings, modtool, testing, init_session |
545 | 546 | exit_on_failure = not (options.dump_test_report or options.upload_test_report) |
546 | 547 |
|
547 | 548 | with rich_live_cm(): |
| 549 | + run_hook(PRE_PREF + BUILD_AND_INSTALL_LOOP, hooks, args=[ordered_ecs]) |
548 | 550 | ecs_with_res = build_and_install_software(ordered_ecs, init_session_state, |
549 | 551 | exit_on_failure=exit_on_failure) |
| 552 | + run_hook(POST_PREF + BUILD_AND_INSTALL_LOOP, hooks, args=[ecs_with_res]) |
550 | 553 | else: |
551 | 554 | ecs_with_res = [(ec, {}) for ec in ordered_ecs] |
552 | 555 |
|
@@ -577,30 +580,20 @@ def process_eb_args(eb_args, eb_go, cfg_settings, modtool, testing, init_session |
577 | 580 | return overall_success |
578 | 581 |
|
579 | 582 |
|
580 | | -def main(args=None, logfile=None, do_build=None, testing=False, modtool=None): |
| 583 | +def main(args=None, logfile=None, do_build=None, testing=False, modtool=None, prepared_cfg_data=None): |
581 | 584 | """ |
582 | 585 | Main function: parse command line options, and act accordingly. |
583 | 586 | :param args: command line arguments to use |
584 | 587 | :param logfile: log file to use |
585 | 588 | :param do_build: whether or not to actually perform the build |
586 | 589 | :param testing: enable testing mode |
| 590 | + :param prepared_cfg_data: prepared configuration data for main function, as returned by prepare_main (or None) |
587 | 591 | """ |
| 592 | + if prepared_cfg_data is None or any([args, logfile, testing]): |
| 593 | + init_session_state, eb_go, cfg_settings = prepare_main(args=args, logfile=logfile, testing=testing) |
| 594 | + else: |
| 595 | + init_session_state, eb_go, cfg_settings = prepared_cfg_data |
588 | 596 |
|
589 | | - register_lock_cleanup_signal_handlers() |
590 | | - |
591 | | - # if $CDPATH is set, unset it, it'll only cause trouble... |
592 | | - # see https://github.com/easybuilders/easybuild-framework/issues/2944 |
593 | | - if 'CDPATH' in os.environ: |
594 | | - del os.environ['CDPATH'] |
595 | | - |
596 | | - # When EB is run via `exec` the special bash variable $_ is not set |
597 | | - # So emulate this here to allow (module) scripts depending on that to work |
598 | | - if '_' not in os.environ: |
599 | | - os.environ['_'] = sys.executable |
600 | | - |
601 | | - # purposely session state very early, to avoid modules loaded by EasyBuild meddling in |
602 | | - init_session_state = session_state() |
603 | | - eb_go, cfg_settings = set_up_configuration(args=args, logfile=logfile, testing=testing) |
604 | 597 | options, orig_paths = eb_go.options, eb_go.args |
605 | 598 |
|
606 | 599 | if 'python2' not in build_option('silence_deprecation_warnings'): |
@@ -729,10 +722,41 @@ def main(args=None, logfile=None, do_build=None, testing=False, modtool=None): |
729 | 722 | cleanup(logfile, eb_tmpdir, testing, silent=False) |
730 | 723 |
|
731 | 724 |
|
| 725 | +def prepare_main(args=None, logfile=None, testing=None): |
| 726 | + """ |
| 727 | + Prepare for calling main function by setting up the EasyBuild configuration |
| 728 | + :param args: command line arguments to take into account when parsing the EasyBuild configuration settings |
| 729 | + :param logfile: log file to use |
| 730 | + :param testing: enable testing mode |
| 731 | + :return: 3-tuple with initial session state data, EasyBuildOptions instance, and tuple with configuration settings |
| 732 | + """ |
| 733 | + register_lock_cleanup_signal_handlers() |
| 734 | + |
| 735 | + # if $CDPATH is set, unset it, it'll only cause trouble... |
| 736 | + # see https://github.com/easybuilders/easybuild-framework/issues/2944 |
| 737 | + if 'CDPATH' in os.environ: |
| 738 | + del os.environ['CDPATH'] |
| 739 | + |
| 740 | + # When EB is run via `exec` the special bash variable $_ is not set |
| 741 | + # So emulate this here to allow (module) scripts depending on that to work |
| 742 | + if '_' not in os.environ: |
| 743 | + os.environ['_'] = sys.executable |
| 744 | + |
| 745 | + # purposely session state very early, to avoid modules loaded by EasyBuild meddling in |
| 746 | + init_session_state = session_state() |
| 747 | + eb_go, cfg_settings = set_up_configuration(args=args, logfile=logfile, testing=testing) |
| 748 | + |
| 749 | + return init_session_state, eb_go, cfg_settings |
| 750 | + |
| 751 | + |
732 | 752 | if __name__ == "__main__": |
| 753 | + init_session_state, eb_go, cfg_settings = prepare_main() |
| 754 | + hooks = load_hooks(eb_go.options.hooks) |
733 | 755 | try: |
734 | | - main() |
| 756 | + main(prepared_cfg_data=(init_session_state, eb_go, cfg_settings)) |
735 | 757 | except EasyBuildError as err: |
| 758 | + run_hook(FAIL, hooks, args=[err]) |
736 | 759 | print_error(err.msg) |
737 | 760 | except KeyboardInterrupt as err: |
| 761 | + run_hook(CANCEL, hooks, args=[err]) |
738 | 762 | print_error("Cancelled by user: %s" % err) |
0 commit comments