reliure¶
-
class
reliure.Composable(func=None, name=None)¶ Bases:
objectBasic composable element
Composable is abstract, you need to implemented the
__call__()method>>> e1 = Composable(lambda element: element**2, name="e1") >>> e2 = Composable(lambda element: element + 10, name="e2")
Then
Composablecan be pipelined this way :>>> chain = e1 | e2 >>> # so yo got: >>> chain(2) 14 >>> # which is equivalent to : >>> e2(e1(2)) 14 >>> # not that by defaut the pipeline agregate the components name >>> chain.name 'e1|e2' >>> # however you can override it >>> chain.name = "chain" >>> chain.name 'chain'
It also possible to ‘map’ the composables >>> cmap = e1 & e2 >>> # so you got: >>> cmap(2) [4, 12]
-
__call__(*args, **kwargs)¶
-
__init__(func=None, name=None)¶ You can create a
Composablefrom a simple function:>>> def square(val, pow=2): ... return val ** pow >>> cfct = Composable(square) >>> cfct.name 'square' >>> cfct(2) 4 >>> cfct(3, 3) 27
-
init_logger(reinit=False)¶
-
logger¶
-
name¶ Name of the optionable component
-
-
class
reliure.Optionable(name=None)¶ Bases:
reliure.pipeline.ComposableAbstract class for an optionable component
-
__init__(name=None)¶ Parameters: name (str) – name of the component
-
add_option(opt_name, otype, hidden=False)¶ Add an option to the object
Parameters: - opt_name (str) – option name
- otype (subclass of
GenericType) – option type - hidden (bool) – if True the option will be hidden
-
change_option_default(opt_name, default_val)¶ Change the default value of an option
Parameters: - opt_name (str) – option name
- value – new default option value
-
static
check(call_fct)¶ Decorator for optionable __call__ method It check the given option values
-
clear_option_value(opt_name)¶ Clear the stored option value (so the default will be used)
Parameters: opt_name (str) – option name
-
clear_options_values()¶ Clear all stored option values (so the defaults will be used)
-
force_option_value(opt_name, value)¶ force the (default) value of an option. The option is then no more listed by
get_options().Parameters: - opt_name (str) – option name
- value – option value
-
get_option_default(opt_name)¶ Return the default value of a given option
Parameters: opt_name (str) – option name Returns: the default value of the option
-
get_option_value(opt_name)¶ Return the value of a given option
Parameters: opt_name (str) – option name Returns: the value of the option
-
get_options(hidden=False)¶ Parameters: hidden (bool) – whether to return hidden options Returns: dictionary of all options (with option’s information) Return type: dict
-
get_options_values(hidden=False)¶ return a dictionary of options values
Parameters: hidden (bool) – whether to return hidden options Returns: dictionary of all option values Return type: dict
-
get_ordered_options(hidden=False)¶ Parameters: hidden (bool) – whether to return hidden option Returns: ordered list of options pre-serialised (as_dict) Return type: list [opt_dict, ...]
-
has_option(opt_name)¶ Whether the component have a given option
Whether the given option is hidden
-
options¶
-
parse_options(option_values)¶ Set the options (with parsing) and returns a dict of all options values
-
print_options()¶ print description of the component options
-
set_option_value(opt_name, value, parse=False)¶ Set the value of one option.
- # TODO/FIXME
- add force/hide argument
- add default argument
- remove methods force option value
- remove change_option_default
Parameters: - opt_name (str) – option name
- value – the new value
- parse (bool) – if True the value is converted from string to the correct type
-
set_options_values(options, parse=False, strict=False)¶ Set the options from a dict of values (in string).
Parameters: - option_values (dict) – the values of options (in format {“opt_name”: “new_value”})
- parse (bool) – whether to parse the given value
- strict (bool) – if True the given option_values dict should only contains existing options (no other key)
-
-
class
reliure.Map(comp, as_list=False)¶ Bases:
reliure.pipeline.OptionableSequenceApply a composable to each element of an generator like input.
>>> item_process = Composable(lambda x: x+2) | Composable(lambda x: x if x > 3 else 0) >>> flux_process = Map(item_process) >>> >>> inputs = range(5) >>> [e for e in flux_process(inputs)] [0, 0, 4, 5, 6]
-
__call__(*args, **kwargs)¶
-
__init__(comp, as_list=False)¶
-