temci.utils package

Submodules

temci.utils.click_helper module

temci.utils.config_utils module

Types shared between different file config definitions

temci.utils.library_init module

temci.utils.mail module

Utilities to send mails.

temci.utils.mail.hostname() → str[source]

Returns the hostname of the current machine

temci.utils.mail.send_mail(recipient: str, subject: str, content: str, attached_files: List[str] = None)[source]

Sends a mail to the recipient with the passed subject, content and attached files.

Parameters
  • recipient – recipient of the mail, i.e. a mail address

  • subject – subject of the mail

  • content – content of the mail

  • attached_files – optional list of names of files that are attached to the mail

temci.utils.number module

class temci.utils.number.FNumber(number: Union[int, float], rel_deviation: Union[int, float] = None, abs_deviation: Union[int, float] = None, is_percent: bool = None, scientific_notation: bool = None, parentheses_mode: Union[str, temci.utils.number.ParenthesesMode] = None, parentheses: bool = None)[source]

Bases: object

A formattable number wrapper.

Configuration format, is in the settings under report/number

# Don't omit the minimum number of decimal places if insignificant?
force_min_decimal_places:         Bool()
            default: true

# The maximum number of decimal places
max_decimal_places:         Int(constraint=<function>)
            default: 5

# The minimum number of shown decimal places if decimal places are shown
min_decimal_places:         Int(constraint=<function>)
            default: 3

# Omit insignificant decimal places
omit_insignificant_decimal_places:         Bool()

# Show parentheses around non significant digits? (If a std dev is given)
parentheses:         Bool()
            default: true

# Mode for showing the parentheses: either d (Digits are considered significant if they don't change
# if the number itself changes += $sigmas * std dev) or o (digits are consideredsignificant if they
# are bigger than $sigmas * std dev)
parentheses_mode:         ExactEither('d'|'o')
            default: o

# Show as percentages
percentages:         Bool()

# Use the exponential notation, i.e. '10e3' for 1000
scientific_notation:         Bool()
            default: true

# Use si prefixes instead of 'e…'
scientific_notation_si_prefixes:         Bool()
            default: true

# Number of standard deviation used for the digit significance evaluation
sigmas:         Int(constraint=<function>)
            default: 2
deviation

Relative deviation

format() → str[source]
classmethod init_settings(new_settings: Dict[str, Union[int, bool]])[source]
settings = {'force_min_decimal_places': True, 'max_decimal_places': 5, 'min_decimal_places': 3, 'omit_insignificant_decimal_places': False, 'parentheses': True, 'parentheses_mode': 'o', 'percentages': False, 'scientific_notation': True, 'scientific_notation_si_prefixes': True, 'sigmas': 2}
settings_format = # Don't omit the minimum number of decimal places if insignificant? force_min_decimal_places: Bool() default: true # The maximum number of decimal places max_decimal_places: Int(constraint=<function>) default: 5 # The minimum number of shown decimal places if decimal places are shown min_decimal_places: Int(constraint=<function>) default: 3 # Omit insignificant decimal places omit_insignificant_decimal_places: Bool() # Show parentheses around non significant digits? (If a std dev is given) parentheses: Bool() default: true # Mode for showing the parentheses: either d (Digits are considered significant if they don't change # if the number itself changes += $sigmas * std dev) or o (digits are consideredsignificant if they # are bigger than $sigmas * std dev) parentheses_mode: ExactEither('d'|'o') default: o # Show as percentages percentages: Bool() # Use the exponential notation, i.e. '10e3' for 1000 scientific_notation: Bool() default: true # Use si prefixes instead of 'e…' scientific_notation_si_prefixes: Bool() default: true # Number of standard deviation used for the digit significance evaluation sigmas: Int(constraint=<function>) default: 2
temci.utils.number.Number

Numeric type

alias of Union[int, float]

class temci.utils.number.ParenthesesMode(value)[source]

Bases: enum.Enum

An enumeration.

DIGIT_CHANGE = 'd'
ORDER_OF_MAGNITUDE = 'o'
classmethod map(key: Union[str, ParenthesesMode])temci.utils.number.ParenthesesMode[source]
temci.utils.number.fnumber(number: Union[int, float], rel_deviation: Union[int, float] = None, abs_deviation: Union[int, float] = None, is_percent: bool = False) → str[source]
temci.utils.number.format_number(number: Union[int, float], deviation: float = 0.0, parentheses: bool = True, explicit_deviation: bool = False, is_deviation_absolute: bool = True, min_decimal_places: int = 3, max_decimal_places: Optional[int] = None, omit_insignificant_decimal_places: bool = True, scientific_notation: bool = False, scientific_notation_steps: int = 3, scientific_notation_decimal_places: int = None, scientific_notation_si_prefixes: bool = True, force_min_decimal_places: bool = True, relative_to_deviation: bool = False, sigmas: int = 2, parentheses_mode: temci.utils.number.ParenthesesMode = <ParenthesesMode.ORDER_OF_MAGNITUDE: 'o'>) → str[source]

Format the passed number

>>> format_number(1.0, 0.5)
'1.(000)'
>>> format_number(1.56, 0.005)
'1.56(0)'
>>> format_number(1560, scientific_notation=True)
'1.560k'
>>> format_number(1560, scientific_notation_si_prefixes=False, scientific_notation=True)
'1.560e3'
>>> format_number(float("inf"))
'inf'
Parameters
  • number – formatted number

  • deviation – standard deviation associated with the number

  • parentheses – show parentheses around non significant digits?

  • explicit_deviation – show the absolute deviation, e.g. “100±456.4”

  • is_deviation_absolute – is the given deviation absolute?

  • min_decimal_places – the minimum number of shown decimal places if decimal places are shown

  • max_decimal_places – the maximum number of decimal places

  • omit_insignificant_decimal_places – omit insignificant decimal places

  • scientific_notation – use the exponential notation, i.e. “10e3” for 1000

  • scientific_notation_steps – steps in which the exponential part is incremented

  • scientific_notation_decimal_places – number of decimal places that are shown in the scientic notation

  • scientific_notation_si_prefixes – use si prefixes instead of “e…”

  • force_min_decimal_places – don’t omit the minimum number of decimal places if insignificant?

  • relative_to_deviation – format the number relative to its deviation, i.e. “10 sigma”

  • sigmas – number of standard deviations for significance

  • parentheses_mode – mode for selecting the significant digits

Returns

the number formatted as a string

temci.utils.number.format_number_sn(number: Union[int, float], scientific_notation_steps: int = 3, deviation: Optional[float] = None, decimal_places: int = None, si_prefixes: bool = True, **kwargs)[source]

temci.utils.plugin module

Utilities for loading plugins. Plugins are python files (ending .py) that are loaded prior to building the cli. These files may e.g. add runners, plugins, …

Plugins are loaded from the application directory (~/.temci) and from the paths given in the environment variable TEMCI_PLUGIN_PATH which contains a colon separated list of paths.

temci.utils.plugin.load_plugins()[source]

Load the plugins from the plugin folders :return:

temci.utils.plugin.plugin_paths() → List[str][source]

Returns the paths that plugins are located in (might return folders and files)

temci.utils.registry module

temci.utils.settings module

temci.utils.sudo_utils module

temci.utils.typecheck module

Implements basic type checking for complex types.

Why? Because it’s nice to be able to type check complex structures that come directly from the user (e.g. from YAML config files).

The Type instance are usable with the standard isinstance function:

isinstance(4, Either(Float(), Int()))

Type instances also support the “&” (producres All(one, two)) and “|” (produces Either(one, two)) operators. The above sample code can therefore be written as:

isinstance(4, Float() | Int())

The native type wrappers also support custom constraints. With help of the fn module one can write:

t = Float(_ > 0) | Int(_ > 10)
isinstance(var, t)

“t” is a Type that matches only floats greater than 0 and ints greater than 10.

For more examples look into the test_typecheck.py file.

class temci.utils.typecheck.All(*types: Tuple[temci.utils.typecheck.Type])[source]

Bases: temci.utils.typecheck.Type

Checks for the value to be of all of several types.

Creates an All instance.

Parameters

types – list of types (or SpecialType subclasses)

Raises

ConstraintError if some of the contraints aren’t (typechecker) Types

types

Expected types

class temci.utils.typecheck.Any(completion_hints: Dict[str, Any] = None)[source]

Bases: temci.utils.typecheck.Type

Checks for the value to be of any type.

Creates an instance.

Parameters

completion_hints – completion hints for supported shells for this type instance

class temci.utils.typecheck.Bool[source]

Bases: temci.utils.typecheck.Type, click.types.ParamType

Like Bool but with a third value none that declares that the value no boolean value. It has None as its default value (by default).

Creates an instance.

Parameters

completion_hints – completion hints for supported shells for this type instance

completion_hints

Completion hints for supported shells for this type instance

name = 'bool'

click.ParamType name, that makes this class usable as a click type

class temci.utils.typecheck.BoolOrNone[source]

Bases: temci.utils.typecheck.Type, click.types.ParamType

Like Bool but with a third value none that declares that the value no boolean value. It has None as its default value (by default).

Creates an instance.

Parameters

completion_hints – completion hints for supported shells for this type instance

completion_hints

Completion hints for supported shells for this type instance

convert(value, param, ctx: click.core.Context)Optional[bool][source]

Convert method that makes this class usable as a click type.

default

The default value of this instance

name = 'bool_or_none'

click.ParamType name, that makes this class usable as a click type

class temci.utils.typecheck.CompletionHint(**hints)[source]

Bases: object

A completion hint annotation for a type. Usage example:

Int() // Completion(zsh="_files")
hints

Completion hints for every supported shell

class temci.utils.typecheck.Constraint(constraint: Callable[[Any], bool], constrained_type: temci.utils.typecheck.Type = Any, description: str = None)[source]

Bases: temci.utils.typecheck.Type

Checks the passed value by an user defined constraint.

Creates an Constraint instance.

Parameters
  • constraint – function that returns True if the user defined constraint is satisfied

  • constrained_type – Type that the constraint is applied on

  • description – short description of the constraint (e.g. “>0”)

Raises

ConstraintError if constrained_type isn’t a (typechecker) Types

constrained_type

Type that the constraint is applied on

constraint

Function that returns True if the user defined constraint is satisfied

description

Short description of the constraint (e.g. “>0”)

string_representation(indents: int = 0, indentation: int = 4, str_list: bool = False, defaults=None) → Union[str, List[str]][source]

Produce a YAML string that contains the default value (if possible), the description of this type and more and its possible sub types.

Parameters
  • indents – number of indents in front of each produced line

  • indentation – indentation width in number of white spaces

  • str_list – return a list of lines instead of a combined string?

  • defaults – default value that should be used instead of the default value of this instance

class temci.utils.typecheck.Default(default)[source]

Bases: object

A default value annotation for a Type. Usage example:

Int() // Default(3)

Especially useful to declare the default value for a key of an dictionary. Allows to use Dict(…).get_default() -> dict.

default

Default value of the annotated type

class temci.utils.typecheck.Description(description: str)[source]

Bases: object

A description of a Type, that annotates it. Usage example:

Int() // Description("Description of Int()")
description

Description string

class temci.utils.typecheck.Dict(data: Dict[Any, temci.utils.typecheck.Type] = None, unknown_keys: bool = False, key_type: temci.utils.typecheck.Type = Any, value_type: temci.utils.typecheck.Type = Any)[source]

Bases: temci.utils.typecheck.Type

Checks for the value to be a dictionary with expected keys and values satisfy given type constraints.

Creates a new instance.

Parameters
  • data – dictionary with the expected keys and the expected types of the associated values

  • unknown_keys – accept unknown keys in value

  • key_type – expected Type of all dictionary keys

  • value_type – expected Type of all dictionary values

Raises

ConstraintError if one of the given types isn’t a (typechecker) Types

get_default() → dict[source]

Returns the default value of this type :raises: ValueError if the default value isn’t set

get_default_yaml(indent: int = 0, indentation: int = 4, str_list: bool = False, defaults=None) → str[source]

Produce a YAML like string that contains the default value and the description of this type and its possible sub types.

Parameters
  • indents – number of indents in front of each produced line

  • indentation – indentation width in number of white spaces

  • str_list – return a list of lines instead of a combined string?

  • defaults – default value that should be used instead of the default value of this instance

get_description(key: str) → str[source]

Returns the description for the passed key or None if there isn’t one.

Parameters

key – passed key

has_default() → bool[source]

Does this type instance have an default value?

is_obsolete(key: str) → bool[source]

Is the type that belongs to the key Obsolete?

Parameters

key – dict key

Returns

obsolete?

key_type

Expected Type of all dictionary keys

obsoleteness_reason(key: str)Optional[temci.utils.typecheck.Obsolete][source]

Return the obsoleteness reason (the Obsolete type object) if the key is obsolete

Parameters

key – dict key

Returns

Obsolete object or none

string_representation(indents: int = 0, indentation: int = 4, str_list: bool = False, defaults=None) → Union[str, List[str]][source]

Produce a YAML string that contains the default value (if possible), the description of this type and more and its possible sub types.

Parameters
  • indents – number of indents in front of each produced line

  • indentation – indentation width in number of white spaces

  • str_list – return a list of lines instead of a combined string?

  • defaults – default value that should be used instead of the default value of this instance

unknown_keys

Fail if value contains unknown keys

value_type

Expected Type of all dictionary values

class temci.utils.typecheck.DirName(constraint: Callable[[Any], bool] = None)[source]

Bases: temci.utils.typecheck.Str

A valid directory name. If the directory doesn’t exist, at least the parent directory must exist.

Creates an instance.

Parameters

constraint – function that returns True if the user defined constraint is satisfied

completion_hints

Completion hints for supported shells for this type instance

constraint

Function that returns True if the user defined constraint is satisfied

temci.utils.typecheck.E(exp_value)temci.utils.typecheck.Exact[source]

Alias for Exact.

class temci.utils.typecheck.Either(*types: tuple)[source]

Bases: temci.utils.typecheck.Type

Checks for the value to be of one of several types.

Creates an Either instance.

Parameters

types – list of types (or SpecialType subclasses)

Raises

ConstraintError if some of the contraints aren’t (typechecker) Types

types

Possible types

class temci.utils.typecheck.Exact(exp_value)[source]

Bases: temci.utils.typecheck.Type

Checks for value equivalence.

Creates an Exact object.

Parameters

exp_value – value to check for

exp_value

Expected value

class temci.utils.typecheck.ExactEither(*exp_values: tuple)[source]

Bases: temci.utils.typecheck.Type

Checks for the value to be of one of several exact values.

Creates an ExactEither instance.

Parameters

exp_values – list of types (or SpecialType subclasses)

Raises

ConstraintError if some of the contraints aren’t (typechecker) Types

exp_values

Expected values

class temci.utils.typecheck.FileName(constraint: Callable[[Any], bool] = None, allow_std: bool = False, allow_non_existent: bool = True)[source]

Bases: temci.utils.typecheck.Str

A valid file name. If the file doesn’t exist, at least the parent directory must exist and the file must be creatable.

Creates an instance.

Parameters
  • constraint – function that returns True if the user defined constraint is satisfied

  • allow_std – allow ‘-‘ as standard out or in

  • allow_non_existent – allow files that don’t exist

allow_non_existent

Allow files that don’t exist

allow_std

Allow ‘-‘ as standard out or in

completion_hints

Completion hints for supported shells for this type instance

constraint

Function that returns True if the user defined constraint is satisfied

temci.utils.typecheck.FileNameOrStdOut()temci.utils.typecheck.FileName[source]

A valid file name or “-” for standard out.

temci.utils.typecheck.Float(constraint: Callable[[Any], bool] = None) → Union[temci.utils.typecheck.T, temci.utils.typecheck.Constraint][source]

Alias for Constraint(constraint, T(float)) or T(float)

Parameters

constraint – function that returns True if the user defined constraint is satisfied

class temci.utils.typecheck.Info(value_name: str = None, value=None, _app_str: str = None)[source]

Bases: object

Information object that is used to produce meaningful type check error messages.

Creates a new info object.

Parameters
  • value_name – name of the value that is type checked

  • value – value that is type checked

add_to_name(app_str: str)temci.utils.typecheck.Info[source]

Creates a new info object based on this one with the given appendix to its value representation. It’s used to give information about what part of the main value is currently examined.

Parameters

app_str – app string appended to the own app string to create the app string for the new info object

Returns

new info object

errormsg(constraint: temci.utils.typecheck.Type, value, msg: str = None) → temci.utils.typecheck.InfoMsg[source]

Creates an info message object with the passed expected type and the optional message.

Parameters
  • constraint – passed expected type

  • value – value that violates th constraint

  • msg – additional message, it should give more information about why the constraint isn’t met

errormsg_cond(cond: bool, constraint: temci.utils.typecheck.Type, value, msg: str = None) → temci.utils.typecheck.InfoMsg[source]

Creates an info message object with the passed expected type and the optional message.

Parameters
  • cond – if this is false InfoMsg(True) is returned.

  • constraint – passed expected type

  • value – value that violates th constraint

  • msg – additional message, it should give more information about why the constraint isn’t met

errormsg_key_non_existent(constraint: temci.utils.typecheck.Type, key: str) → temci.utils.typecheck.InfoMsg[source]

Creates an info message object with the passed expected type that contains the message that currently examined part of the value is unexpected.

Parameters

constraint – passed expected type

errormsg_unexpected(key: str) → temci.utils.typecheck.InfoMsg[source]

Creates an info message object with the passed expected type that contains the message that currently examined part of the value has an unexpected key.

Parameters

key – the unexpected key

get_value()Any[source]

Get the main value of this object. :raises: ValueError if the main value isn’t set

has_value

Is the value property of this info object set to a meaningful value?

set_value(value)[source]

Set the main value of this object

value

Main value that is type checked

value_name

Name of the value that is typechecked

wrap(result: bool) → temci.utils.typecheck.InfoMsg[source]

Wrap the passed bool into a InfoMsg object.

class temci.utils.typecheck.Int(constraint: Callable[[Any], bool] = None, range: range = None, description: str = None)[source]

Bases: temci.utils.typecheck.Type

Checks for the value to be of type int and to adhere to some constraints.

Creates an instance.

Parameters
  • constraint – function that returns True if the user defined constraint is satisfied

  • range – range (or list) that the value has to be part of

  • description – description of the constraints

completion_hints

Completion hints for supported shells for this type instance

constraint

Function that returns True if the user defined constraint is satisfied

description

Description of the constraints

range

Range (or list) that the value has to be part of

class temci.utils.typecheck.List(elem_type: temci.utils.typecheck.Type = Any)[source]

Bases: temci.utils.typecheck.Type

Checks for the value to be a list with elements of a given type.

Creates a new instance.

Parameters

elem_type – type of the list elements

Raises

ConstraintError if elem_type isn’t a (typechecker) Types

elem_type

Expected type of the list elements

get_default()Any[source]

Returns the default value of this type :raises: ValueError if the default value isn’t set

get_default_yaml(indents: int = 0, indentation: int = 4, str_list: bool = False, defaults=None) → Union[str, List[str]][source]

Produce a YAML like string that contains the default value and the description of this type and its possible sub types.

Parameters
  • indents – number of indents in front of each produced line

  • indentation – indentation width in number of white spaces

  • str_list – return a list of lines instead of a combined string?

  • defaults – default value that should be used instead of the default value of this instance

class temci.utils.typecheck.ListOrTuple(elem_type: temci.utils.typecheck.Type = Any)[source]

Bases: temci.utils.typecheck.Type

Checks for the value to be a list or tuple with elements of a given type.

Creates an instance.

Parameters

elem_type – type of the list or tuple elements

Raises

ConstraintError if elem_type isn’t a (typechecker) Types

elem_type

Expected type of the list or tuple elements

temci.utils.typecheck.NaturalNumber(constraint: Callable[[Any], bool] = None)temci.utils.typecheck.Int[source]

Matches all natural numbers (ints >= 0) that satisfy the optional user defined constrained.

Parameters

constraint – function that returns True if the user defined constraint is satisfied

class temci.utils.typecheck.NonErrorConstraint(constraint: Callable[[Any], Any], error_cls: type, constrained_type: temci.utils.typecheck.Type = Any, description: str = None)[source]

Bases: temci.utils.typecheck.Type

Checks the passed value by an user defined constraint that fails if it raises an error.

Creates a new instance

Parameters
  • constraint – function that doesn’t raise an error if the user defined constraint is satisfied

  • error_cls – class of the errors the constraint method raises

  • constrained_type – Type that the constraint is applied on

  • description – short description of the constraint (e.g. “>0”)

Raises

ConstraintError if constrained_type isn’t a (typechecker) Types

constrained_type

Type that the constraint is applied on

constraint

Function that returns True if the user defined constraint is satisfied

description

Short description of the constraint (e.g. “>0”)

error_cls

Class of the errors the constraint method raises

class temci.utils.typecheck.NonExistent(completion_hints: Dict[str, Any] = None)[source]

Bases: temci.utils.typecheck.Type

Checks a key of a dictionary for existence if its associated value has this type.

Creates an instance.

Parameters

completion_hints – completion hints for supported shells for this type instance

class temci.utils.typecheck.Optional(other_type: temci.utils.typecheck.Type)[source]

Bases: temci.utils.typecheck.Either

Checks the value and checks that its either of native type None or of another Type constraint. Alias for Either(Exact(None), other_type)

Creates an Optional instance.

Parameters

other_type – type to make optional

Raises

ConstraintError if other_type isn’t a (typechecker) Types

temci.utils.typecheck.PositiveInt(constraint: Callable[[Any], bool] = None)temci.utils.typecheck.Int[source]

Matches all positive integers that satisfy the optional user defined constrained.

Parameters

constraint – function that returns True if the user defined constraint is satisfied

class temci.utils.typecheck.Str(constraint: Callable[[Any], bool] = None)[source]

Bases: temci.utils.typecheck.Type

Checks for the value to be a string an optionally meet some constraints.

Creates an instance.

Parameters

constraint – function that returns True if the user defined constraint is satisfied

constraint

Function that returns True if the user defined constraint is satisfied

class temci.utils.typecheck.StrList[source]

Bases: temci.utils.typecheck.Type, click.types.ParamType

A comma separated string list which contains elements from a fixed set of allowed values.

Creates an instance.

Parameters

completion_hints – completion hints for supported shells for this type instance

allowed_values

Possible values that can appear in the string list, if None all values are allowed.

convert(value, param, ctx: click.core.Context)List[str][source]

Convert method that makes this class usable as a click type.

get_default_yaml(indents: int = 0, indentation: int = 4, str_list: bool = False, defaults=None) → str[source]

Produce a YAML like string that contains the default value and the description of this type and its possible sub types.

Parameters
  • indents – number of indents in front of each produced line

  • indentation – indentation width in number of white spaces

  • str_list – return a list of lines instead of a combined string?

  • defaults – default value that should be used instead of the default value of this instance

name = 'comma_sep_str_list'

click.ParamType name, that makes this class usable as a click type

class temci.utils.typecheck.T(native_type: type)[source]

Bases: temci.utils.typecheck.Type

Wrapper around a native type.

Creates an isntance.

Parameters

native_type – wrapped native type

native_type

Native type that is wrapped

class temci.utils.typecheck.Tuple(*elem_types: Tuple[temci.utils.typecheck.Type])[source]

Bases: temci.utils.typecheck.Type

Checks for the value to be a tuple (or a list) with elements of the given types.

Creates a new instance.

Parameters

elem_types – types of each tuple element

Raises

ConstraintError if elem_type isn’t a (typechecker) Types

elem_types

Expected type of each tuple element

class temci.utils.typecheck.Type(completion_hints: Dict[str, Any] = None)[source]

Bases: object

A simple type checker type class.

Creates an instance.

Parameters

completion_hints – completion hints for supported shells for this type instance

completion_hints

Completion hints for supported shells for this type instance

default

Default value of this type instance

description

Description of this type instance

dont_typecheck_default()temci.utils.typecheck.Type[source]

Disable type checking the default value. :return: self

get_default()Any[source]

Returns the default value of this type :raises: ValueError if the default value isn’t set

get_default_yaml(indents: int = 0, indentation: int = 4, str_list: bool = False, defaults=None) → Union[str, List[str]][source]

Produce a YAML like string that contains the default value and the description of this type and its possible sub types.

Parameters
  • indents – number of indents in front of each produced line

  • indentation – indentation width in number of white spaces

  • str_list – return a list of lines instead of a combined string?

  • defaults – default value that should be used instead of the default value of this instance

has_default() → bool[source]

Does this type instance have an default value?

string_representation(indents: int = 0, indentation: int = 4, str_list: bool = False, defaults=None) → Union[str, List[str]][source]

Produce a YAML string that contains the default value (if possible), the description of this type and more and its possible sub types.

Parameters
  • indents – number of indents in front of each produced line

  • indentation – indentation width in number of white spaces

  • str_list – return a list of lines instead of a combined string?

  • defaults – default value that should be used instead of the default value of this instance

typecheck_default

Type check the default value

class temci.utils.typecheck.ValidTimeSpan[source]

Bases: temci.utils.typecheck.Type, click.types.ParamType

A string that is parseable as timespan by pytimeparse. E.g. “32m” or “2h 32m”.

Creates an instance.

Parameters

completion_hints – completion hints for supported shells for this type instance

convert(value, param, ctx: click.core.Context) → int[source]

Convert method that makes this class usable as a click type.

name = 'valid_timespan'

click.ParamType name, that makes this class usable as a click type

class temci.utils.typecheck.ValidYamlFileName(allow_non_existent: bool = False)[source]

Bases: temci.utils.typecheck.Str

A valid file name that refers to a valid YAML file.

Create an instance.

Parameters

allow_non_existent – allow files that don’t exist

allow_non_existent

Allow files that don’t exist

completion_hints

Completion hints for supported shells for this type instance

temci.utils.typecheck.YAML_FILE_COMPLETION_HINT = "_files -g '*\\.yaml'"

YAML file name completion hint for ZSH

temci.utils.typecheck.typecheck(value, type: Union[temci.utils.typecheck.Type, type], value_name: str = None)[source]

Like verbose_isinstance but raises an error if the value hasn’t the expected type.

Parameters
  • value – passed value

  • type – expected type of the value

  • value_name – optional description of the value

Raises

TypeError

temci.utils.typecheck.typecheck_locals(locals: Dict[str, Any] = None, **variables: Dict[str, Union[temci.utils.typecheck.Type, type]])[source]

Like typecheck but checks several variables for their associated expected type. The advantage against typecheck is that it sets the value descriptions properly. Example usage:

def func(a: str, b: int):
    typecheck_locals(locals(), a=Str(), b=Int())
Parameters
  • locals – directory to get the variable values from

  • variables – variable names with their associated expected types

Raises

TypeError

temci.utils.typecheck.verbose_isinstance(value, type: Union[temci.utils.typecheck.Type, type], value_name: str = None) → temci.utils.typecheck.InfoMsg[source]

Verbose version of isinstance that returns a InfoMsg object.

Parameters
  • value – value to check

  • type – type or Type to check for

  • value_name – name of the passed value (improves the error message)

temci.utils.util module

Utility functions and classes that don’t depend on the rest of the temci code base.

class temci.utils.util.InsertionTimeOrderedDict[source]

Bases: object

A dictionary which’s elements are sorted by their insertion time.

classmethod from_list(items: Optional[list], key_func: Callable[[Any], Any])temci.utils.util.InsertionTimeOrderedDict[source]

Creates an ordered dict out of a list of elements.

Parameters
  • items – list of elements

  • key_func – function that returns a key for each passed list element

Returns

created ordered dict with the elements in the same order as in the passed list

items() → List[Tuple[Any, Any]][source]
keys() → List[source]

Returns all keys of this dictionary. They are sorted by their insertion time.

values() → List[source]

Rerturns all values of this dictionary. They are sorted by their insertion time.

class temci.utils.util.Singleton[source]

Bases: type

Singleton meta class. @see http://stackoverflow.com/a/6798042

temci.utils.util.allow_all_imports = True

Allow all imports (should the can_import method return true for every module)?

temci.utils.util.can_import(module: str) → bool[source]

Can a module (like scipy or numpy) be imported without a severe and avoidable performance penalty? The rational behind this is that some parts of temci don’t need scipy or numpy.

Parameters

module – name of the module

temci.utils.util.document(**kwargs: Dict[str, str])[source]

Document

Parameters

kwargs – class attribute, documentation prefix

temci.utils.util.does_command_succeed(cmd: str) → bool[source]

Does the passed command succeed (when executed by /bin/sh)?

temci.utils.util.does_program_exist(program: str) → bool[source]

Does the passed program exist?

temci.utils.util.geom_std(values: List[float]) → float[source]

Calculates the geometric standard deviation for the passed values. Source: https://en.wikipedia.org/wiki/Geometric_standard_deviation

temci.utils.util.get_cache_line_size(cache_level: int = None) → Optional[int][source]

Returns the cache line size of the cache on the given level. Level 0 and 1 are actually on the same level.

Parameters

cache_level – if None the highest level cache is used

Returns

cache line size or none if the cache on the given level doesn’t exist

temci.utils.util.get_distribution_name() → str[source]

Returns the name of the current linux distribution (requires lsb_release to be installed)

temci.utils.util.get_distribution_release() → str[source]

Returns the used release of the current linux distribution (requires lsb_release to be installed)

temci.utils.util.get_doc_for_type_scheme(type_scheme: Type) → str[source]

Return a class documentation string for the given type scheme. Use the default_yaml method.

temci.utils.util.get_memory_page_size() → int[source]

Returns the size of a main memory page

temci.utils.util.handler = <RainbowLoggingHandler <stderr> (NOTSET)>

Colored logging handler that is used for the root logger

temci.utils.util.has_pdflatex() → bool[source]

Is pdflatex installed?

temci.utils.util.has_root_privileges() → bool[source]

Has the current user root privileges?

temci.utils.util.in_standalone_mode = False

In rudimentary standalone mode (executed via run.py)

temci.utils.util.join_strs(strs: List[str], last_word: str = 'and') → str[source]

Joins the passed strings together with “, ” except for the last to strings that separated by the passed word.

Parameters
  • strs – strings to join

  • last_word – passed word that is used between the two last strings

temci.utils.util.on_apple_os() → bool[source]

Is the current operating system an apple OS X?

temci.utils.util.parse_timespan(time: str) → float[source]

Parse a time span expression, see https://pypi.org/project/pytimeparse/

Supports -1 to express an infinite time span

Parameters

time – time span expression, mixture of different time units is possible

Returns

time span in seconds

class temci.utils.util.proc_wait_with_rusage[source]

Bases: object

Each Popen object gets a field rusage

temci.utils.util.recursive_exec_for_leafs(data: dict, func, _path_prep=[])[source]

Executes the function for every leaf key (a key without any sub keys) of the data dict tree.

Parameters
  • data – dict tree

  • func – function that gets passed the leaf key, the key path and the actual value

temci.utils.util.rusage_header() → str[source]
temci.utils.util.sphinx_doc() → bool[source]

Is the code only loaded to document it with sphinx?

temci.utils.util.warn_for_pdflatex_non_existence_once(_warned=[False])[source]

Log a warning if the pdflatex isn’t available, but only if this function is called the first time

temci.utils.vcs module

Module contents

Package with utility modules.