7. Hooks & Events

Pyke supports being easily hooked at some stages of the build process to change certain parts of the logic or the behaviour.

Basically a hook allows you to change the way a function works, without having to modify the pyke code itself.

While here in this documentation only a fraction of the functions are explained, in pyke almost all functions can be hooked and changed from the outside.

The function hooking works the same way regardless of the function being hooked or the module.

TODO:

7.1. Hookable functions

To hook a function just assign the new function you want, like:
pyke.terminal.safeprint = mysafeprint

# —————————————————————————— # Hookeable methods # # In order to hook, just assign pyke.hooks.<hookeable_method> to point to your # own method, and your own method will be executed. # # For example, you can use default methods so you only change the # behaviours you want: # # >>> orgSafePrint = pyke.terminal.safeprint # >>> def mySafeprint (msg, newline = True, error = False, mode = None): # >>> return orgSafePrint (‘HOOKED:’+msg, newline, error, mode) # >>> # >>> def myFormatJobCommand (job, node, logger): # >>> formatted = pyke.runtime.formatJob (job, node, logger) # >>> if job.isPythonFunction() and job.getCommandName() == ‘cp’: # >>> return ‘HOOKED: cp :)’ + formatted # >>> return formatted # >>> # >>> def myExecBuildFile (file, globals, locals): # >>> return pyke.runtime.execBuildFile (file, globals, locals) # # Now, referencing your hooks is as easy as: # # >>> import pyke.hooks # >>> pyke.terminal.safeprint = mySafeprint # >>> pyke.hooks.formatJob = myFormatJobCommand # >>> pyke.hooks.execbuildfile = myExecBuildFile # # —————————————————————————— cmdbrief = None # pyke.runtime.cmdbrief execJob = None # pyke.runtime.execJob formatJob = None # pyke.runtime.formatJob execbuildfile = None # pyke.runtime.execbuildfile shouldNodeBeBuilt = None # pyke.runtime.shouldNodeBeBuilt

safeprint = None # pyke.terminal.safeprint

execPythonFunction = None # pyke.sysutil.execPythonFunction execSystemCommand = None # pyke.sysutil.execSystemCommand

“”” execJob

Executes a job on given node and returns a tuple containing (exitcode, stdout, stderr). This hook might be useful to implement caches, distributing workload, ...

A dummy implementation would look like:

>>> prevExecJob = pyke.hooks.execJob
>>> def myCustomExecJob (job, node, responsive):
>>>   (exitcode, stdout, stderr) = prevExecJob (job, node, responsive)
>>>   return (exitcode, stdout, stderr)
>>>
>>> pyke.hooks.execJob = myCustomExecJob

See pyke.core.Job.execJob for details “”“

Table Of Contents

Previous topic

6.9. Working with large projects

Next topic

8. Reference for all rules

This Page