示例#1
0
 def __init__(self, method):
     super().__init__(
         'Call to abstract method {class_name}.{method_name}(...): missing implementation.'.format(
             class_name=get_name(method.__self__),
             method_name=get_name(method),
         )
     )
示例#2
0
文件: errors.py 项目: tate11/bonobo
 def __init__(self, method):
     super().__init__(
         'Call to abstract method {class_name}.{method_name}(...): missing implementation.'
         .format(
             class_name=get_name(method.__self__),
             method_name=get_name(method),
         ))
示例#3
0
 def register_group(self, *args, check=None):
     check = set(check) if check else None
     for attr in args:
         self.register(attr)
         if check:
             check.remove(get_name(attr))
     assert not (check and len(check))
示例#4
0
 def register_group(self, *args, check=None):
     check = set(check) if check else None
     for attr in args:
         self.register(attr)
         if check:
             check.remove(get_name(attr))
     assert not (check and len(check))
示例#5
0
 def print_tree(self, i, level=0):
     g = self.graph
     node = g[i]
     name = get_name(node)
     indent = '  ' * level
     print(f'{indent}{name}')
     for j in g.outputs_of(i):
         self.print_tree(j, level=level + 1)
示例#6
0
    def run_node(self, i, input, level=0):
        g = self.graph
        node = g[i]
        name = get_name(node)
        self.tick_in(i, name, level)
        indent = '  ' * level
        services = {k: v for k, v in self.service_bindings[i] if v is not None}
        for k in self.runtime_bindings[i]:
            s = getattr(node, k)
            services[k] = self.services[s]

        if services:
            # print(f'*** binding services: {services}')
            node = partial(node, **services)

# 		if services:
# 			print(f'{indent}{name} {services.keys()}')
# 		else:
# 			print(f'{indent}{name}')

        try:
            # print(f'calling {node!r}({input})')
            start = time.time()
            if input is None:
                result = node()
            else:
                result = node(input)
            end = time.time()
            elapsed = end - start
            self.timers[(i, level, name)] += elapsed

            if result == NOT_MODIFIED:
                result = input

            if isinstance(result, types.GeneratorType):
                #print('RESULT IS A GENERATOR')
                for r in result:
                    self.tick_out(i, name, level)
                    #print(f'[{name}] =gen=> {r}')
                    for j in g.outputs_of(i):
                        self.run_node(j, r, level=level + 1)
            else:
                self.tick_out(i, name, level)
                #print(f'RESULT IS {result}')
                #print(f'[{name}] =ret=> {result}')
                for j in g.outputs_of(i):
                    self.run_node(j, result, level=level + 1)
        except Exception as e:
            print(f'**** ERROR running {node}: {e!r}')
            traceback.print_exc()
示例#7
0
 def graphviz(self):
     try:
         return self._graphviz
     except AttributeError:
         g = Digraph()
         g.attr(rankdir='LR')
         g.node('BEGIN', shape='point')
         for i in self.outputs_of(BEGIN):
             g.edge('BEGIN', str(i))
         for ix in self.topologically_sorted_indexes:
             g.node(str(ix), label=get_name(self[ix]))
             for iy in self.outputs_of(ix):
                 g.edge(str(ix), str(iy))
         self._graphviz = g
         return self._graphviz
示例#8
0
 def graphviz(self):
     try:
         return self._graphviz
     except AttributeError:
         g = Digraph()
         g.attr(rankdir='LR')
         g.node('BEGIN', shape='point')
         for i in self.outputs_of(BEGIN):
             g.edge('BEGIN', str(i))
         for ix in self.topologically_sorted_indexes:
             g.node(str(ix), label=get_name(self[ix]))
             for iy in self.outputs_of(ix):
                 g.edge(str(ix), str(iy))
         self._graphviz = g
         return self._graphviz
示例#9
0
文件: api.py 项目: tate11/bonobo
    def register(self, x, graph=False):
        """Register a function as being part of an API, then returns the original function."""

        if graph:
            # This function must comply to the "graph" API interface, meaning it can bahave like bonobo.run.
            from inspect import signature
            parameters = list(signature(x).parameters)
            required_parameters = {'plugins', 'services', 'strategy'}
            assert len(parameters) > 0 and parameters[
                0] == 'graph', 'First parameter of a graph api function must be "graph".'
            assert required_parameters.intersection(
                parameters
            ) == required_parameters, 'Graph api functions must define the following parameters: ' + ', '.join(
                sorted(required_parameters))

        self.__all__.append(get_name(x))
        return x
示例#10
0
    def register(self, x, graph=False):
        """Register a function as being part of an API, then returns the original function."""

        if graph:
            # This function must comply to the "graph" API interface, meaning it can bahave like bonobo.run.
            from inspect import signature
            parameters = list(signature(x).parameters)
            required_parameters = {'plugins', 'services', 'strategy'}
            assert len(parameters
                       ) > 0 and parameters[0] == 'graph', 'First parameter of a graph api function must be "graph".'
            assert required_parameters.intersection(
                parameters
            ) == required_parameters, 'Graph api functions must define the following parameters: ' + ', '.join(
                sorted(required_parameters)
            )

        self.__all__.append(get_name(x))
        return x
示例#11
0
    def __init__(cls, what, bases=None, dict=None):
        super().__init__(what, bases, dict)

        cls.__processors = sortedlist()
        cls.__processors_cache = None
        cls.__methods = sortedlist()
        cls.__options = sortedlist()
        cls.__names = set()

        # cls.__kwoptions = []

        for typ in cls.__mro__:
            for name, value in filter(lambda x: isoption(x[1]), typ.__dict__.items()):
                if iscontextprocessor(value):
                    cls.__processors.insort((value._creation_counter, value))
                    continue

                if not value.name:
                    value.name = name

                if not name in cls.__names:
                    cls.__names.add(name)
                    cls.__options.insort((not value.positional, value._creation_counter, name, value))

        # Docstring formating
        _options_doc = []
        for _positional, _counter, _name, _value in cls.__options:
            _param = _name
            if _value.type:
                _param = get_name(_value.type) + ' ' + _param

            prefix = ':param {}: '.format(_param)
            for lineno, line in enumerate((_value.__doc__ or '').split('\n')):
                _options_doc.append((' ' * len(prefix) if lineno else prefix) + line)
        cls.__doc__ = '\n\n'.join(
            map(
                str.strip,
                filter(None, (
                    cls.__doc__,
                    '\n'.join(_options_doc)
                ))
            )
        )
示例#12
0
def register_api(x, __all__=__all__):
    __all__.append(get_name(x))
    return x
示例#13
0
def _get_graphviz_node_id(graph, i):
    escaped_index = str(i)
    escaped_name = json.dumps(get_name(graph[i]))
    return '{{{} [label={}]}}'.format(escaped_index, escaped_name)
示例#14
0
 def do_handle(self, graph, **options):
     if not self.handler:
         raise RuntimeError("{} has no handler defined.".format(get_name(self)))
     return self.handler(graph, **options)
示例#15
0
 def logger(self):
     try:
         return self._logger
     except AttributeError:
         self._logger = logging.getLogger(get_name(self))
         return self._logger
示例#16
0
文件: functools.py 项目: zkan/bonobo
 def __name__(self):
     return get_name(self.func)
示例#17
0
def _get_graphviz_node_id(graph, i):
    escaped_index = str(i)
    escaped_name = json.dumps(get_name(graph[i]))
    return '{{{} [label={}]}}'.format(escaped_index, escaped_name)
示例#18
0
 def logger(self):
     try:
         return self._logger
     except AttributeError:
         self._logger = logging.getLogger(get_name(self))
         return self._logger
示例#19
0
def test_create_container_empty_values(services):
    c = create_container(services)
    assert len(c) == 2
    assert 'fs' in c and get_name(c['fs']) == 'OSFS'
    assert 'http' in c and get_name(c['http']) == 'requests'
示例#20
0
 def do_handle(self, graph, **options):
     if not self.handler:
         raise RuntimeError('{} has no handler defined.'.format(get_name(self)))
     return self.handler(graph, **options)
示例#21
0
def test_create_container_empty_values(services):
    c = create_container(services)
    assert len(c) == 2
    assert "fs" in c and get_name(c["fs"]) == "OSFS"
    assert "http" in c and get_name(c["http"]) == "requests"
示例#22
0
 def __repr__(self):
     name, type_name = get_name(self), get_name(type(self))
     return '<{}({}{}){}>'.format(type_name, self.status, name,
                                  self.get_statistics_as_string(prefix=' '))
示例#23
0
文件: executor.py 项目: zkan/bonobo
 def __init__(self, GraphExecutionContextType=None):
     if not settings.ALPHA.get():
         raise NotImplementedError(
             "{} is experimental, you need to explicitely activate it using ALPHA=True in system env."
             .format(get_name(self)))
     super().__init__(GraphExecutionContextType)