General Utilities

This module contains various utility functions.

easylink.utilities.general_utils.handle_exceptions(func, exceptions_logger, with_debugger)[source]

Wraps a function to handle exceptions by logging and optionally dropping into a debugger.

Return type:

Callable

Parameters:
  • func (Callable) – The wrapped function that is executed and monitored for exceptions.

  • exceptions_logger (Any) – The logging object used to log exceptions that occur during function execution.

  • with_debugger (bool) – Whether or not to drop into an interactive debugger upon encountering an exception.

Returns:

A wrapped version of func that includes the exception handling logic.

Notes

Exceptions BdbQuit and KeyboardInterrupt are re-raised _without_ logging to allow for normal debugger and program exit behaviors.

easylink.utilities.general_utils.configure_logging_to_terminal(verbose)[source]

Configures logging output to the terminal with optional verbosity levels.

Return type:

None

Parameters:

verbose (int) – An integer indicating the verbosity level of the logging output. Higher values produce more detailed logging information.

Notes

This function clears any default logging configuration before applying the new settings.

easylink.utilities.general_utils._add_logging_sink(sink, verbose, colorize=False, serialize=False)[source]

Adds a logging sink to the global process logger.

Return type:

None

Parameters:
  • sink (TextIO) – The output stream to which log messages will be directed, e.g. sys.stdout.

  • verbose (int) – Verbosity of the logger. The log level is set to INFO if 0 and DEBUG otherwise.

  • colorize (bool) – Whether to use the colorization options from loguru.

  • serialize (bool) – Whether the logs should be converted to JSON before they’re dumped to the logging sink.

easylink.utilities.general_utils.exit_with_validation_error(error_msg)[source]

Logs error messages and exits the program.

This function logs the provided validation error messages using a structured YAML format and terminates the program execution with a non-zero exit code (indicating an error).

Return type:

None

Parameters:

error_msg (dict) – The error message to print to the user.

Raises:

SystemExit – Exits the program with an EINVAL (invalid argument) code due to previously-determined validation errors.

easylink.utilities.general_utils.is_on_slurm()[source]

Returns True if the current environment is a SLURM cluster.

Return type:

bool

Notes

This function simply checks for the presence of the sbatch command to _infer_ if SLURM is installed. It does _not_ check if SLURM is currently active or managing jobs.