9.2.9. Utils#

General utilities and helpers.

junifer.utils.configure_logging(level='WARNING', fname=None, overwrite=None, output_format=None)#

Configure the logging functionality.

Parameters:
levelint or {“DEBUG”, “INFO”, “WARNING”, “ERROR”}

The level of the messages to print. If string, it will be interpreted as elements of logging (default “WARNING”).

fnamestr or pathlib.Path, optional

Filename of the log to print to. If None, stdout is used (default None).

overwritebool, optional

Overwrite the log file (if it exists). Otherwise, statements will be appended to the log (default). None is the same as False, but additionally raises a warning to notify the user that log entries will be appended (default None).

output_formatstr, optional

Format of the output messages. See the following for examples: https://docs.python.org/dev/howto/logging.html e.g., "%(asctime)s - %(levelname)s - %(message)s". If None, default string format is used (default "%(asctime)s - %(name)s - %(levelname)s - %(message)s").

junifer.utils.make_executable(path)#

Make path executable.

Parameters:
pathpathlib.Path

The path to make executable.

junifer.utils.raise_error(msg, klass=<class 'ValueError'>, exception=None)#

Raise error, but first log it.

Parameters:
msgstr

The message for the exception.

klasssubclass of Exception, optional

The subclass of Exception to raise using (default ValueError).

exceptionException, optional

The original exception to follow up on (default None).

junifer.utils.run_ext_cmd(name, cmd)#

Run external command via subprocess.

Parameters:
namestr

The name of the command.

cmdlist of str

The command to run as list of string.

Raises:
RuntimeError

If command fails.

junifer.utils.warn_with_log(msg, category=<class 'RuntimeWarning'>)#

Warn, but first log it.

Parameters:
msgstr

Warning message.

categorysubclass of Warning, optional

The warning subclass (default RuntimeWarning).