explicit-python 2.4.1__tar.gz → 3.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {explicit_python-2.4.1 → explicit_python-3.0.0}/PKG-INFO +44 -11
- explicit_python-2.4.1/src/explicit_python.egg-info/PKG-INFO → explicit_python-3.0.0/README.md +38 -33
- {explicit_python-2.4.1 → explicit_python-3.0.0}/pyproject.toml +53 -16
- {explicit_python-2.4.1 → explicit_python-3.0.0}/src/explicit/adapters/db.py +8 -5
- {explicit_python-2.4.1 → explicit_python-3.0.0}/src/explicit/adapters/fs.py +4 -2
- {explicit_python-2.4.1 → explicit_python-3.0.0}/src/explicit/adapters/messaging.py +5 -3
- {explicit_python-2.4.1 → explicit_python-3.0.0}/src/explicit/contrib/domain/model/__init__.py +5 -2
- explicit_python-3.0.0/src/explicit/contrib/domain/model/fields.py +32 -0
- {explicit_python-2.4.1 → explicit_python-3.0.0}/src/explicit/contrib/messagebus/event_registry.py +19 -13
- explicit_python-3.0.0/src/explicit/domain/__init__.py +52 -0
- {explicit_python-2.4.1 → explicit_python-3.0.0}/src/explicit/domain/factories.py +8 -8
- explicit_python-3.0.0/src/explicit/domain/fields.py +36 -0
- explicit_python-3.0.0/src/explicit/domain/model.py +160 -0
- {explicit_python-2.4.1 → explicit_python-3.0.0}/src/explicit/domain/types.py +17 -13
- {explicit_python-2.4.1 → explicit_python-3.0.0}/src/explicit/domain/validation/exceptions.py +31 -20
- {explicit_python-2.4.1 → explicit_python-3.0.0}/src/explicit/messagebus/__init__.py +3 -1
- {explicit_python-2.4.1 → explicit_python-3.0.0}/src/explicit/messagebus/commands.py +24 -34
- {explicit_python-2.4.1 → explicit_python-3.0.0}/src/explicit/messagebus/dependency_injection.py +13 -13
- {explicit_python-2.4.1 → explicit_python-3.0.0}/src/explicit/messagebus/events.py +47 -47
- {explicit_python-2.4.1 → explicit_python-3.0.0}/src/explicit/messagebus/exceptions.py +3 -1
- {explicit_python-2.4.1 → explicit_python-3.0.0}/src/explicit/messagebus/messagebus.py +24 -15
- {explicit_python-2.4.1 → explicit_python-3.0.0}/src/explicit/messagebus/queries.py +15 -16
- {explicit_python-2.4.1 → explicit_python-3.0.0}/src/explicit/unit_of_work.py +15 -25
- explicit_python-2.4.1/README.md → explicit_python-3.0.0/src/explicit_python.egg-info/PKG-INFO +66 -7
- explicit_python-3.0.0/src/explicit_python.egg-info/requires.txt +2 -0
- explicit_python-2.4.1/src/explicit/contrib/domain/model/fields.py +0 -31
- explicit_python-2.4.1/src/explicit/domain/__init__.py +0 -28
- explicit_python-2.4.1/src/explicit/domain/fields.py +0 -9
- explicit_python-2.4.1/src/explicit/domain/model.py +0 -152
- explicit_python-2.4.1/src/explicit_python.egg-info/requires.txt +0 -2
- {explicit_python-2.4.1 → explicit_python-3.0.0}/LICENSE +0 -0
- {explicit_python-2.4.1 → explicit_python-3.0.0}/MANIFEST.in +0 -0
- {explicit_python-2.4.1 → explicit_python-3.0.0}/setup.cfg +0 -0
- {explicit_python-2.4.1 → explicit_python-3.0.0}/src/explicit/adapters/__init__.py +0 -0
- {explicit_python-2.4.1 → explicit_python-3.0.0}/src/explicit/contrib/__init__.py +0 -0
- {explicit_python-2.4.1 → explicit_python-3.0.0}/src/explicit/contrib/domain/__init__.py +0 -0
- {explicit_python-2.4.1 → explicit_python-3.0.0}/src/explicit/contrib/messagebus/__init__.py +0 -0
- {explicit_python-2.4.1 → explicit_python-3.0.0}/src/explicit/domain/validation/__init__.py +0 -0
- {explicit_python-2.4.1 → explicit_python-3.0.0}/src/explicit/py.typed +0 -0
- {explicit_python-2.4.1 → explicit_python-3.0.0}/src/explicit_python.egg-info/SOURCES.txt +0 -0
- {explicit_python-2.4.1 → explicit_python-3.0.0}/src/explicit_python.egg-info/dependency_links.txt +0 -0
- {explicit_python-2.4.1 → explicit_python-3.0.0}/src/explicit_python.egg-info/top_level.txt +0 -0
- {explicit_python-2.4.1 → explicit_python-3.0.0}/version.conf +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: explicit-python
|
|
3
|
-
Version:
|
|
3
|
+
Version: 3.0.0
|
|
4
4
|
Summary: Набор компонентов для построения многослойной архитектуры
|
|
5
5
|
Author-email: BARS Group <bars@bars-open.ru>
|
|
6
6
|
Project-URL: Homepage, https://stash.bars-open.ru/projects/EDUBASE/repos/explicit/browse
|
|
@@ -13,15 +13,17 @@ Classifier: Operating System :: OS Independent
|
|
|
13
13
|
Classifier: License :: OSI Approved :: MIT License
|
|
14
14
|
Classifier: Development Status :: 5 - Production/Stable
|
|
15
15
|
Classifier: Programming Language :: Python
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
17
16
|
Classifier: Programming Language :: Python :: 3.10
|
|
18
17
|
Classifier: Programming Language :: Python :: 3.11
|
|
19
18
|
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
-
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
22
|
+
Requires-Python: >=3.10
|
|
21
23
|
Description-Content-Type: text/markdown
|
|
22
24
|
License-File: LICENSE
|
|
23
25
|
Requires-Dist: more_itertools
|
|
24
|
-
Requires-Dist: pydantic<2.
|
|
26
|
+
Requires-Dist: pydantic<3,>=2.14
|
|
25
27
|
Dynamic: license-file
|
|
26
28
|
|
|
27
29
|
# Explicit
|
|
@@ -175,7 +177,7 @@ def update_person(person, data: 'PersonDTO'):
|
|
|
175
177
|
```python
|
|
176
178
|
class CommandBusMixin(ABC):
|
|
177
179
|
|
|
178
|
-
_command_handlers:
|
|
180
|
+
_command_handlers: dict[type[Command], Callable] = {}
|
|
179
181
|
|
|
180
182
|
def handle_command(self, command: Command):
|
|
181
183
|
"""Передача запроса обработчику типа данного запроса."""
|
|
@@ -190,10 +192,10 @@ def update_person(person, data: 'PersonDTO'):
|
|
|
190
192
|
) -> 'Student':
|
|
191
193
|
with uow.wrap():
|
|
192
194
|
student: Student = domain_register_student(
|
|
193
|
-
StudentDTO(**command.
|
|
195
|
+
StudentDTO(**command.model_dump())
|
|
194
196
|
)
|
|
195
197
|
uow.add_event(events.StudentCreated(
|
|
196
|
-
**command.
|
|
198
|
+
**command.model_dump(), **asdict(student)
|
|
197
199
|
))
|
|
198
200
|
return student
|
|
199
201
|
```
|
|
@@ -205,7 +207,7 @@ def update_person(person, data: 'PersonDTO'):
|
|
|
205
207
|
```python
|
|
206
208
|
class EventBusMixin(ABC):
|
|
207
209
|
|
|
208
|
-
_event_handlers:
|
|
210
|
+
_event_handlers: dict[type[Event], list[EventHandler]] = {}
|
|
209
211
|
|
|
210
212
|
def handle_event(self, event: Event):
|
|
211
213
|
"""Передача события списку обработчиков типа данного события."""
|
|
@@ -274,7 +276,7 @@ def update_person(person, data: 'PersonDTO'):
|
|
|
274
276
|
uow.students.update(student)
|
|
275
277
|
|
|
276
278
|
uow.add_event(events.StudentCreated(
|
|
277
|
-
**command.
|
|
279
|
+
**command.model_dump(), **asdict(student)
|
|
278
280
|
))
|
|
279
281
|
```
|
|
280
282
|
|
|
@@ -283,8 +285,39 @@ def update_person(person, data: 'PersonDTO'):
|
|
|
283
285
|
Можно увидеть в тестовом приложении src/testapp.
|
|
284
286
|
|
|
285
287
|
## Запуск тестов
|
|
286
|
-
|
|
287
|
-
|
|
288
|
+
|
|
289
|
+
Тесты запускаются через `tox`. В системе должен быть установлен [uv](https://docs.astral.sh/uv/).
|
|
290
|
+
|
|
291
|
+
Для корректного запуска тестов необходимы следующие значения переменных окружения в системе. Вместо `<login>` и `<password>` необходимо подставить данные от УЗ БАРС:
|
|
292
|
+
|
|
293
|
+
```bash
|
|
294
|
+
UV_INDEX="internal=http://<login>:<password>@nexus.py.bars.group/repository/pypi-all/simple"
|
|
295
|
+
UV_DEFAULT_INDEX="https://pypi.org/simple"
|
|
296
|
+
UV_INDEX_STRATEGY=unsafe-best-match
|
|
297
|
+
# Для docker 29+
|
|
298
|
+
TOX_DOCKER_GATEWAY=localhost
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
Чтобы не менять значения системных переменных, можно создать `.env` файл c переменными окружения и запускать команды через [python-dotenv](https://github.com/theskumar/python-dotenv/).
|
|
302
|
+
|
|
303
|
+
Установка `tox` с необходимыми зависимостями:
|
|
304
|
+
```bash
|
|
305
|
+
uv tool install tox --with tox-uv --with m3-tox-docker
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
Или с использованием `python-dotenv`:
|
|
309
|
+
```bash
|
|
310
|
+
dotenv run uv tool install tox --with tox-uv --with m3-tox-docker
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
Запуск тестов:
|
|
314
|
+
```bash
|
|
315
|
+
tox
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
Через `python-dotenv`:
|
|
319
|
+
```bash
|
|
320
|
+
dotenv run tox
|
|
288
321
|
```
|
|
289
322
|
|
|
290
323
|
|
explicit_python-2.4.1/src/explicit_python.egg-info/PKG-INFO → explicit_python-3.0.0/README.md
RENAMED
|
@@ -1,29 +1,3 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: explicit-python
|
|
3
|
-
Version: 2.4.1
|
|
4
|
-
Summary: Набор компонентов для построения многослойной архитектуры
|
|
5
|
-
Author-email: BARS Group <bars@bars-open.ru>
|
|
6
|
-
Project-URL: Homepage, https://stash.bars-open.ru/projects/EDUBASE/repos/explicit/browse
|
|
7
|
-
Project-URL: Repository, https://stash.bars-open.ru/scm/edubase/explicit.git
|
|
8
|
-
Classifier: Intended Audience :: Developers
|
|
9
|
-
Classifier: Environment :: Web Environment
|
|
10
|
-
Classifier: Natural Language :: Russian
|
|
11
|
-
Classifier: Natural Language :: English
|
|
12
|
-
Classifier: Operating System :: OS Independent
|
|
13
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
-
Classifier: Development Status :: 5 - Production/Stable
|
|
15
|
-
Classifier: Programming Language :: Python
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
-
Requires-Python: >=3.9
|
|
21
|
-
Description-Content-Type: text/markdown
|
|
22
|
-
License-File: LICENSE
|
|
23
|
-
Requires-Dist: more_itertools
|
|
24
|
-
Requires-Dist: pydantic<2.0
|
|
25
|
-
Dynamic: license-file
|
|
26
|
-
|
|
27
1
|
# Explicit
|
|
28
2
|
## Набор компонентов для построения явной (Explicit) многослойной архитектуры
|
|
29
3
|
|
|
@@ -175,7 +149,7 @@ def update_person(person, data: 'PersonDTO'):
|
|
|
175
149
|
```python
|
|
176
150
|
class CommandBusMixin(ABC):
|
|
177
151
|
|
|
178
|
-
_command_handlers:
|
|
152
|
+
_command_handlers: dict[type[Command], Callable] = {}
|
|
179
153
|
|
|
180
154
|
def handle_command(self, command: Command):
|
|
181
155
|
"""Передача запроса обработчику типа данного запроса."""
|
|
@@ -190,10 +164,10 @@ def update_person(person, data: 'PersonDTO'):
|
|
|
190
164
|
) -> 'Student':
|
|
191
165
|
with uow.wrap():
|
|
192
166
|
student: Student = domain_register_student(
|
|
193
|
-
StudentDTO(**command.
|
|
167
|
+
StudentDTO(**command.model_dump())
|
|
194
168
|
)
|
|
195
169
|
uow.add_event(events.StudentCreated(
|
|
196
|
-
**command.
|
|
170
|
+
**command.model_dump(), **asdict(student)
|
|
197
171
|
))
|
|
198
172
|
return student
|
|
199
173
|
```
|
|
@@ -205,7 +179,7 @@ def update_person(person, data: 'PersonDTO'):
|
|
|
205
179
|
```python
|
|
206
180
|
class EventBusMixin(ABC):
|
|
207
181
|
|
|
208
|
-
_event_handlers:
|
|
182
|
+
_event_handlers: dict[type[Event], list[EventHandler]] = {}
|
|
209
183
|
|
|
210
184
|
def handle_event(self, event: Event):
|
|
211
185
|
"""Передача события списку обработчиков типа данного события."""
|
|
@@ -274,7 +248,7 @@ def update_person(person, data: 'PersonDTO'):
|
|
|
274
248
|
uow.students.update(student)
|
|
275
249
|
|
|
276
250
|
uow.add_event(events.StudentCreated(
|
|
277
|
-
**command.
|
|
251
|
+
**command.model_dump(), **asdict(student)
|
|
278
252
|
))
|
|
279
253
|
```
|
|
280
254
|
|
|
@@ -283,8 +257,39 @@ def update_person(person, data: 'PersonDTO'):
|
|
|
283
257
|
Можно увидеть в тестовом приложении src/testapp.
|
|
284
258
|
|
|
285
259
|
## Запуск тестов
|
|
286
|
-
|
|
287
|
-
|
|
260
|
+
|
|
261
|
+
Тесты запускаются через `tox`. В системе должен быть установлен [uv](https://docs.astral.sh/uv/).
|
|
262
|
+
|
|
263
|
+
Для корректного запуска тестов необходимы следующие значения переменных окружения в системе. Вместо `<login>` и `<password>` необходимо подставить данные от УЗ БАРС:
|
|
264
|
+
|
|
265
|
+
```bash
|
|
266
|
+
UV_INDEX="internal=http://<login>:<password>@nexus.py.bars.group/repository/pypi-all/simple"
|
|
267
|
+
UV_DEFAULT_INDEX="https://pypi.org/simple"
|
|
268
|
+
UV_INDEX_STRATEGY=unsafe-best-match
|
|
269
|
+
# Для docker 29+
|
|
270
|
+
TOX_DOCKER_GATEWAY=localhost
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
Чтобы не менять значения системных переменных, можно создать `.env` файл c переменными окружения и запускать команды через [python-dotenv](https://github.com/theskumar/python-dotenv/).
|
|
274
|
+
|
|
275
|
+
Установка `tox` с необходимыми зависимостями:
|
|
276
|
+
```bash
|
|
277
|
+
uv tool install tox --with tox-uv --with m3-tox-docker
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
Или с использованием `python-dotenv`:
|
|
281
|
+
```bash
|
|
282
|
+
dotenv run uv tool install tox --with tox-uv --with m3-tox-docker
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
Запуск тестов:
|
|
286
|
+
```bash
|
|
287
|
+
tox
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
Через `python-dotenv`:
|
|
291
|
+
```bash
|
|
292
|
+
dotenv run tox
|
|
288
293
|
```
|
|
289
294
|
|
|
290
295
|
|
|
@@ -15,7 +15,7 @@ license-files = ['LICENSE']
|
|
|
15
15
|
authors = [
|
|
16
16
|
{name = 'BARS Group', email = 'bars@bars-open.ru'}
|
|
17
17
|
]
|
|
18
|
-
requires-python = '>=3.
|
|
18
|
+
requires-python = '>=3.10'
|
|
19
19
|
classifiers = [
|
|
20
20
|
'Intended Audience :: Developers',
|
|
21
21
|
'Environment :: Web Environment',
|
|
@@ -25,14 +25,16 @@ classifiers = [
|
|
|
25
25
|
'License :: OSI Approved :: MIT License',
|
|
26
26
|
'Development Status :: 5 - Production/Stable',
|
|
27
27
|
'Programming Language :: Python',
|
|
28
|
-
'Programming Language :: Python :: 3.9',
|
|
29
28
|
'Programming Language :: Python :: 3.10',
|
|
30
29
|
'Programming Language :: Python :: 3.11',
|
|
31
30
|
'Programming Language :: Python :: 3.12',
|
|
31
|
+
'Programming Language :: Python :: 3.13',
|
|
32
|
+
'Programming Language :: Python :: 3.14',
|
|
33
|
+
'Programming Language :: Python :: 3.15',
|
|
32
34
|
]
|
|
33
35
|
dependencies = [
|
|
34
36
|
'more_itertools',
|
|
35
|
-
'pydantic
|
|
37
|
+
'pydantic>=2.14,<3',
|
|
36
38
|
]
|
|
37
39
|
dynamic = ['version']
|
|
38
40
|
|
|
@@ -58,23 +60,17 @@ no_site_packages = true
|
|
|
58
60
|
ignore_missing_imports = true
|
|
59
61
|
|
|
60
62
|
[tool.isort]
|
|
63
|
+
multi_line_output = 3
|
|
64
|
+
force_grid_wrap = 1
|
|
65
|
+
include_trailing_comma = true
|
|
61
66
|
line_length = 120
|
|
62
|
-
|
|
63
|
-
indent = 4
|
|
64
|
-
atomic = true
|
|
65
|
-
from_first = true
|
|
67
|
+
combine_as_imports = true
|
|
66
68
|
lines_after_imports = 2
|
|
67
|
-
|
|
68
|
-
extra_standard_library = [
|
|
69
|
-
'dataclasses',
|
|
70
|
-
]
|
|
71
|
-
known_project=[
|
|
69
|
+
known_project = [
|
|
72
70
|
'explicit',
|
|
73
|
-
'
|
|
74
|
-
'edu',
|
|
75
|
-
'training',
|
|
71
|
+
'testapp',
|
|
76
72
|
]
|
|
77
|
-
sections=[
|
|
73
|
+
sections = [
|
|
78
74
|
'FUTURE',
|
|
79
75
|
'STDLIB',
|
|
80
76
|
'THIRDPARTY',
|
|
@@ -82,3 +78,44 @@ sections=[
|
|
|
82
78
|
'PROJECT',
|
|
83
79
|
'LOCALFOLDER',
|
|
84
80
|
]
|
|
81
|
+
|
|
82
|
+
[tool.ruff]
|
|
83
|
+
target-version = 'py310'
|
|
84
|
+
line-length = 120
|
|
85
|
+
indent-width = 4
|
|
86
|
+
|
|
87
|
+
[tool.ruff.lint]
|
|
88
|
+
select = ['F', 'E', 'D', 'W', 'S', 'N', 'UP007', 'UP045']
|
|
89
|
+
ignore = [
|
|
90
|
+
# Missing docstring in public module
|
|
91
|
+
'D100',
|
|
92
|
+
# Missing docstring in public class
|
|
93
|
+
'D101',
|
|
94
|
+
# Missing docstring in public method
|
|
95
|
+
'D102',
|
|
96
|
+
# Missing docstring in public function
|
|
97
|
+
'D103',
|
|
98
|
+
# Missing docstring in public package
|
|
99
|
+
'D104',
|
|
100
|
+
# Missing docstring in magic method
|
|
101
|
+
'D105',
|
|
102
|
+
# Missing docstring in public nested class
|
|
103
|
+
'D106',
|
|
104
|
+
# Missing docstring in __init__
|
|
105
|
+
'D107',
|
|
106
|
+
# use of assert detected (useless with pytest)
|
|
107
|
+
'S101',
|
|
108
|
+
]
|
|
109
|
+
|
|
110
|
+
[tool.ruff.lint.pydocstyle]
|
|
111
|
+
convention = 'google'
|
|
112
|
+
|
|
113
|
+
[tool.ruff.format]
|
|
114
|
+
quote-style = 'single'
|
|
115
|
+
indent-style = 'space'
|
|
116
|
+
docstring-code-format = true
|
|
117
|
+
|
|
118
|
+
[tool.ruff.lint.per-file-ignores]
|
|
119
|
+
'*/tests/*' = ['D', 'S106']
|
|
120
|
+
'**/__init__.py' = ['F401']
|
|
121
|
+
'**/domain/model.py' = ['N818']
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
"""Абстракции адаптера СУБД."""
|
|
2
|
-
from abc import ABCMeta
|
|
3
|
-
from abc import abstractmethod
|
|
4
|
-
from typing import Any
|
|
5
2
|
|
|
3
|
+
from abc import (
|
|
4
|
+
ABCMeta,
|
|
5
|
+
abstractmethod,
|
|
6
|
+
)
|
|
7
|
+
from typing import (
|
|
8
|
+
Any,
|
|
9
|
+
)
|
|
6
10
|
|
|
7
|
-
class AbstractSpecification(metaclass=ABCMeta):
|
|
8
11
|
|
|
12
|
+
class AbstractSpecification(metaclass=ABCMeta):
|
|
9
13
|
"""Набор условий для проверки соответствия объекта этим условиям."""
|
|
10
14
|
|
|
11
15
|
@abstractmethod
|
|
@@ -18,7 +22,6 @@ class AbstractSpecification(metaclass=ABCMeta):
|
|
|
18
22
|
|
|
19
23
|
|
|
20
24
|
class AbstractRepository(metaclass=ABCMeta):
|
|
21
|
-
|
|
22
25
|
"""Репозиторий - абстракция над хранилищем данных (БД).
|
|
23
26
|
|
|
24
27
|
Должен содержать методы получения объектов со всеми вариантами выборки:
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"""Абстракции адаптера обмена сообщениями."""
|
|
2
|
-
from abc import ABC
|
|
3
|
-
from abc import abstractmethod
|
|
4
2
|
|
|
3
|
+
from abc import (
|
|
4
|
+
ABC,
|
|
5
|
+
abstractmethod,
|
|
6
|
+
)
|
|
5
7
|
|
|
6
|
-
class AbstractAdapter(ABC):
|
|
7
8
|
|
|
9
|
+
class AbstractAdapter(ABC):
|
|
8
10
|
@abstractmethod
|
|
9
11
|
def publish(self, message, *args, **kwargs):
|
|
10
12
|
raise NotImplementedError()
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""Поля модели предметной области."""
|
|
2
|
+
|
|
3
|
+
from uuid import (
|
|
4
|
+
uuid4,
|
|
5
|
+
)
|
|
6
|
+
|
|
7
|
+
from pydantic.fields import (
|
|
8
|
+
Field,
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def identifier(**kwargs):
|
|
13
|
+
return Field(
|
|
14
|
+
None,
|
|
15
|
+
title='Идентификатор',
|
|
16
|
+
description=(
|
|
17
|
+
'Идентификатор записи. Может отсутствовать у создаваемых объектов, но обязан присутствовать у существующих.'
|
|
18
|
+
),
|
|
19
|
+
gt=0,
|
|
20
|
+
**kwargs,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def uuid_identifier(**kwargs):
|
|
25
|
+
return Field(
|
|
26
|
+
default_factory=uuid4,
|
|
27
|
+
title='Идентификатор UUID',
|
|
28
|
+
description=(
|
|
29
|
+
'Идентификатор записи. Может отсутствовать у создаваемых объектов, но обязан присутствовать у существующих.'
|
|
30
|
+
),
|
|
31
|
+
**kwargs,
|
|
32
|
+
)
|
{explicit_python-2.4.1 → explicit_python-3.0.0}/src/explicit/contrib/messagebus/event_registry.py
RENAMED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
"""Реестр событий по топикам."""
|
|
2
|
-
|
|
3
|
-
from dataclasses import dataclass
|
|
4
|
-
from typing import TYPE_CHECKING
|
|
5
|
-
from typing import Dict
|
|
6
|
-
from typing import Type
|
|
7
|
-
from typing import Union
|
|
2
|
+
|
|
8
3
|
import logging
|
|
4
|
+
from collections import (
|
|
5
|
+
defaultdict,
|
|
6
|
+
)
|
|
7
|
+
from dataclasses import (
|
|
8
|
+
dataclass,
|
|
9
|
+
)
|
|
10
|
+
from typing import (
|
|
11
|
+
TYPE_CHECKING,
|
|
12
|
+
)
|
|
9
13
|
|
|
10
14
|
|
|
11
15
|
if TYPE_CHECKING:
|
|
12
|
-
from explicit.messagebus.events import
|
|
16
|
+
from explicit.messagebus.events import (
|
|
17
|
+
Event,
|
|
18
|
+
)
|
|
13
19
|
|
|
14
20
|
logger = logging.getLogger(__name__)
|
|
15
21
|
logger.setLevel(logging.INFO)
|
|
@@ -28,21 +34,21 @@ class Message:
|
|
|
28
34
|
|
|
29
35
|
|
|
30
36
|
class Registry:
|
|
31
|
-
|
|
32
37
|
"""Реестр событий по топикам."""
|
|
33
38
|
|
|
34
|
-
_registry:
|
|
39
|
+
_registry: dict[str, list[type['Event']]]
|
|
35
40
|
|
|
36
41
|
def __init__(self):
|
|
37
42
|
self._registry = defaultdict(list)
|
|
38
43
|
|
|
39
|
-
def register(self, topic: str, *events:
|
|
44
|
+
def register(self, topic: str, *events: type['Event']) -> None:
|
|
40
45
|
"""Регистрирует сопоставление топика с типом события."""
|
|
41
46
|
self._registry[topic].extend(events)
|
|
42
47
|
|
|
43
|
-
def resolve(self, message: Message) ->
|
|
44
|
-
"""
|
|
45
|
-
|
|
48
|
+
def resolve(self, message: Message) -> 'Event | None':
|
|
49
|
+
"""Определяет подходящий тип события.
|
|
50
|
+
|
|
51
|
+
Возвращает экземпляр для передачи на обработку в шину событий либо None.
|
|
46
52
|
"""
|
|
47
53
|
event = None
|
|
48
54
|
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"""Объекты предметной области."""
|
|
2
|
+
|
|
3
|
+
from .factories import (
|
|
4
|
+
AbstractDomainFactory,
|
|
5
|
+
DTOBase,
|
|
6
|
+
)
|
|
7
|
+
from .fields import (
|
|
8
|
+
Field,
|
|
9
|
+
get_field_title,
|
|
10
|
+
)
|
|
11
|
+
from .model import (
|
|
12
|
+
HasUnsetValues,
|
|
13
|
+
Unset,
|
|
14
|
+
asdict,
|
|
15
|
+
is_unset,
|
|
16
|
+
unset,
|
|
17
|
+
)
|
|
18
|
+
from .types import (
|
|
19
|
+
Bool,
|
|
20
|
+
Date,
|
|
21
|
+
Int,
|
|
22
|
+
NoneBool,
|
|
23
|
+
NoneDate,
|
|
24
|
+
NoneInt,
|
|
25
|
+
NoneStr,
|
|
26
|
+
NoneUnsetUUID,
|
|
27
|
+
Str,
|
|
28
|
+
UnsetUUID,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
__all__ = [
|
|
33
|
+
'AbstractDomainFactory',
|
|
34
|
+
'DTOBase',
|
|
35
|
+
'Unset',
|
|
36
|
+
'unset',
|
|
37
|
+
'is_unset',
|
|
38
|
+
'HasUnsetValues',
|
|
39
|
+
'asdict',
|
|
40
|
+
'Field',
|
|
41
|
+
'get_field_title',
|
|
42
|
+
'UnsetUUID',
|
|
43
|
+
'Bool',
|
|
44
|
+
'Date',
|
|
45
|
+
'Int',
|
|
46
|
+
'NoneBool',
|
|
47
|
+
'NoneDate',
|
|
48
|
+
'NoneInt',
|
|
49
|
+
'NoneStr',
|
|
50
|
+
'NoneUnsetUUID',
|
|
51
|
+
'Str',
|
|
52
|
+
]
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
"""Объекты передачи данных."""
|
|
2
|
-
|
|
3
|
-
from abc import
|
|
2
|
+
|
|
3
|
+
from abc import (
|
|
4
|
+
ABCMeta,
|
|
5
|
+
abstractmethod,
|
|
6
|
+
)
|
|
4
7
|
|
|
5
8
|
from pydantic.main import BaseModel # pylint: disable=no-name-in-module
|
|
6
9
|
|
|
7
|
-
from .model import
|
|
10
|
+
from .model import (
|
|
11
|
+
HasUnsetValues,
|
|
12
|
+
)
|
|
8
13
|
|
|
9
14
|
|
|
10
15
|
class DTOBase(HasUnsetValues, BaseModel):
|
|
11
|
-
|
|
12
16
|
"""Базовый объект передачи данных.
|
|
13
17
|
|
|
14
18
|
.. code-block::python
|
|
@@ -18,12 +22,8 @@ class DTOBase(HasUnsetValues, BaseModel):
|
|
|
18
22
|
|
|
19
23
|
"""
|
|
20
24
|
|
|
21
|
-
class Config:
|
|
22
|
-
arbitrary_types_allowed = False
|
|
23
|
-
|
|
24
25
|
|
|
25
26
|
class AbstractDomainFactory(metaclass=ABCMeta):
|
|
26
|
-
|
|
27
27
|
@abstractmethod
|
|
28
28
|
def create(self, data):
|
|
29
29
|
"""Сборка объекта модели предметной области из переданных данных.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""Набор полей объектов предметной области."""
|
|
2
|
+
|
|
3
|
+
from functools import (
|
|
4
|
+
partial,
|
|
5
|
+
)
|
|
6
|
+
|
|
7
|
+
from pydantic import (
|
|
8
|
+
Field as DefaultField,
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
from .model import (
|
|
12
|
+
unset,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
Field = partial(DefaultField, default=unset) # pylint: disable=invalid-name
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def get_field_title(cls: type, name: str) -> str:
|
|
20
|
+
"""Возвращает заголовок поля pydantic-модели или pydantic-датакласса.
|
|
21
|
+
|
|
22
|
+
Если заголовок не задан, возвращает имя поля.
|
|
23
|
+
|
|
24
|
+
.. code-block:: python
|
|
25
|
+
|
|
26
|
+
@dataclass
|
|
27
|
+
class User:
|
|
28
|
+
username: str = Field(title='Логин')
|
|
29
|
+
email: str
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
get_field_title(User, 'username') == 'Логин'
|
|
33
|
+
get_field_title(User, 'email') == 'email'
|
|
34
|
+
|
|
35
|
+
"""
|
|
36
|
+
return cls.__pydantic_fields__[name].title or name # type: ignore[attr-defined]
|