utils#

Module attributes and functions#

utils.binary_to_boolean_type(value)[source]#

Converts a binary string to a boolean type.

Parameters:

value (str) – the binary string

Returns:

the boolean type

Return type:

bool

utils.check_fn_dynamic_type(fn, tp, strict=True)[source]#

Controls if the function respects the type tp. The function must have the same number of arguments as the type tp and the same type for each argument.

Parameters:
  • fn (T) – the function to be checked

  • tp (Type[T]) – the type to be respected

  • strict – if True, raises an error if the function does not respect the type tp

Return type:

bool

utils.create_if_not_exists(path)[source]#

Creates the specified folder if it does not exist.

Parameters:

path (str) – the complete path of the folder to be created

utils.custom_str_underscore(value)[source]#
class utils.disable_logging(min_level=50)[source]#

Wrapper for disabling logging for a specific block of code.

utils.field_with_aliases(choices)[source]#

Build a data type where for each key in choices there are a set of aliases.

Example

Given the following dictionary:

choices = {
    'a': ['a', 'alpha'],
    'b': ['b', 'beta']
}

The values ‘a’ and ‘alpha’ will be converted to ‘a’, and ‘b’ and ‘beta’ will be converted to ‘b’.

Parameters:

choices (dict) – the dictionary containing the aliases

Returns:

the data type for argparse

Return type:

str

utils.infer_args_from_signature(signature, excluded_signature=None)[source]#

Load the arguments of a function from its signature.

Parameters:

signature (Signature) – the signature of the function

Returns:

the inferred arguments

Return type:

dict

utils.none_or_float(value)[source]#
utils.random_id(length=8, alphabet='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789')[source]#

Returns a random string of the specified length.

Parameters:
  • length – the length of the string

  • alphabet – the alphabet to be used

Returns:

the random string

utils.register_dynamic_module_fn(name, register, tp)[source]#

Register a dynamic module in the specified dictionary.

Parameters:
  • name (str) – the name of the module

  • register (dict) – the dictionary where the module will be registered

  • cls – the class to be registered

  • tp (Type[T]) – the type of the class, used to dynamically infer the arguments

utils.setup_logging()[source]#

Configures the logging module.

utils.smart_joint(*paths)[source]#