Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.

Commit 6b4b2ae

Browse files
4.0.0 refactoring - architecture updates
1 parent e79d628 commit 6b4b2ae

30 files changed

Lines changed: 945 additions & 748 deletions

multibar/__init__.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from .api import *
2+
from .impl import *
3+
4+
__all__ = (
5+
"CalculationServiceAware",
6+
"ProgressbarClientAware",
7+
"ContractAware",
8+
"ContractCheck",
9+
"ContractManagerAware",
10+
"HookSignatureType",
11+
"HooksAware",
12+
"ProgressbarAware",
13+
"SectorAware",
14+
"SignatureSegmentProtocol",
15+
"ProgressbarSignatureProtocol",
16+
"ProgressbarWriterAware",
17+
"ProgressbarCalculationService",
18+
"ProgressbarClient",
19+
"ContractManager",
20+
"WriteProgressContract",
21+
"Hooks",
22+
"WRITER_HOOKS",
23+
"Progressbar",
24+
"Sector",
25+
"Signature",
26+
"SignatureSegment",
27+
"ProgressbarWriter",
28+
)

multibar/api/__init__.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from .calculation_service import *
2+
from .clients import *
3+
from .contracts import *
4+
from .hooks import *
5+
from .progressbars import *
6+
from .sectors import *
7+
from .signatures import *
8+
from .writers import *
9+
10+
__all__ = (
11+
"CalculationServiceAware",
12+
"ProgressbarClientAware",
13+
"ContractAware",
14+
"ContractCheck",
15+
"ContractManagerAware",
16+
"HookSignatureType",
17+
"HooksAware",
18+
"ProgressbarAware",
19+
"SectorAware",
20+
"SignatureSegmentProtocol",
21+
"ProgressbarSignatureProtocol",
22+
"ProgressbarWriterAware",
23+
)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
__all__ = ("CalculationServiceAware",)
2+
3+
import abc
4+
import typing
5+
6+
from .. import iterators
7+
8+
9+
class CalculationServiceAware(abc.ABC):
10+
__slots__ = ()
11+
12+
@abc.abstractmethod
13+
def calculate_filled_indexes(self) -> iterators.AbstractIterator[int]:
14+
...
15+
16+
@abc.abstractmethod
17+
def calculate_unfilled_indexes(self) -> iterators.AbstractIterator[int]:
18+
...
19+
20+
@property
21+
@abc.abstractmethod
22+
def progressbar_length(self) -> int:
23+
...
24+
25+
@property
26+
@abc.abstractmethod
27+
def progress_percents(self) -> float:
28+
...
29+
30+
@property
31+
@abc.abstractmethod
32+
def start_value(self) -> typing.Union[int, float]:
33+
...
34+
35+
@property
36+
@abc.abstractmethod
37+
def end_value(self) -> typing.Union[int, float]:
38+
...
39+
40+
@staticmethod
41+
@abc.abstractmethod
42+
def get_progress_percentage(start: int, end: int, /) -> float:
43+
...

multibar/api/clients.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
from __future__ import annotations
2+
3+
__all__ = ("ProgressbarClientAware",)
4+
5+
import abc
6+
import typing
7+
8+
from . import contracts
9+
from . import hooks as hooks_
10+
11+
if typing.TYPE_CHECKING:
12+
from multibar.api import progressbars
13+
from multibar.api import sectors
14+
15+
16+
class ProgressbarClientAware(abc.ABC):
17+
@abc.abstractmethod
18+
@typing.overload
19+
def get_progress(
20+
self,
21+
start_value: int,
22+
end_value: int,
23+
/,
24+
) -> typing.Optional[progressbars.ProgressbarAware[sectors.SectorAware]]:
25+
...
26+
27+
@abc.abstractmethod
28+
@typing.overload
29+
def get_progress(
30+
self,
31+
start_value: int,
32+
end_value: int,
33+
/,
34+
*,
35+
length: int,
36+
) -> typing.Optional[progressbars.ProgressbarAware[sectors.SectorAware]]:
37+
...
38+
39+
@abc.abstractmethod
40+
def get_progress(
41+
self,
42+
start_value: int,
43+
end_value: int,
44+
/,
45+
*,
46+
length: int = 20,
47+
) -> typing.Optional[progressbars.ProgressbarAware[sectors.SectorAware]]:
48+
...
49+
50+
@abc.abstractmethod
51+
def set_hooks(self, hooks: hooks_.HooksAware) -> ProgressbarClientAware:
52+
...
53+
54+
@abc.abstractmethod
55+
def update_hooks(self, hooks: hooks_.HooksAware) -> ProgressbarClientAware:
56+
...
57+
58+
@property
59+
@abc.abstractmethod
60+
def hooks(self) -> hooks_.HooksAware:
61+
...
62+
63+
@property
64+
@abc.abstractmethod
65+
def contract_manager(self) -> contracts.ContractManagerAware:
66+
...

multibar/api/contracts.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
from __future__ import annotations
2+
3+
__all__ = ("ContractAware", "ContractCheck", "ContractManagerAware",)
4+
5+
import abc
6+
import typing
7+
import dataclasses
8+
9+
from .. import utils
10+
11+
12+
@dataclasses.dataclass
13+
class ContractCheck:
14+
kept: bool
15+
metadata: dict[str, typing.Any] = dataclasses.field(default_factory=dict)
16+
warnings: list[str] = dataclasses.field(default_factory=list)
17+
errors: list[str] = dataclasses.field(default_factory=list)
18+
19+
@classmethod
20+
def done(
21+
cls,
22+
metadata: typing.Optional[dict[str, typing.Any]] = None,
23+
) -> ContractCheck:
24+
return cls(kept=True, metadata=utils.none_or({}, metadata))
25+
26+
@classmethod
27+
def terminated(
28+
cls,
29+
metadata: typing.Optional[dict[str, typing.Any]] = None,
30+
warnings: typing.Optional[list[str]] = None,
31+
errors: typing.Optional[list[str]] = None,
32+
) -> ContractCheck:
33+
return cls(
34+
kept=False,
35+
metadata=utils.none_or({}, metadata),
36+
warnings=utils.none_or([], warnings),
37+
errors=utils.none_or([], errors),
38+
)
39+
40+
41+
class ContractAware(abc.ABC):
42+
__slots__ = ()
43+
44+
@abc.abstractmethod
45+
def check(self, *args: typing.Any, **kwargs: typing.Any) -> ContractCheck:
46+
...
47+
48+
@abc.abstractmethod
49+
def render_terminated_contract(self, check: ContractCheck, /, *, raise_errors: bool) -> None:
50+
...
51+
52+
53+
class ContractManagerAware(abc.ABC):
54+
__slots__ = ()
55+
56+
@abc.abstractmethod
57+
def trigger_contract(
58+
self,
59+
contract: ContractAware,
60+
*args: typing.Any,
61+
**kwargs: typing.Any,
62+
) -> None:
63+
...
64+
65+
@abc.abstractmethod
66+
def trigger_contracts(self, *args: typing.Any, **kwargs: typing.Any) -> None:
67+
...
68+
69+
@abc.abstractmethod
70+
def subscribe(self, contract: ContractAware, /) -> None:
71+
...
72+
73+
@abc.abstractmethod
74+
def terminate(self, contract: ContractAware, /) -> None:
75+
...
76+
77+
@abc.abstractmethod
78+
def set_raise_errors(self, value: bool, /) -> None:
79+
...
80+
81+
@property
82+
@abc.abstractmethod
83+
def contracts(self) -> list[ContractAware]:
84+
...

multibar/api/hooks.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
from __future__ import annotations
2+
3+
__all__ = ("HookSignatureType", "HooksAware",)
4+
5+
import abc
6+
import typing
7+
8+
if typing.TYPE_CHECKING:
9+
from . import clients
10+
11+
HookSignatureType: typing.TypeAlias = typing.Callable[..., typing.Optional[bool]]
12+
13+
14+
class HooksAware(abc.ABC):
15+
__slots__ = ()
16+
17+
def __or__(self, other: typing.Any) -> typing.Any:
18+
if not isinstance(other, HooksAware):
19+
return NotImplemented
20+
21+
self.on_error_hooks.extend(other.on_error_hooks)
22+
self.post_execution_hooks.extend(other.post_execution_hooks)
23+
self.pre_execution_hooks.extend(other.pre_execution_hooks)
24+
25+
return self
26+
27+
@abc.abstractmethod
28+
def add_to_client(self, writer: clients.ProgressbarClientAware, /) -> HooksAware:
29+
...
30+
31+
@abc.abstractmethod
32+
def add_pre_execution(self, callback: HookSignatureType, /) -> HooksAware:
33+
...
34+
35+
@abc.abstractmethod
36+
def add_post_execution(self, callback: HookSignatureType, /) -> HooksAware:
37+
...
38+
39+
@abc.abstractmethod
40+
def add_on_error(self, callback: HookSignatureType, /) -> HooksAware:
41+
...
42+
43+
@abc.abstractmethod
44+
def trigger_post_execution(self, *args: typing.Any, **kwargs: typing.Any) -> None:
45+
...
46+
47+
@abc.abstractmethod
48+
def trigger_pre_execution(self, *args: typing.Any, **kwargs: typing.Any) -> None:
49+
...
50+
51+
@abc.abstractmethod
52+
def trigger_on_error(self, *args: typing.Any, **kwargs: typing.Any) -> None:
53+
...
54+
55+
@property
56+
@abc.abstractmethod
57+
def pre_execution_hooks(self) -> list[HookSignatureType]:
58+
...
59+
60+
@property
61+
@abc.abstractmethod
62+
def post_execution_hooks(self) -> list[HookSignatureType]:
63+
...
64+
65+
@property
66+
@abc.abstractmethod
67+
def on_error_hooks(self) -> list[HookSignatureType]:
68+
...

multibar/api/progressbars.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from __future__ import annotations
2+
3+
__all__ = ("ProgressbarAware",)
4+
5+
import abc
6+
import typing
7+
8+
from . import sectors
9+
10+
SectorT = typing.TypeVar("SectorT", bound=sectors.SectorAware)
11+
12+
13+
class ProgressbarAware(abc.ABC, typing.Generic[SectorT]):
14+
@abc.abstractmethod
15+
def add_sector(self, sector: SectorT, /) -> ProgressbarAware[SectorT]:
16+
...
17+
18+
@abc.abstractmethod
19+
def replace_visual(self, sector_pos: int, new_visual: str, /) -> ProgressbarAware[SectorT]:
20+
...
21+
22+
@property
23+
@abc.abstractmethod
24+
def length(self) -> int:
25+
...
26+
27+
@property
28+
@abc.abstractmethod
29+
def storage(self) -> typing.Sequence[SectorT]:
30+
...

multibar/api/sectors.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from __future__ import annotations
2+
3+
__all__ = ("SectorAware",)
4+
5+
import abc
6+
import typing
7+
8+
if typing.TYPE_CHECKING:
9+
from . import progressbars
10+
11+
SelfT = typing.TypeVar("SelfT", bound="AbstractSector")
12+
13+
14+
class SectorAware(abc.ABC):
15+
@abc.abstractmethod
16+
def add_to_progressbar(self: SelfT, progressbar: progressbars.ProgressbarAware[SelfT], /) -> SelfT:
17+
...
18+
19+
@property
20+
@abc.abstractmethod
21+
def name(self) -> typing.AnyStr:
22+
...
23+
24+
@abc.abstractmethod
25+
def change_name(self, value: str, /) -> SectorAware:
26+
...
27+
28+
@property
29+
@abc.abstractmethod
30+
def is_filled(self) -> bool:
31+
...
32+
33+
@property
34+
@abc.abstractmethod
35+
def position(self) -> int:
36+
...

0 commit comments

Comments
 (0)