ten8t package

Contents

ten8t package#

Submodules#

ten8t.rule_pathlib module#

ten8t.rule_fs module#

ten8t.rule_ndf module#

ten8t.rule_pdf module#

ten8t.rule_ping module#

ten8t.rule_sqlachemy module#

ten8t.rule_webapi module#

ten8t.rule_xlsx module#

ten8t.ten8t_attribute module#

ten8t.ten8t_checker module#

ten8t.ten8t_exception module#

Basic exception classes for ten8t.

exception ten8t.ten8t_exception.Ten8tException[source]#

Bases: Exception

Specialized exception for ten8t.

exception ten8t.ten8t_exception.Ten8tTypeError[source]#

Bases: TypeError

Type errors associated with setting up ten8t

When bad types are sent to ten8t, this exception will be raised and should not be confused the TypeError that (should) indicate an unexpected lower level error.

exception ten8t.ten8t_exception.Ten8tValueError[source]#

Bases: ValueError

Value Error associated with setting up ten8t

These exceptions will occur when setting up parameters on ten8t attributes and basic setup. For example a negative weight.

ten8t.ten8t_function module#

ten8t.ten8t_immutable module#

ten8t.ten8t_logging module#

Logging support for Ten8t.

The purpose of this module is to set up package logging in a general way that integrates with other packages and loggers.

The key feature is that you can call ten8t_setup_logging AFTER you have configured other packages’ loggers’ and it will just work along with them.

If the only logging in the system is set up with this tool then you can still use this and provide a target stream (e.g., stdout) and a file name.

This method is set up to manage a single global logger object named ten8t_logger that should be used by all the ten8t modules.

ten8t.ten8t_logging.ten8t_reset_logging()[source]#

Reset the logger to its initial state by removing all handlers and reinstating a NullHandler.

NOTE: This function is intended for testing purposes ONLY.

Using this in production code may disrupt logging configurations.

ten8t.ten8t_logging.ten8t_setup_logging(level: int = 30, propagate: bool = True, file_name: str | None = None, stream_=None, format_string: str = '%(asctime)s - %(name)s - %(levelname)s - %(message)s') None[source]#

Configure the global logger for the ‘ten8t’ package.

Parameters:
  • level (int) – Logging level (default=logging.WARNING).

  • propagate (bool) – If True, propagates logs to the parent logger (default=True).

  • file_name (str) – Optional file path to save logs.

  • stream (io.TextIOWrapper | None) – Optional stream (e.g., sys.stdout, sys.stderr).

  • format_string (str) – Format string for log messages (default:time, name, level, and msg).

Returns:

Configures the global ten8t_logger.

Return type:

None

ten8t.ten8t_module module#

ten8t.ten8t_package module#

ten8t.ten8t_rc_factory module#

ten8t.ten8t_result module#

This module contains the Ten8tResult class and some common result transformers.

ten8t.ten8t_result.TR#

alias of Ten8tResult

class ten8t.ten8t_result.Ten8tResult(status: bool | None = False, func_name: str = '', pkg_name: str = '', module_name: str = '', msg: str = '', info_msg: str = '', warn_msg: str = '', msg_rendered: str = '', doc: str = '', runtime_sec: float = 0.0, except_: Exception | None = None, traceback: str = '', skipped: bool = False, weight: float = 100.0, tag: str = '', level: int = 1, phase: str = '', count: int = 0, ruid: str = '', ttl_minutes: float = 0.0, mit_msg: str = '', owner_list: list[str] = <factory>, skip_on_none: bool = False, fail_on_none: bool = False, summary_result: bool = False, thread_id: str = '')[source]#

Bases: object

Return value of a Ten8tFunction.

This dataclass tracks the status of a Ten8tFunction. It includes data relating to the function call, such as the status, module name, function name, message, additional info, warning message, docstring, runtime, exceptions, traceback, skip flag, tag, level, and count.

While normally I choose “reasonable” defaults, in this case there really are none that aren’t “zero” values except for weight and level, which default to 100% and 1 respectively.

This data can be used for reporting purposes.

status#

Check status. Default is False.

Type:

bool

module_name#

Module name. Default is “”.

Type:

str

func_name#

Function name. Default is “”.

Type:

str

msg#

Message to the user. Default is “”.

Type:

str

info_msg#

Additional function call info. Default is “”.

Type:

str

warn_msg#

Warning message. Default is “”.

Type:

str

doc#

Function docstring. Default is “”.

Type:

str

runtime_sec#

Function runtime in seconds. Default is 0.0.

Type:

float

except_#

Raised exception, if any. Default is None.

Type:

Exception

traceback#

Exception traceback, if any. Default is “”.

Type:

str

skipped#

Function skip flag. Default is False.

Type:

bool

tag#

Function tag. Default is “”.

Type:

str

level#

Function level. Default is 1.

Type:

int

thread_id#

Thread the function ran on. Default is “”.

Type:

str

count#

Return value count from a Ten8tFunction.

Type:

int

as_dict() dict[source]#

Convert the Ten8tResult instance to a dictionary.

count: int = 0#
doc: str = ''#
except_: Exception | None = None#
fail_on_none: bool = False#
func_name: str = ''#
info_msg: str = ''#
level: int = 1#
mit_msg: str = ''#
module_name: str = ''#
msg: str = ''#
msg_rendered: str = ''#
mu = <ten8t.render._markup.Ten8tMarkup object>#
owner_list: list[str]#
phase: str = ''#
pkg_name: str = ''#
ruid: str = ''#
runtime_sec: float = 0.0#
skip_on_none: bool = False#
skipped: bool = False#
status: bool | None = False#
summary_result: bool = False#
tag: str = ''#
thread_id: str = ''#
traceback: str = ''#
ttl_minutes: float = 0.0#
warn_msg: str = ''#
weight: float = 100.0#
ten8t.ten8t_result.fails_only(sr: Ten8tResult)[source]#

Filters out successful results.

Parameters:

sr (Ten8tResult) – The result to check.

Returns:

The result if it has failed, otherwise None.

Return type:

Ten8tResult

ten8t.ten8t_result.group_by(results: Sequence[Ten8tResult], keys: Sequence[str]) dict[str, Any][source]#

Groups a list of Ten8tResult by a list of keys.

This function allows for arbitrary grouping of Ten8tResult using the keys of the Ten8tResult as the grouping criteria. You can group in any order or depth with any number of keys.

Parameters:
  • results (Sequence[Ten8tResult]) – The list of results to group.

  • keys (Sequence[str]) – The list of keys to group by.S

ten8t.ten8t_result.overview(results: list[Ten8tResult]) str[source]#

Returns an overview of the results.

Parameters:

results (list[Ten8tResult]) – The list of results to summarize.

Returns:

A summary of the results.

Return type:

str

ten8t.ten8t_result.passes_only(sr: Ten8tResult)[source]#

Return only results that have pass status

ten8t.ten8t_result.remove_info(sr: Ten8tResult)[source]#

Filter out messages tagged as informational

Parameters:

sr (Ten8tResult) – The result to check.

Returns:

The result if it has failed, otherwise None.

Return type:

Ten8tResult

ten8t.ten8t_result.results_as_dict(results: list[Ten8tResult])[source]#

Converts a list of Ten8tResult to a list of dictionaries.

Parameters:

results (list[Ten8tResult]) – The list of results to convert.

Returns:

The list of dictionaries.

Return type:

list[Dict]

ten8t.ten8t_result.warn_as_fail(sr: Ten8tResult)[source]#

Treats results with a warning message as failures.

Parameters:

sr (Ten8tResult) – The result to check.

Returns:

The result with its status set to False if there’s a warning message.

Return type:

Ten8tResult

ten8t.ten8t_ruid module#

ten8t.ten8t_thread module#

ten8t.ten8t_util module#

This is the sad place for lonely functions that don’t have a place

ten8t.ten8t_util.FloatList#

Type alias for a sequence of floats.

alias of Sequence[float]

ten8t.ten8t_util.FloatListOrNone#

Type alias for a sequence of floats or None.

alias of Sequence[float] | float | None

ten8t.ten8t_util.FloatOrNone: TypeAlias = float | None#

Type alias for a float or None.

ten8t.ten8t_util.IntList#

Type alias for a sequence of integers.

alias of Sequence[int]

ten8t.ten8t_util.IntListOrNone#

Type alias for a sequence of integers or None.

alias of Sequence[int] | int | None

ten8t.ten8t_util.IntOrNone: TypeAlias = int | None#

Type alias for an integer or None.

class ten8t.ten8t_util.NextIntValue[source]#

Bases: object

I had to create this class in order to make mypy happy. Mypy does not know how to handle dynamic functions and playing games

ten8t.ten8t_util.StrList#

Type alias for a sequence of strings.

alias of Sequence[str]

ten8t.ten8t_util.StrListOrNone#

Type alias for a sequence of strings or None.

alias of Sequence[str] | str | None

ten8t.ten8t_util.StrOrNone: TypeAlias = str | None#

Type alias for a string or None.

ten8t.ten8t_util.any_to_int_list(param: Sequence[int] | int | None, sep=' ') Sequence[int][source]#

Convert a string to a list of integers or if a list is given make sure it is all integers. :param param: list of integers or string to convert to list of integers :param sep: separator character.

Returns:

list of integers

ten8t.ten8t_util.any_to_path_list(param: Sequence[str | Path] | None, sep=' ') Sequence[Path][source]#

Flexibly take a list of strings are pathlib objects and make a uniform list of pathlib objects. This is useful for normalizing data read from different sources without have a bunch of point of use parsing.

The assumption is that this data could come from a config file, a command line parameter, a UI element that returns strings, or code. This should make all code just “fix” the data with this call.

Parameters:
  • param – StrOrPathListOrNone Data to normalize

  • sep – Separator character. Should almost always be ‘ ‘

Returns:

ten8t.ten8t_util.any_to_str_list(param: Sequence[str] | str | None, sep=' ') Sequence[str][source]#

Convert a string to a list of strings or if a list is given make sure it is all strings. :param param: list of strings or string to convert to list of strings :param sep: separator character.

Returns:

ten8t.ten8t_util.str_to_bool(s: str, default=None) bool[source]#

Convert a string value to a boolean.

Module contents#