qsprpred.logs package

Submodules

qsprpred.logs.config module

class qsprpred.logs.config.LevelFilter(level)[source]

Bases: Filter

LoggingFilter used to filter one or more specific log levels messages

Initialize a filter.

Initialize with the name of the logger which, together with its children, will have its events allowed through the filter. If no name is specified, allow every event.

filter(record)[source]

Determine if the specified record is to be logged.

Returns True if the record should be logged, or False otherwise. If deemed appropriate, the record may be modified in-place.

class qsprpred.logs.config.LevelFormatter(formats: dict[int, str], **kwargs)[source]

Bases: Formatter

LoggingFormatter used to specifiy the formatting per level

Initialize the formatter with specified format strings.

Initialize the formatter either with the specified format string, or a default as described above. Allow for specialized date formatting with the optional datefmt argument. If datefmt is omitted, you get an ISO8601-like (or RFC 3339-like) format.

Use a style parameter of ‘%’, ‘{’ or ‘$’ to specify that you want to use one of %-formatting, str.format() ({}) formatting or string.Template formatting in your format string.

Changed in version 3.2: Added the style parameter.

converter()
localtime([seconds]) -> (tm_year,tm_mon,tm_mday,tm_hour,tm_min,

tm_sec,tm_wday,tm_yday,tm_isdst)

Convert seconds since the Epoch to a time tuple expressing local time. When ‘seconds’ is not passed in, convert the current time instead.

default_msec_format = '%s,%03d'
default_time_format = '%Y-%m-%d %H:%M:%S'
format(record: LogRecord) str[source]

Format the specified record as text.

The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.

formatException(ei)

Format and return the specified exception information as a string.

This default implementation just uses traceback.print_exception()

formatMessage(record)
formatStack(stack_info)

This method is provided as an extension point for specialized formatting of stack information.

The input data is a string as returned from a call to traceback.print_stack(), but with the last trailing newline removed.

The base implementation just returns the value passed in.

formatTime(record, datefmt=None)

Return the creation time of the specified LogRecord as formatted text.

This method should be called from format() by a formatter which wants to make use of a formatted time. This method can be overridden in formatters to provide for any specific requirement, but the basic behaviour is as follows: if datefmt (a string) is specified, it is used with time.strftime() to format the creation time of the record. Otherwise, an ISO8601-like (or RFC 3339-like) format is used. The resulting string is returned. This function uses a user-configurable function to convert the creation time to a tuple. By default, time.localtime() is used; to change this for a particular formatter instance, set the ‘converter’ attribute to a function with the same signature as time.localtime() or time.gmtime(). To change it for all formatters, for example if you want all logging times to be shown in GMT, set the ‘converter’ attribute in the Formatter class.

usesTime()

Check if the format uses the creation time of the record.

class qsprpred.logs.config.LogFileConfig(path, logger, debug)[source]

Bases: object

qsprpred.logs.config.config_logger(log_file_path, debug=None, disable_existing_loggers=True)[source]

Function to configure the logging. All info is saved in a simple format on the log file path. Debug entries are saved to a separate file if debug is True Debug and warning and above are save in a verbose format. Warning and above are also printed to std.out

Parameters:
  • log_file_path (str) – Folder where all logs for this run are saved

  • debug (bool) – if true, debug messages are saved

  • no_exist_log (bool) – if true, existing loggers are disabled

qsprpred.logs.config.get_git_info()[source]

Get information of the current git commit

If the package is installed with pip, read the detailed version extracted by setuptools_scm. Otherwise, use gitpython to get the information from the git repo.

qsprpred.logs.config.get_runid(log_folder: str = 'logs', old: bool = True, id: int | None = None)[source]

Fetch runid that is used in all logfiles to identifiy a specific run.

Parameters:
  • log_folder (str) – Folder where all logs are saved

  • old (bool) – if true, fetches the last used runid

  • id (int) – If included, returns this runid number

Returns:

runid in the format “0001”

Return type:

runid (str)

qsprpred.logs.config.init_logfile(log, args=None)[source]

Put some intial information in the logfile

Parameters:
  • log – Logging instance

  • args (dict) – Dictionary with all command line arguments

qsprpred.logs.utils module

qsprpred.logs.utils.backup_files(output_dir: str, output_prefixes: tuple, cp_suffix=None)[source]
qsprpred.logs.utils.backup_files_in_folder(_dir: str, backup_id: int, output_prefixes, output_extensions='dummy', cp_suffix=None)[source]

Backs up files in a specified directory to a backup directory.

Parameters:
  • _dir (str) – The directory path where the files to be backed up are located.

  • backup_id (int) – The ID of the backup.

  • output_prefixes (str) – The prefix of the output files to be backed up.

  • output_extensions (str, optional) – The extension of the output files to be backed up. Defaults to “dummy”.

  • cp_suffix (list of str, optional) – The suffix of the files to be copied instead of moved. Defaults to None.

Returns:

A message indicating which files were backed up and where they

were moved/copied.

Return type:

str

qsprpred.logs.utils.enable_file_logger(log_folder: str, filename: str, debug: bool = False, log_name: str | None = None, init_data: dict | None = None, disable_existing_loggers: bool = False)[source]

Enable file logging.

Parameters:
  • log_folder (str) – path to the folder where the log file should be stored

  • filename (str) – name of the log file

  • debug (bool) – whether to enable debug logging. Defaults to False.

  • log_name (str, optional) – name of the logger. Defaults to None.

  • init_data (dict, optional) – initial data to be logged. Defaults to None.

  • disable_existing_loggers (bool) – whether to disable existing loggers.

qsprpred.logs.utils.export_conda_environment(filepath: str)[source]

Export the conda environment to a yaml file.

Parameters:

filepath (str) – path to the yaml file

Raises:
qsprpred.logs.utils.generate_backup_dir(root: str, backup_id: int)[source]

Generates backup directory for files to be overwritten.

Parameters:
  • root (str) – the root directory

  • backup_id (int) – the ID of the backup

Returns:

the path to the new backup directory

Return type:

new_dir

qsprpred.logs.utils.generate_backup_runID(path='.')[source]

Generates runID for generation backups of files to be overwritten.

If no previous backfiles (starting with #) exists, runid is set to 0, else to previous runid+1

Module contents

qsprpred.logs.setLogger(log)[source]