‘configuration_support’ module

See also

Please see Configuring the project for more examples and detailed explanation

_universum.configuration_support

combine(dictionary_a, dictionary_b)[source]

Combine two dictionaries using plus operator for matching keys

Parameters:
  • dictionary_a – may have any keys and values
  • dictionary_b – may have any keys, but the values of keys, matching dictionary_a, should be the same type
Returns:

new dictionary containing all keys from both dictionary_a and dictionary_b; for each matching key the value in resulting dictionary is a sum of two corresponding values

For example:

>>> combine(dict(attr_a = "a1", attr_b = ["b11", "b12"]), dict(attr_a = "a2", attr_b = ["b2"]))
{'attr_b': ['b11', 'b12', 'b2'], 'attr_a': 'a1a2'}
>>> combine(dict(attr_a = {"a1": "v1"}, attr_b = {"b1": "v1"}), dict(attr_a = {"a2": "v2"}))
{'attr_b': {'b1': 'v1'}, 'attr_a': {'a1': 'v1', 'a2': 'v2'}}
class Variations[source]

Variations is a class for establishing project configurations. This class object is a list of dictionaries:

>>> v1 = Variations([{"field1": "string"}])
>>> v1
[{'field1': 'string'}]

Build-in method all() generates iterable for all configuration dictionaries for further usage:

>>> for i in v1.all(): i
{'field1': 'string'}

Built-in method dump() will generate a printable string representation of the object. This string will be printed into console output

>>> v1.dump()
"[{'field1': 'string'}]"

Adding two objects will extend list of dictionaries:

>>> v2 = Variations([{"field1": "line"}])
>>> for i in (v1 + v2).all(): i
{'field1': 'string'}
{'field1': 'line'}

While multiplying them will combine same fields of dictionaries:

>>> for i in (v1 * v2).all(): i
{'field1': 'stringline'}

When a field value is a list itself -

>>> v3 = Variations([dict(field2=["string"])])
>>> v4 = Variations([dict(field2=["line"])])

multiplying them will extend the inner list:

>>> for i in (v3 * v4).all(): i
{'field2': ['string', 'line']}
__add__(other)[source]

This functions defines operator + for Variations class objects by concatenating lists of dictionaries into one list. The order of list members in resulting list is preserved: first all dictionaries from self, then all dictionaries from other.

Parameters:otherVariations object to be added to self
Returns:new Variations object, including all configurations from both self and other objects
__mul__(other)[source]

This functions defines operator * for Variations class objects. The resulting object is created by combining every self list member with every other list member using combine() function.

Parameters:otherVariations object to be multiplied to self
Returns:new Variations object, consisting of the list of combined configurations
all()[source]

Function for configuration iterating.

Returns:iterable for all dictionary objects in Variations list
dump(produce_string_command=True)[source]

Function for Variations objects pretty printing.

Parameters:produce_string_command – if set to False, prints “command” as list instead of string
Returns:a user-friendly string representation of all configurations list
filter(checker, parent=None)[source]

This function is supposed to be called from main script, not configuration file. It uses provided checker to find all the configurations that pass the check, removing those not matching conditions.

Parameters:
  • checker – a function that returns True if configuration passes the filter and False otherwise
  • parent – an inner parameter for recursive usage; should be None when function is called from outside
Returns:

new Variations object without configurations not matching checker conditions

set_project_root(project_root)[source]

Function to be called from main script; not supposed to be used in configuration file. Stores generated project location for further usage. This function is needed because project sources most likely will be copied to a temporary directory of some automatically generated location and the CI run will be performed there.

Parameters:project_root – path to actual project root
get_project_root()[source]

Function to be used in configuration file. Inserts actual project location after that location is generated. If project root is not set, function returns current directory.

Returns:actual project root