Merge branch 'better_errors' of github.com:hartym/bonobo into better_errors
This commit is contained in:
@ -148,3 +148,11 @@ class GraphExecutionContext(BaseContext):
|
|||||||
def unregister_plugins(self):
|
def unregister_plugins(self):
|
||||||
for plugin_context in self.plugins:
|
for plugin_context in self.plugins:
|
||||||
plugin_context.unregister()
|
plugin_context.unregister()
|
||||||
|
|
||||||
|
|
||||||
|
@property
|
||||||
|
def xstatus(self):
|
||||||
|
"""
|
||||||
|
UNIX-like exit status, only coherent if the context has stopped.
|
||||||
|
"""
|
||||||
|
return max(node.xstatus for node in self.nodes)
|
||||||
|
|||||||
@ -123,8 +123,6 @@ class NodeExecutionContext(BaseContext, WithStatistics):
|
|||||||
self.step()
|
self.step()
|
||||||
except InactiveReadableError:
|
except InactiveReadableError:
|
||||||
break
|
break
|
||||||
except Empty:
|
|
||||||
sleep(TICK_PERIOD) # XXX: How do we determine this constant?
|
|
||||||
|
|
||||||
logger.debug('Node loop ends for {!r}.'.format(self))
|
logger.debug('Node loop ends for {!r}.'.format(self))
|
||||||
|
|
||||||
@ -133,6 +131,8 @@ class NodeExecutionContext(BaseContext, WithStatistics):
|
|||||||
self._step()
|
self._step()
|
||||||
except InactiveReadableError:
|
except InactiveReadableError:
|
||||||
raise
|
raise
|
||||||
|
except Empty:
|
||||||
|
sleep(TICK_PERIOD) # XXX: How do we determine this constant?
|
||||||
except (
|
except (
|
||||||
NotImplementedError,
|
NotImplementedError,
|
||||||
UnrecoverableError,
|
UnrecoverableError,
|
||||||
@ -294,12 +294,18 @@ class NodeExecutionContext(BaseContext, WithStatistics):
|
|||||||
# Store or check input type
|
# Store or check input type
|
||||||
if self._input_type is None:
|
if self._input_type is None:
|
||||||
self._input_type = type(input_bag)
|
self._input_type = type(input_bag)
|
||||||
elif type(input_bag) is not self._input_type:
|
elif type(input_bag) != self._input_type:
|
||||||
raise UnrecoverableTypeError(
|
try:
|
||||||
'Input type changed between calls to {!r}.\nGot {!r} which is not of type {!r}.'.format(
|
if self._input_type == tuple:
|
||||||
self.wrapped, input_bag, self._input_type
|
input_bag = self._input_type(input_bag)
|
||||||
)
|
else:
|
||||||
)
|
input_bag = self._input_type(*input_bag)
|
||||||
|
except Exception as exc:
|
||||||
|
raise UnrecoverableTypeError(
|
||||||
|
'Input type changed to incompatible type between calls to {!r}.\nGot {!r} which is not of type {!r}.'.format(
|
||||||
|
self.wrapped, input_bag, self._input_type
|
||||||
|
)
|
||||||
|
) from exc
|
||||||
|
|
||||||
# Store or check input length, which is a soft fallback in case we're just using tuples
|
# Store or check input length, which is a soft fallback in case we're just using tuples
|
||||||
if self._input_length is None:
|
if self._input_length is None:
|
||||||
|
|||||||
16
bonobo/nodes/aggregation.py
Normal file
16
bonobo/nodes/aggregation.py
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
from bonobo.config import Configurable, Method, Option, ContextProcessor, use_raw_input
|
||||||
|
from bonobo.util import ValueHolder
|
||||||
|
|
||||||
|
|
||||||
|
class Reduce(Configurable):
|
||||||
|
function = Method()
|
||||||
|
initializer = Option(required=False)
|
||||||
|
|
||||||
|
@ContextProcessor
|
||||||
|
def buffer(self, context):
|
||||||
|
values = yield ValueHolder(self.initializer() if callable(self.initializer) else self.initializer)
|
||||||
|
context.send(values.get())
|
||||||
|
|
||||||
|
@use_raw_input
|
||||||
|
def __call__(self, values, bag):
|
||||||
|
values.set(self.function(values.get(), bag))
|
||||||
Reference in New Issue
Block a user