Skip to content

Commit

Permalink
also implement start and end hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
boegel committed Nov 18, 2017
1 parent e4496e3 commit 88a50e2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
11 changes: 8 additions & 3 deletions easybuild/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
from easybuild.framework.easyconfig.tweak import obtain_ec_for, tweak
from easybuild.tools.config import find_last_log, get_repository, get_repositorypath, build_option
from easybuild.tools.docs import list_software
from easybuild.tools.filetools import adjust_permissions, cleanup, load_hooks, write_file
from easybuild.tools.filetools import adjust_permissions, cleanup, load_hooks, run_hook, write_file
from easybuild.tools.github import check_github, find_easybuild_easyconfig, install_github_token
from easybuild.tools.github import new_pr, merge_pr, update_pr
from easybuild.tools.modules import modules_tool
Expand Down Expand Up @@ -118,6 +118,8 @@ def build_and_install_software(ecs, init_session_state, hooks=None, exit_on_fail
# e.g. via easyconfig.handle_allowed_system_deps
init_env = copy.deepcopy(os.environ)

run_hook('start', hooks)

res = []
for ec in ecs:
ec_res = {}
Expand Down Expand Up @@ -161,6 +163,8 @@ def build_and_install_software(ecs, init_session_state, hooks=None, exit_on_fail

res.append((ec, ec_res))

run_hook('end', hooks)

return res


Expand Down Expand Up @@ -460,9 +464,10 @@ def main(args=None, logfile=None, do_build=None, testing=False, modtool=None):
sys.exit(0)

# build software, will exit when errors occurs (except when testing)
hooks = load_hooks(build_option('hooks'))
exit_on_failure = not options.dump_test_report and not options.upload_test_report
if not testing or (testing and do_build):
exit_on_failure = not options.dump_test_report and not options.upload_test_report
hooks = load_hooks(build_option('hooks'))

ecs_with_res = build_and_install_software(ordered_ecs, init_session_state, hooks=hooks,
exit_on_failure=exit_on_failure)
else:
Expand Down
8 changes: 8 additions & 0 deletions test/framework/toy_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1749,6 +1749,9 @@ def test_toy_build_hooks(self):
hooks_file_txt = '\n'.join([
"import os",
'',
"def start_hook():",
" print('start hook triggered')",
'',
"def pre_configure_hook(self):",
" print('pre-configure: toy.source: %s' % os.path.exists('toy.source'))",
'',
Expand All @@ -1758,6 +1761,9 @@ def test_toy_build_hooks(self):
"def post_install_hook(self):",
" print('in post-install hook for %s v%s' % (self.name, self.version))",
" print(', '.join(sorted(os.listdir(self.installdir))))",
'',
"def end_hook():",
" print('end hook triggered, all done!')",
])
write_file(hooks_file, hooks_file_txt)

Expand All @@ -1771,10 +1777,12 @@ def test_toy_build_hooks(self):

self.assertEqual(stderr, '')
expected_output = '\n'.join([
"start hook triggered",
"pre-configure: toy.source: True",
"post-configure: toy.source: False",
"in post-install hook for toy v0.0",
"bin, lib",
"end hook triggered, all done!",
])
self.assertEqual(stdout.strip(), expected_output)

Expand Down

0 comments on commit 88a50e2

Please sign in to comment.