loki.jit_build.jit
Utilities to facilitate Just-in-Time compilation for testing purposes.
Functions
|
Clean test directory based on JIT'ed source file. |
|
Generate, Just-in-Time compile and load a given item for interactive execution. |
|
Generate, just-in-time compile and load a set of items into a library and import dynamically into the Python runtime. |
|
Execute |
- jit_compile(source, filepath=None, objname=None)
Generate, Just-in-Time compile and load a given item for interactive execution.
- Parameters:
source (
SourcefileorModuleorSubroutine) – The item to compile and loadfilepath (str or
Path, optional) – Path of the source file to write (default: hashed name ingettempdir())objname (str, optional) – Return a specific object (module or subroutine) in
source
- jit_compile_lib(sources, path, name, wrap=None, builder=None)
Generate, just-in-time compile and load a set of items into a library and import dynamically into the Python runtime.
- Parameters:
source (list) – Source items or filepaths to compile and add to lib
path (str or
Path) – Basepath for on-the-fly creation of source filesname (str) – Name of created lib
wrap (list, optional) – File names to pass to
f90wrap. Defaults to list of source files.builder (
Builder, optional) – Builder object to use for lib compilation and linking
- run_isolated(target, *args, multiprocessing_context='fork', exit_after_result=False, **kwargs)
Execute
targetin a short-lived subprocess and return its result.This is useful for tests that JIT-compile and import native extension modules, where unloading all linked Fortran/Python wrapper state from the current process is not reliable. Python exceptions raised by
targetare re-raised asRuntimeErrorwith the child traceback; native crashes or explicit non-zero exits are reported via the child process exit code.- Parameters:
target (callable) – The callable to execute in the child process.
multiprocessing_context (str, optional) – Multiprocessing start method. Use
'fork'for low-overhead isolation when inherited process state is safe, or'spawn'when the child must start without inherited native extension modules.exit_after_result (bool, optional) – Exit the child process immediately after reporting the result, bypassing interpreter shutdown. This is useful for native extension tests where finalizers can crash after successful execution.
- clean_test(filepath)
Clean test directory based on JIT’ed source file.