context
This module manages shared runtime context across different parts of an application. It tracks session-specific data, caller identification (e.g., Jupyter, scripts), and allows for runtime library path registration. It supports reproducibility, logging, and analysis by preserving contextual metadata during execution.
- get_caller()[source]
Identify the current session or script origin. Returns a string like ‘jupyter_session:<id>’ or ‘script:<filename>’.
- Return type:
str
Retrieve the shared data dictionary associated with the current context.
- Returns:
A dictionary that holds all shared data for the current context/session.
- Return type:
dict
- register_libs_path(libs_dir)[source]
Add a local library directory to Python’s sys.path if it exists.
Useful for loading local modules dynamically without installing them system-wide.
- Parameters:
libs_dir (str) – The path to the directory containing the libraries.
- Raises:
ValueError – If the given path does not point to a valid directory.
- Return type:
None
Set the shared data dictionary for the current context.
- Parameters:
data (dict) – The context data to store. If not a dictionary, only ‘logid’ is saved.
logid (str) – A string identifier used for logging or session tracking.
- Returns:
The updated context dictionary.
- Return type:
dict