-
Notifications
You must be signed in to change notification settings - Fork 203
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
add support for implementing pre- and post-step hooks #2343
Merged
Merged
Changes from 4 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
a389a3b
first implementation of support for pre- and post-step hooks
boegel 5523e85
only load implementation of hooks once
boegel 1bc7dce
add tests for load_hooks and find_hook functions
boegel e5477ac
add test for --hooks option
boegel 7536b40
Merge branch 'develop' into hooks
boegel ff9bd88
rename 'find_hook' to 'find_step_hook' and add more generic 'find_hoo…
boegel 6a7dc72
implement run_hook function, collapse find_hook and find_step_hook in…
boegel e4496e3
use run_hook to run pre- and post-step hooks
boegel 88a50e2
also implement start and end hooks
boegel 779ebfe
fix order in import statement
boegel a9f55d4
flesh out hook support into easybuild.tools.hooks module
boegel 3e4b326
no need to resolve --hooks path or make it a build option, but do mak…
boegel fb82002
verify defined hooks and produce error if unknown hooks are defined
boegel 43dfdcf
fix remarks by @damianam
boegel 7f336e1
make verify_hook issue suggestions for close matching hook names in e…
boegel c5d093e
add support for --avail-hooks
boegel 3194f4f
add 'hooks' as last named argument to 'build_and_install_software' fu…
boegel ae50e00
add constants for 'pre_', 'post_' and '_hook' prefix/suffix of hook n…
boegel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ | |
import fileinput | ||
import glob | ||
import hashlib | ||
import imp | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No longer needed |
||
import os | ||
import re | ||
import shutil | ||
|
@@ -1651,3 +1652,50 @@ def diff_files(path1, path2): | |
file1_lines = ['%s\n' % l for l in read_file(path1).split('\n')] | ||
file2_lines = ['%s\n' % l for l in read_file(path2).split('\n')] | ||
return ''.join(difflib.unified_diff(file1_lines, file2_lines, fromfile=path1, tofile=path2)) | ||
|
||
|
||
def load_hooks(hooks_path): | ||
"""Load defined hooks (if any).""" | ||
hooks = [] | ||
if hooks_path: | ||
(hooks_dir, hooks_filename) = os.path.split(hooks_path) | ||
(hooks_mod_name, hooks_file_ext) = os.path.splitext(hooks_filename) | ||
if hooks_file_ext == '.py': | ||
_log.info("Importing hooks implementation from %s...", hooks_path) | ||
(fh, pathname, descr) = imp.find_module(hooks_mod_name, [hooks_dir]) | ||
try: | ||
# import module that defines hooks, and collect all functions of which name ends with '_hook' | ||
imported_hooks = imp.load_module(hooks_mod_name, fh, pathname, descr) | ||
for attr in dir(imported_hooks): | ||
if attr.endswith('_hook'): | ||
hook = getattr(imported_hooks, attr) | ||
if callable(hook): | ||
hooks.append(hook) | ||
else: | ||
_log.debug("Skipping non-callable attribute '%s' when loading hooks", attr) | ||
_log.debug("Found hooks: %s", hooks) | ||
except ImportError as err: | ||
raise EasyBuildError("Failed to import hooks implementation from %s: %s", hooks_path, err) | ||
else: | ||
raise EasyBuildError("Provided path for hooks implementation should be location of a Python file (*.py)") | ||
else: | ||
_log.info("No location for hooks implementation provided, no hooks defined") | ||
|
||
return hooks | ||
|
||
|
||
def find_hook(step_name, known_hooks, pre_hook=True): | ||
""" | ||
Find pre- or post-hook for specified step. | ||
|
||
:param step_name: name of the step that hook relates to | ||
:param pre_hook: True to search for pre-step hook, False to search for post-step hook | ||
""" | ||
res = None | ||
hook_name = ('post_', 'pre_')[pre_hook] + step_name + '_hook' | ||
for hook in known_hooks: | ||
if hook.__name__ == hook_name: | ||
res = hook | ||
break | ||
|
||
return res |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling
run_hook
whenhooks = None
would work, but seems odd.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather have the logic for dealing with not having any hooks defined in
run_hook
rather than having to copy-paste the logic to check whether any hooks are defined in multiple places.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems reasonable.