diff options
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | python-decouple.spec | 414 | ||||
| -rw-r--r-- | sources | 1 |
3 files changed, 416 insertions, 0 deletions
@@ -0,0 +1 @@ +/decouple-0.0.7.tar.gz diff --git a/python-decouple.spec b/python-decouple.spec new file mode 100644 index 0000000..b23aa05 --- /dev/null +++ b/python-decouple.spec @@ -0,0 +1,414 @@ +%global _empty_manifest_terminate_build 0 +Name: python-decouple +Version: 0.0.7 +Release: 1 +Summary: Decoupling logic +License: Apache 2.0 +URL: https://github.com/andrey-avdeev/decouple +Source0: https://mirrors.nju.edu.cn/pypi/web/packages/6c/e3/f70681dd89a96a701f22055caedc79cf88cebdeac9df827a5720bca80278/decouple-0.0.7.tar.gz +BuildArch: noarch + + +%description +# Decouple +## Say NO to monolithic architecture. +Decouple complex system to separated modules by mediator. + +```shell script +pip install decouple +``` + +## Register event handler + + +## Dispatch events + + +## Example +### Simple usage +Code of example is [here](https://github.com/andrey-avdeev/decouple/tree/master/examples/simple) + +1. Write ModuleA - publisher +```python +from dataclasses import dataclass + +from decouple import Module, Event, Mediator + + +class ModuleA(Module): + def __init__(self, mediator: Mediator = Mediator()): + super().__init__(mediator) + + def start(self): + self.pub(StartEvent(a=7)) + + +@dataclass +class StartEvent(Event): + a: int = 0 # must be serializable +``` + +2. Write ModuleB - subscriber +```python +from decouple import Module +from examples.simple.module_a import StartEvent + + +class ModuleB(Module): + def __init__(self): + super().__init__() + + self.sub(StartEvent, self.handle_a) + + def handle_start(self, event: StartEvent): + print(f'field a:{event.a}') + +``` + +3. Compose both modules to the whole +```python +from examples.simple.module_a import ModuleA +from examples.simple.module_b import ModuleB + + +module_a = ModuleA() +module_a.add(ModuleB()) + +module_a.start() +``` + +### Priorities +Manual control +```python +from decouple import Module +from examples.simple.module_a import StartEvent + + +class ModuleB(Module): + def __init__(self): + super().__init__() + + # handler with higher priority will be triggered early + self.sub(StartEvent, self.handle_b, priority=0) + self.sub(StartEvent, self.handle_a, priority=100) + + def handle_a(self, event: StartEvent): + # will be triggered first + print(f'field a:{event.a}') + + def handle_b(self, event: StartEvent): + # will be triggered second + print(f'event.uuid:{event.uuid}, event.timestamp:{event.timestamp}') +``` +Default priority depends on registration order +```python +from decouple import Module +from examples.simple.module_a import StartEvent + + +class ModuleB(Module): + def __init__(self): + super().__init__() + + # priority of handlers call increased by 1 every registration for the same event + self.sub(StartEvent, self.handle_b) # priority=1 + self.sub(StartEvent, self.handle_a) # priority=2 + + def handle_a(self, event: StartEvent): + # will be triggered second + print(f'field a:{event.a}') + + def handle_b(self, event: StartEvent): + # will be triggered first + print(f'event.uuid:{event.uuid}, event.timestamp:{event.timestamp}') +``` + +# Feedback +I will be glad to read your feedback in issues and pull requests. + +%package -n python3-decouple +Summary: Decoupling logic +Provides: python-decouple +BuildRequires: python3-devel +BuildRequires: python3-setuptools +BuildRequires: python3-pip +%description -n python3-decouple +# Decouple +## Say NO to monolithic architecture. +Decouple complex system to separated modules by mediator. + +```shell script +pip install decouple +``` + +## Register event handler + + +## Dispatch events + + +## Example +### Simple usage +Code of example is [here](https://github.com/andrey-avdeev/decouple/tree/master/examples/simple) + +1. Write ModuleA - publisher +```python +from dataclasses import dataclass + +from decouple import Module, Event, Mediator + + +class ModuleA(Module): + def __init__(self, mediator: Mediator = Mediator()): + super().__init__(mediator) + + def start(self): + self.pub(StartEvent(a=7)) + + +@dataclass +class StartEvent(Event): + a: int = 0 # must be serializable +``` + +2. Write ModuleB - subscriber +```python +from decouple import Module +from examples.simple.module_a import StartEvent + + +class ModuleB(Module): + def __init__(self): + super().__init__() + + self.sub(StartEvent, self.handle_a) + + def handle_start(self, event: StartEvent): + print(f'field a:{event.a}') + +``` + +3. Compose both modules to the whole +```python +from examples.simple.module_a import ModuleA +from examples.simple.module_b import ModuleB + + +module_a = ModuleA() +module_a.add(ModuleB()) + +module_a.start() +``` + +### Priorities +Manual control +```python +from decouple import Module +from examples.simple.module_a import StartEvent + + +class ModuleB(Module): + def __init__(self): + super().__init__() + + # handler with higher priority will be triggered early + self.sub(StartEvent, self.handle_b, priority=0) + self.sub(StartEvent, self.handle_a, priority=100) + + def handle_a(self, event: StartEvent): + # will be triggered first + print(f'field a:{event.a}') + + def handle_b(self, event: StartEvent): + # will be triggered second + print(f'event.uuid:{event.uuid}, event.timestamp:{event.timestamp}') +``` +Default priority depends on registration order +```python +from decouple import Module +from examples.simple.module_a import StartEvent + + +class ModuleB(Module): + def __init__(self): + super().__init__() + + # priority of handlers call increased by 1 every registration for the same event + self.sub(StartEvent, self.handle_b) # priority=1 + self.sub(StartEvent, self.handle_a) # priority=2 + + def handle_a(self, event: StartEvent): + # will be triggered second + print(f'field a:{event.a}') + + def handle_b(self, event: StartEvent): + # will be triggered first + print(f'event.uuid:{event.uuid}, event.timestamp:{event.timestamp}') +``` + +# Feedback +I will be glad to read your feedback in issues and pull requests. + +%package help +Summary: Development documents and examples for decouple +Provides: python3-decouple-doc +%description help +# Decouple +## Say NO to monolithic architecture. +Decouple complex system to separated modules by mediator. + +```shell script +pip install decouple +``` + +## Register event handler + + +## Dispatch events + + +## Example +### Simple usage +Code of example is [here](https://github.com/andrey-avdeev/decouple/tree/master/examples/simple) + +1. Write ModuleA - publisher +```python +from dataclasses import dataclass + +from decouple import Module, Event, Mediator + + +class ModuleA(Module): + def __init__(self, mediator: Mediator = Mediator()): + super().__init__(mediator) + + def start(self): + self.pub(StartEvent(a=7)) + + +@dataclass +class StartEvent(Event): + a: int = 0 # must be serializable +``` + +2. Write ModuleB - subscriber +```python +from decouple import Module +from examples.simple.module_a import StartEvent + + +class ModuleB(Module): + def __init__(self): + super().__init__() + + self.sub(StartEvent, self.handle_a) + + def handle_start(self, event: StartEvent): + print(f'field a:{event.a}') + +``` + +3. Compose both modules to the whole +```python +from examples.simple.module_a import ModuleA +from examples.simple.module_b import ModuleB + + +module_a = ModuleA() +module_a.add(ModuleB()) + +module_a.start() +``` + +### Priorities +Manual control +```python +from decouple import Module +from examples.simple.module_a import StartEvent + + +class ModuleB(Module): + def __init__(self): + super().__init__() + + # handler with higher priority will be triggered early + self.sub(StartEvent, self.handle_b, priority=0) + self.sub(StartEvent, self.handle_a, priority=100) + + def handle_a(self, event: StartEvent): + # will be triggered first + print(f'field a:{event.a}') + + def handle_b(self, event: StartEvent): + # will be triggered second + print(f'event.uuid:{event.uuid}, event.timestamp:{event.timestamp}') +``` +Default priority depends on registration order +```python +from decouple import Module +from examples.simple.module_a import StartEvent + + +class ModuleB(Module): + def __init__(self): + super().__init__() + + # priority of handlers call increased by 1 every registration for the same event + self.sub(StartEvent, self.handle_b) # priority=1 + self.sub(StartEvent, self.handle_a) # priority=2 + + def handle_a(self, event: StartEvent): + # will be triggered second + print(f'field a:{event.a}') + + def handle_b(self, event: StartEvent): + # will be triggered first + print(f'event.uuid:{event.uuid}, event.timestamp:{event.timestamp}') +``` + +# Feedback +I will be glad to read your feedback in issues and pull requests. + +%prep +%autosetup -n decouple-0.0.7 + +%build +%py3_build + +%install +%py3_install +install -d -m755 %{buildroot}/%{_pkgdocdir} +if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi +if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi +if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi +if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi +pushd %{buildroot} +if [ -d usr/lib ]; then + find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/lib64 ]; then + find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/bin ]; then + find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/sbin ]; then + find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst +fi +touch doclist.lst +if [ -d usr/share/man ]; then + find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst +fi +popd +mv %{buildroot}/filelist.lst . +mv %{buildroot}/doclist.lst . + +%files -n python3-decouple -f filelist.lst +%dir %{python3_sitelib}/* + +%files help -f doclist.lst +%{_docdir}/* + +%changelog +* Mon Apr 10 2023 Python_Bot <Python_Bot@openeuler.org> - 0.0.7-1 +- Package Spec generated @@ -0,0 +1 @@ +4ffeaebb883be335262292aece329c04 decouple-0.0.7.tar.gz |
