curryer.utils¶
Generic utilities (not specific to the SPICE library).
@author: Brandon Stone
Attributes¶
Functions¶
|
Wrapper to track the performance of functions or class methods. |
|
Format the performance results from track_performance. |
|
Execute commands in a subprocess. |
|
Enable logging to the console and optionally to a file. |
Module Contents¶
- curryer.utils.logger¶
- curryer.utils.track_performance(func: Callable, storage: dict = None)¶
Wrapper to track the performance of functions or class methods.
- Parameters:
func (callable) – Function to track.
storage (dict, optional) – Dictionary to store the metrics in, otherwise it is assumed that func is part of an instance and metrics will be added to the _performance_metrics attribute.
- Returns:
Wrapped function or class method.
- Return type:
callable
- curryer.utils.format_performance(obj, indent: str = '\t', p: int = 3, ascending=None)¶
Format the performance results from track_performance.
- Parameters:
obj (instance or dict) – Dictionary of the performance metrics or instance with the automated _performance_metrics attribute.
indent (str, optional) – String used for indentation. Default is tab.
p (int, optional) – Decimal precision in timing format. Default is 3, aka milliseconds.
ascending (None or bool, optional) – Order results by insert (None), ascending (True), or descending (False). Default is None.
- Returns:
Formatted performance results.
- Return type:
str
- curryer.utils.capture_subprocess(cmd, timeout=3600, capture_output=False)¶
Execute commands in a subprocess.
- Parameters:
cmd (list of str) – Command arguments to execute.
timeout (int, optional) – Number of seconds to wait before timing out. Default=3600 (1hr)
capture_output (bool, optional) – Option to return the stdout text. Default=False
- Returns:
The stdout text is returned if `capture_output`=True.
- Return type:
None or str
- curryer.utils.enable_logging(log_level=logging.DEBUG, log_file: bool | str | pathlib.Path = False, extra_loggers: list[str] = None)¶
Enable logging to the console and optionally to a file.
- Parameters:
log_level (int) – A logging log level.
log_file (bool or str or Path, optional) – Option to enable logging to a file. If true or a directory the filename will be auto-generated. If true, the file will be saved to the current working directory. Otherwise, the supplied file will be used.
extra_loggers (List[str], optional) – Collection of additional loggers to enable at DEBUG level.