iota2.common.utils

This module contains decorators and utils functions.

Functions

chunker(list_of_things, chunk_size)

Yield an iterator, splitting the input list by chunks of given size

dataclass([cls, init, repr, eq, order, ...])

Add dunder methods based on the fields defined in the class.

fields(class_or_instance)

Return a tuple describing the fields of this dataclass.

is_dataclass(obj)

Returns True if obj is a dataclass or an instance of a dataclass.

is_empty_dataclass(dataclass_inst)

Check if at least one field of the dataclass is set.

is_nomenclature_castable_to_int(labels_table)

Try to convert labels to int.

print_types(func)

Decorator to print types of arguments when calling a function.

run(cmd[, desc, env, logger])

Launch a system command and raise an execption if fail.

str2bool(val)

Convert a string vue to boolean.

timer

perf_counter() -> float

wraps(wrapped[, assigned, updated])

Decorator factory to apply update_wrapper() to a wrapper function

Classes

Any(*args, **kwargs)

Special type indicating an unconstrained type.

Callable()

Generator()

Mapping()

A Mapping is a generic container for associating key/value pairs.

RemoveInStringList(*args)

Remove element decorator to remove strings in a list.

TaskConfig([logger, ram])

Dataclass containing ressources for tasks

class iota2.common.utils.RemoveInStringList(*args)[source]

Remove element decorator to remove strings in a list.

__init__(*args)[source]
class iota2.common.utils.TaskConfig(logger=<Logger distributed.worker (WARNING)>, ram=128)[source]

Dataclass containing ressources for tasks

__init__(logger=<Logger distributed.worker (WARNING)>, ram=128)
logger: Logger = <Logger distributed.worker (WARNING)>
ram: int = 128
iota2.common.utils.chunker(list_of_things, chunk_size)[source]

Yield an iterator, splitting the input list by chunks of given size

Parameters:
  • list_of_things (list) – Input list

  • chunk_size (int) – Number of elements by list

Return type:

Generator

iota2.common.utils.is_empty_dataclass(dataclass_inst)[source]

Check if at least one field of the dataclass is set.

Return type:

bool

iota2.common.utils.is_nomenclature_castable_to_int(labels_table)[source]

Try to convert labels to int.

Return type:

bool

iota2.common.utils.print_types(func)[source]

Decorator to print types of arguments when calling a function.

Return type:

Callable

iota2.common.utils.run(cmd, desc=None, env=None, logger=<Logger distributed.worker (WARNING)>)[source]

Launch a system command and raise an execption if fail.

Parameters:
  • cmd (str) – the system command to be launched

  • desc (Optional[str]) – an optional description of the command for log_dir

  • env (Optional[Mapping[str, str]]) – the environ variable if None, os.environ is used

  • logger (Logger) – by default module LOGGER value is used

Return type:

int

iota2.common.utils.str2bool(val)[source]

Convert a string vue to boolean.

usage: use in argParse as function to parse options :type val: str :param val: the value to convert

Return type:

bool