|
1 | | -from typing import Any, Callable |
2 | | -from abc import ABC |
| 1 | +from typing import Any |
3 | 2 |
|
4 | | -from .callback import Callback, Output, Input |
5 | | - |
6 | | - |
7 | | -class Contribution(ABC): |
8 | | - # noinspection PyShadowingBuiltins |
9 | | - def __init__(self, name: str): |
10 | | - self.name = name |
11 | | - self.extension: Extension | None = None |
12 | | - self.layout_callback: Callback | None = None |
13 | | - self.callbacks: list[Callback] = [] |
14 | | - |
15 | | - def to_dict(self) -> dict[str, Any]: |
16 | | - d = dict(name=self.name) |
17 | | - if self.extension is not None: |
18 | | - d.update(extension=self.extension.name) |
19 | | - if self.layout_callback is not None: |
20 | | - d.update(layout=self.layout_callback.to_dict()) |
21 | | - if self.callbacks: |
22 | | - d.update(callbacks=[cb.to_dict() for cb in self.callbacks]) |
23 | | - return d |
24 | | - |
25 | | - def layout(self, *args) -> Callable: |
26 | | - """Decorator.""" |
27 | | - |
28 | | - def decorator(function: Callable) -> Callable: |
29 | | - self.layout_callback = Callback.from_decorator( |
30 | | - "layout", args, function, outputs_allowed=False |
31 | | - ) |
32 | | - return function |
33 | | - |
34 | | - return decorator |
35 | | - |
36 | | - def callback(self, *args: Input | Output) -> Callable[[Callable], Callable]: |
37 | | - """Decorator.""" |
38 | | - |
39 | | - def decorator(function: Callable) -> Callable: |
40 | | - self.callbacks.append( |
41 | | - Callback.from_decorator( |
42 | | - "callback", args, function, outputs_allowed=True |
43 | | - ) |
44 | | - ) |
45 | | - return function |
46 | | - |
47 | | - return decorator |
48 | | - |
49 | | - def __str__(self): |
50 | | - return self.name |
| 3 | +from dashipy.lib.contribution import Contribution |
51 | 4 |
|
52 | 5 |
|
53 | 6 | class Extension: |
@@ -79,7 +32,7 @@ def add(self, contribution: Contribution): |
79 | 32 | raise TypeError( |
80 | 33 | f"unrecognized contribution of type {contrib_type.__qualname__}" |
81 | 34 | ) |
82 | | - contribution.extension = self |
| 35 | + contribution.extension = self.name |
83 | 36 | contributions: list[Contribution] = getattr(self, contrib_point_name) |
84 | 37 | contributions.append(contribution) |
85 | 38 |
|
|
0 commit comments