Skip to content

configuration

Configuration

SCT General Configuration.

Attributes

Classes

GeneralConfiguration dataclass

SCT general configuration

Attributes

save_log class-attribute instance-attribute
Python
save_log: bool = True
save_config_copy class-attribute instance-attribute
Python
save_config_copy: bool = True
toml_path class-attribute instance-attribute
Python
toml_path: Path | None = None

Methods:

__init__
Python
__init__(save_log: bool = True, save_config_copy: bool = True, toml_path: Path | None = None) -> None
from_dict classmethod
Python
from_dict(arg: dict) -> GeneralConfiguration

Convert from dict

to_dict
Python
to_dict() -> dict

Convert to dict

from_toml classmethod
Python
from_toml(file: str | Path) -> GeneralConfiguration

Generating a GeneralConfiguration dataclass from a .toml configuration file.

Parameters:

Name Type Description Default
file str | Path

path to the .toml configuration file

required

Returns:

Type Description
GeneralConfiguration

GeneralConfiguration dataclass set from .toml file

to_toml
Python
to_toml(out_file: Path) -> None

Saving to disk a .toml file from the dataclass instance.

Parameters:

Name Type Description Default
out_file Path

path to the output .toml file

required

Functions:

SCT Abstract Base Class for Analyses Configurations.

Classes

AnalysisConfigABC

Bases: ABC

Abstract Base Class for Analyses Configurations

Attributes

validation_schema instance-attribute
Python
validation_schema: Path
config_group_name instance-attribute
Python
config_group_name: str

Methods:

from_dict abstractmethod classmethod
Python
from_dict(arg: dict) -> Self
to_dict abstractmethod
Python
to_dict() -> dict
from_toml classmethod
Python
from_toml(file: str | Path) -> Self

Generating a Self dataclass from a .toml configuration file.

Parameters:

Name Type Description Default
file str | Path

path to the .toml configuration file

required

Returns:

Type Description
Self

Self dataclass set from .toml file

to_toml
Python
to_toml(out_file: Path) -> None

Saving to disk a .toml file from the dataclass instance.

Parameters:

Name Type Description Default
out_file Path

path to the output .toml file

required

Functions:

Common utilities for analyses configurations.

Classes

InvalidConfigurationFile

Bases: RuntimeError

Invalid SCT .toml configuration file

Functions:

toml_schema_validation

Python
toml_schema_validation(content: dict, schema_path: str | Path)

Validation of input configuration file for SCT tool.

Parameters:

Name Type Description Default
content dict

dictionary containing the parsed toml content

required
schema_path str | Path

path to the json schema file

required

Logger

SCT Logger

Attributes

sct_logger module-attribute

Python
sct_logger = logging.getLogger('sct-log')

Classes

AnsiColors

Bases: Enum

Ansi escape color strings for Logging Formatter

Attributes

GREY class-attribute instance-attribute
Python
GREY = '\x1b[38;20m'
YELLOW class-attribute instance-attribute
Python
YELLOW = '\x1b[33;20m'
HIGHLIGHT_YELLOW class-attribute instance-attribute
Python
HIGHLIGHT_YELLOW = '\x1b[48;5;226m'
GREEN class-attribute instance-attribute
Python
GREEN = '\x1b[1;32m'
HIGHLIGHT_GREEN class-attribute instance-attribute
Python
HIGHLIGHT_GREEN = '\x1b[48;5;40m'
RED class-attribute instance-attribute
Python
RED = '\x1b[31;20m'
HIGHLIGHT_RED class-attribute instance-attribute
Python
HIGHLIGHT_RED = '\x1b[48;5;196m'
BOLD_RED class-attribute instance-attribute
Python
BOLD_RED = '\x1b[31;1m'
PURPLE class-attribute instance-attribute
Python
PURPLE = '\x1b[1;35m'
BLUE class-attribute instance-attribute
Python
BLUE = '\x1b[1;34m'
LIGHT_BLUE class-attribute instance-attribute
Python
LIGHT_BLUE = '\x1b[1;36m'
BOLD class-attribute instance-attribute
Python
BOLD = '\x1b[1m'
UNDERLINE class-attribute instance-attribute
Python
UNDERLINE = '\x1b[4m'
RESET class-attribute instance-attribute
Python
RESET = '\x1b[0m'

ConsoleFormatter

Bases: Formatter

Custom logger formatter with colors

Attributes

fmt class-attribute instance-attribute
Python
fmt = '| %(levelname)-9s @ %(module)s| %(asctime)s | %(message)s'
FORMATS class-attribute instance-attribute
Python
FORMATS = {logging.DEBUG: AnsiColors.GREY.value + fmt + AnsiColors.RESET.value, logging.INFO: AnsiColors.GREY.value + fmt + AnsiColors.RESET.value, logging.WARNING: AnsiColors.YELLOW.value + fmt + AnsiColors.RESET.value, logging.ERROR: AnsiColors.RED.value + fmt + AnsiColors.RESET.value, logging.CRITICAL: AnsiColors.BOLD_RED.value + fmt + AnsiColors.RESET.value, logging.FAIL: AnsiColors.BOLD.value + AnsiColors.HIGHLIGHT_RED.value + fmt + AnsiColors.RESET.value, logging.SUCCESS: AnsiColors.BOLD.value + AnsiColors.HIGHLIGHT_GREEN.value + fmt + AnsiColors.RESET.value}

Methods:

format
Python
format(record)

FileFormatter

Bases: Formatter

Custom logger formatter with colors

Attributes

fmt class-attribute instance-attribute
Python
fmt = '| %(levelname)-9s @ %(module)s| %(asctime)s | %(message)s'
FORMATS class-attribute instance-attribute
Python
FORMATS = {logging.DEBUG: fmt, logging.INFO: fmt, logging.WARNING: fmt, logging.ERROR: fmt, logging.CRITICAL: fmt, logging.FAIL: fmt, logging.SUCCESS: fmt}

Methods:

__init__
Python
__init__()
format
Python
format(record)

ConsoleHandler

Bases: StreamHandler

Custom logging stream handler to centralize logging

Methods:

__init__
Python
__init__()

SCTFileHandler

Bases: FileHandler

Custom logging file handler to centralize logging

Methods:

__init__
Python
__init__(filename: Path)

File handler to write log to disk.

Parameters:

Name Type Description Default
filename Path

log filename

required

Functions:

add_logging_level

Python
add_logging_level(level_name, level_num, method_name=None)

Comprehensively adds a new logging level to the logging module and the currently configured logging class.

level_name becomes an attribute of the logging module with the value levelNum. method_name becomes a convenience method for both logging itself and the class returned by logging.getLoggerClass() (usually just logging.Logger). If method_name is not specified, level_name.lower() is used.

To avoid accidental clobbering of existing attributes, this method will raise an AttributeError if the level name is already an attribute of the logging module or if the method name is already present

Example

addLoggingLevel("TRACE", logging.DEBUG - 5) logging.getLogger(name).setLevel("TRACE") logging.getLogger(name).trace("that worked") logging.trace("so did this") logging.TRACE 5

enable_quality_logger

Python
enable_quality_logger(file_handler: Handler | None = None)

Enabling quality logger with the same handler of the sct common logger.

Parameters:

Name Type Description Default
file_handler FileHandler | None

if provided, a file handler is added to the logger, by default None

None