encommon 0.13.1__py3-none-any.whl → 0.15.0__py3-none-any.whl
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.
- encommon/__init__.py +2 -7
- encommon/colors/__init__.py +14 -0
- encommon/colors/color.py +518 -0
- encommon/colors/test/__init__.py +6 -0
- encommon/colors/test/test_color.py +189 -0
- encommon/config/config.py +83 -30
- encommon/config/files.py +16 -13
- encommon/config/logger.py +10 -5
- encommon/config/params.py +47 -31
- encommon/config/paths.py +15 -12
- encommon/config/test/__init__.py +1 -1
- encommon/config/test/test_config.py +15 -17
- encommon/config/test/test_files.py +8 -7
- encommon/config/test/test_logger.py +21 -15
- encommon/config/test/test_paths.py +12 -11
- encommon/config/utils.py +9 -3
- encommon/conftest.py +33 -22
- encommon/crypts/params.py +46 -11
- encommon/crypts/test/test_crypts.py +5 -5
- encommon/crypts/test/test_hashes.py +2 -1
- encommon/times/__init__.py +5 -3
- encommon/times/common.py +4 -3
- encommon/times/params.py +103 -45
- encommon/times/parse.py +39 -12
- encommon/times/test/test_duration.py +3 -2
- encommon/times/test/test_parse.py +16 -9
- encommon/times/test/test_time.py +123 -0
- encommon/times/test/test_timer.py +5 -4
- encommon/times/test/test_timers.py +10 -9
- encommon/times/test/test_unitime.py +23 -0
- encommon/times/test/test_window.py +4 -3
- encommon/times/test/test_windows.py +7 -6
- encommon/times/{times.py → time.py} +129 -22
- encommon/times/timer.py +10 -10
- encommon/times/timers.py +3 -3
- encommon/times/unitime.py +57 -0
- encommon/times/window.py +31 -31
- encommon/times/windows.py +10 -10
- encommon/types/__init__.py +20 -2
- encommon/types/classes.py +84 -0
- encommon/types/lists.py +33 -0
- encommon/types/notate.py +2 -1
- encommon/types/strings.py +34 -4
- encommon/types/test/test_classes.py +74 -0
- encommon/types/test/test_empty.py +2 -1
- encommon/types/test/test_lists.py +23 -0
- encommon/types/test/test_strings.py +15 -3
- encommon/types/types.py +20 -0
- encommon/utils/__init__.py +4 -0
- encommon/utils/paths.py +5 -6
- encommon/utils/sample.py +118 -41
- encommon/utils/stdout.py +53 -7
- encommon/utils/test/test_paths.py +3 -3
- encommon/utils/test/test_sample.py +128 -29
- encommon/utils/test/test_stdout.py +92 -28
- encommon/version.txt +1 -1
- {encommon-0.13.1.dist-info → encommon-0.15.0.dist-info}/METADATA +1 -1
- encommon-0.15.0.dist-info/RECORD +84 -0
- {encommon-0.13.1.dist-info → encommon-0.15.0.dist-info}/WHEEL +1 -1
- encommon/times/test/test_times.py +0 -89
- encommon-0.13.1.dist-info/RECORD +0 -73
- {encommon-0.13.1.dist-info → encommon-0.15.0.dist-info}/LICENSE +0 -0
- {encommon-0.13.1.dist-info → encommon-0.15.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,189 @@
|
|
1
|
+
"""
|
2
|
+
Functions and routines associated with Enasis Network Common Library.
|
3
|
+
|
4
|
+
This file is part of Enasis Network software eco-system. Distribution
|
5
|
+
is permitted, for more information consult the project license file.
|
6
|
+
"""
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
from pytest import mark
|
11
|
+
|
12
|
+
from ..color import Color
|
13
|
+
from ...types import lattrs
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
def test_Color() -> None:
|
18
|
+
"""
|
19
|
+
Perform various tests associated with relevant routines.
|
20
|
+
"""
|
21
|
+
|
22
|
+
color = Color('000001')
|
23
|
+
|
24
|
+
|
25
|
+
attrs = lattrs(color)
|
26
|
+
|
27
|
+
assert attrs == [
|
28
|
+
'_Color__source']
|
29
|
+
|
30
|
+
|
31
|
+
assert repr(color) == (
|
32
|
+
"Color('#000001')")
|
33
|
+
|
34
|
+
assert hash(color) > 0
|
35
|
+
|
36
|
+
assert str(color) == '#000001'
|
37
|
+
|
38
|
+
|
39
|
+
assert int(color) == 1
|
40
|
+
assert float(color) == 1.0
|
41
|
+
|
42
|
+
assert color + 1 == '000002'
|
43
|
+
assert color - 1 == '000000'
|
44
|
+
|
45
|
+
assert color == '000001'
|
46
|
+
assert color != '000000'
|
47
|
+
assert color != int
|
48
|
+
|
49
|
+
assert color > 0
|
50
|
+
assert color >= 1
|
51
|
+
assert color <= 1
|
52
|
+
assert color < 2
|
53
|
+
|
54
|
+
assert color > '000000'
|
55
|
+
assert color >= '000001'
|
56
|
+
assert color <= '000001'
|
57
|
+
assert color < '000002'
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
@mark.parametrize(
|
62
|
+
'source,expect',
|
63
|
+
[('ff00cc', (255, 0, 204)),
|
64
|
+
('ffffff', (255, 255, 255)),
|
65
|
+
('000000', (0, 0, 0)),
|
66
|
+
('ff0000', (255, 0, 0)),
|
67
|
+
('00ff00', (0, 255, 0)),
|
68
|
+
('0000ff', (0, 0, 255)),
|
69
|
+
('808080', (128, 128, 128)),
|
70
|
+
('ffff00', (255, 255, 0)),
|
71
|
+
('00ffff', (0, 255, 255)),
|
72
|
+
('ff00ff', (255, 0, 255)),
|
73
|
+
('800080', (128, 0, 128))])
|
74
|
+
def test_Color_rgb(
|
75
|
+
source: str,
|
76
|
+
expect: tuple[int, ...],
|
77
|
+
) -> None:
|
78
|
+
"""
|
79
|
+
Perform various tests associated with relevant routines.
|
80
|
+
|
81
|
+
:param source: Source color used when converting values.
|
82
|
+
:param expect: Expected output from the testing routine.
|
83
|
+
"""
|
84
|
+
|
85
|
+
assert Color(source).rgb == expect
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
@mark.parametrize(
|
90
|
+
'source,expect',
|
91
|
+
[('ff00cc', (52.1391, 25.6196, 59.3238)),
|
92
|
+
('ffffff', (95.0500, 100.0000, 108.9000)),
|
93
|
+
('000000', (0.0000, 0.0000, 0.0000)),
|
94
|
+
('ff0000', (41.2400, 21.2600, 1.9300)),
|
95
|
+
('00ff00', (35.7600, 71.5200, 11.9200)),
|
96
|
+
('0000ff', (18.0500, 7.2200, 95.0500)),
|
97
|
+
('808080', (20.5175, 21.5861, 23.5072)),
|
98
|
+
('ffff00', (77.0000, 92.7800, 13.8500)),
|
99
|
+
('00ffff', (53.8100, 78.7400, 106.9700)),
|
100
|
+
('ff00ff', (59.2900, 28.4800, 96.9800)),
|
101
|
+
('800080', (12.7984, 6.1477, 20.9342))])
|
102
|
+
def test_Color_xyz(
|
103
|
+
source: str,
|
104
|
+
expect: tuple[int, ...],
|
105
|
+
) -> None:
|
106
|
+
"""
|
107
|
+
Perform various tests associated with relevant routines.
|
108
|
+
|
109
|
+
:param source: Source color used when converting values.
|
110
|
+
:param expect: Expected output from the testing routine.
|
111
|
+
"""
|
112
|
+
|
113
|
+
assert Color(source).xyz == expect
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
@mark.parametrize(
|
118
|
+
'source,expect',
|
119
|
+
[('ff00cc', (0.3803, 0.1869)),
|
120
|
+
('ffffff', (0.3127, 0.3290)),
|
121
|
+
('000000', (0.0000, 0.0000)),
|
122
|
+
('ff0000', (0.6401, 0.3300)),
|
123
|
+
('00ff00', (0.3000, 0.6000)),
|
124
|
+
('0000ff', (0.1500, 0.0600)),
|
125
|
+
('808080', (0.3127, 0.3290)),
|
126
|
+
('ffff00', (0.4193, 0.5053)),
|
127
|
+
('00ffff', (0.2247, 0.3287)),
|
128
|
+
('ff00ff', (0.3209, 0.1542)),
|
129
|
+
('800080', (0.3209, 0.1542))])
|
130
|
+
def test_Color_xy(
|
131
|
+
source: str,
|
132
|
+
expect: tuple[int, ...],
|
133
|
+
) -> None:
|
134
|
+
"""
|
135
|
+
Perform various tests associated with relevant routines.
|
136
|
+
|
137
|
+
:param source: Source color used when converting values.
|
138
|
+
:param expect: Expected output from the testing routine.
|
139
|
+
"""
|
140
|
+
|
141
|
+
assert Color(source).xy == expect
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
@mark.parametrize(
|
146
|
+
'source,expect',
|
147
|
+
[('ff00cc', (312, 100, 50)),
|
148
|
+
('ffffff', (0, 0, 100)),
|
149
|
+
('000000', (0, 0, 0)),
|
150
|
+
('ff0000', (0, 100, 50)),
|
151
|
+
('00ff00', (120, 100, 50)),
|
152
|
+
('0000ff', (240, 100, 50)),
|
153
|
+
('808080', (0, 0, 50)),
|
154
|
+
('ffff00', (60, 100, 50)),
|
155
|
+
('00ffff', (180, 100, 50)),
|
156
|
+
('ff00ff', (300, 100, 50)),
|
157
|
+
('800080', (300, 100, 25))])
|
158
|
+
def test_Color_hsl(
|
159
|
+
source: str,
|
160
|
+
expect: tuple[int, ...],
|
161
|
+
) -> None:
|
162
|
+
"""
|
163
|
+
Perform various tests associated with relevant routines.
|
164
|
+
|
165
|
+
:param source: Source color used when converting values.
|
166
|
+
:param expect: Expected output from the testing routine.
|
167
|
+
"""
|
168
|
+
|
169
|
+
assert Color(source).hsl == expect
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
def test_Color_cover() -> None:
|
174
|
+
"""
|
175
|
+
Perform various tests associated with relevant routines.
|
176
|
+
"""
|
177
|
+
|
178
|
+
color1 = Color('000001')
|
179
|
+
color2 = Color('#000001')
|
180
|
+
|
181
|
+
assert not (color1 > None) # type: ignore
|
182
|
+
assert not (color1 >= None) # type: ignore
|
183
|
+
assert not (color1 <= None) # type: ignore
|
184
|
+
assert not (color1 < None) # type: ignore
|
185
|
+
|
186
|
+
assert color1 - color2 == 0
|
187
|
+
assert color1 - '000001' == 0
|
188
|
+
assert color1 + color2 == 2
|
189
|
+
assert color1 + '000001' == 2
|
encommon/config/config.py
CHANGED
@@ -8,7 +8,6 @@ is permitted, for more information consult the project license file.
|
|
8
8
|
|
9
9
|
|
10
10
|
from copy import deepcopy
|
11
|
-
from typing import Any
|
12
11
|
from typing import Callable
|
13
12
|
from typing import Optional
|
14
13
|
from typing import TYPE_CHECKING
|
@@ -19,6 +18,7 @@ from .params import Params
|
|
19
18
|
from .paths import ConfigPaths
|
20
19
|
from .utils import config_paths
|
21
20
|
from ..crypts import Crypts
|
21
|
+
from ..types import DictStrAny
|
22
22
|
from ..types import merge_dicts
|
23
23
|
from ..types import setate
|
24
24
|
|
@@ -55,8 +55,8 @@ class Config:
|
|
55
55
|
|
56
56
|
__files: ConfigFiles
|
57
57
|
__paths: ConfigPaths
|
58
|
-
__cargs:
|
59
|
-
__sargs:
|
58
|
+
__cargs: DictStrAny
|
59
|
+
__sargs: DictStrAny
|
60
60
|
|
61
61
|
__model: Callable # type: ignore
|
62
62
|
|
@@ -67,11 +67,11 @@ class Config:
|
|
67
67
|
|
68
68
|
def __init__(
|
69
69
|
self,
|
70
|
-
*,
|
71
70
|
files: Optional['PATHABLE'] = None,
|
71
|
+
*,
|
72
72
|
paths: Optional['PATHABLE'] = None,
|
73
|
-
cargs: Optional[
|
74
|
-
sargs: Optional[
|
73
|
+
cargs: Optional[DictStrAny] = None,
|
74
|
+
sargs: Optional[DictStrAny] = None,
|
75
75
|
model: Optional[Callable] = None, # type: ignore
|
76
76
|
) -> None:
|
77
77
|
"""
|
@@ -133,14 +133,14 @@ class Config:
|
|
133
133
|
@property
|
134
134
|
def cargs(
|
135
135
|
self,
|
136
|
-
) ->
|
136
|
+
) -> DictStrAny:
|
137
137
|
"""
|
138
138
|
Return the value for the attribute from class instance.
|
139
139
|
|
140
140
|
:returns: Value for the attribute from class instance.
|
141
141
|
"""
|
142
142
|
|
143
|
-
returned:
|
143
|
+
returned: DictStrAny = {}
|
144
144
|
|
145
145
|
cargs = deepcopy(self.__cargs)
|
146
146
|
|
@@ -155,14 +155,14 @@ class Config:
|
|
155
155
|
@property
|
156
156
|
def sargs(
|
157
157
|
self,
|
158
|
-
) ->
|
158
|
+
) -> DictStrAny:
|
159
159
|
"""
|
160
160
|
Return the value for the attribute from class instance.
|
161
161
|
|
162
162
|
:returns: Value for the attribute from class instance.
|
163
163
|
"""
|
164
164
|
|
165
|
-
returned:
|
165
|
+
returned: DictStrAny = {}
|
166
166
|
|
167
167
|
sargs = deepcopy(self.__sargs)
|
168
168
|
|
@@ -177,16 +177,71 @@ class Config:
|
|
177
177
|
@property
|
178
178
|
def config(
|
179
179
|
self,
|
180
|
-
) ->
|
180
|
+
) -> DictStrAny:
|
181
181
|
"""
|
182
|
-
Return the configuration
|
182
|
+
Return the configuration dumped from the Pydantic model.
|
183
183
|
|
184
|
-
:returns: Configuration
|
184
|
+
:returns: Configuration dumped from the Pydantic model.
|
185
185
|
"""
|
186
186
|
|
187
187
|
return self.params.model_dump()
|
188
188
|
|
189
189
|
|
190
|
+
@property
|
191
|
+
def basic(
|
192
|
+
self,
|
193
|
+
) -> DictStrAny:
|
194
|
+
"""
|
195
|
+
Return the configuration source loaded from the objects.
|
196
|
+
|
197
|
+
:returns: Configuration source loaded from the objects.
|
198
|
+
"""
|
199
|
+
|
200
|
+
files = self.files
|
201
|
+
|
202
|
+
ferged = files.merge
|
203
|
+
|
204
|
+
merge_dicts(
|
205
|
+
dict1=ferged,
|
206
|
+
dict2=self.cargs,
|
207
|
+
force=True)
|
208
|
+
|
209
|
+
return deepcopy(ferged)
|
210
|
+
|
211
|
+
|
212
|
+
@property
|
213
|
+
def merge(
|
214
|
+
self,
|
215
|
+
) -> DictStrAny:
|
216
|
+
"""
|
217
|
+
Return the configuration source loaded from the objects.
|
218
|
+
|
219
|
+
:returns: Configuration source loaded from the objects.
|
220
|
+
"""
|
221
|
+
|
222
|
+
files = self.files
|
223
|
+
paths = self.paths
|
224
|
+
|
225
|
+
ferged = files.merge
|
226
|
+
perged = paths.merge
|
227
|
+
|
228
|
+
merge_dicts(
|
229
|
+
dict1=ferged,
|
230
|
+
dict2=self.cargs,
|
231
|
+
force=True)
|
232
|
+
|
233
|
+
values = perged.values()
|
234
|
+
|
235
|
+
for merge in values:
|
236
|
+
|
237
|
+
merge_dicts(
|
238
|
+
dict1=ferged,
|
239
|
+
dict2=merge,
|
240
|
+
force=False)
|
241
|
+
|
242
|
+
return deepcopy(ferged)
|
243
|
+
|
244
|
+
|
190
245
|
@property
|
191
246
|
def model(
|
192
247
|
self,
|
@@ -215,20 +270,12 @@ class Config:
|
|
215
270
|
if params is not None:
|
216
271
|
return params
|
217
272
|
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
merge_dicts(
|
222
|
-
dict1=merged,
|
223
|
-
dict2=self.cargs,
|
224
|
-
force=True)
|
225
|
-
|
226
|
-
params = self.model(**merged)
|
227
|
-
|
273
|
+
params = self.model(
|
274
|
+
**self.basic)
|
228
275
|
|
229
276
|
self.__params = params
|
230
277
|
|
231
|
-
return
|
278
|
+
return self.__params
|
232
279
|
|
233
280
|
|
234
281
|
@property
|
@@ -241,11 +288,14 @@ class Config:
|
|
241
288
|
:returns: Instance of Python logging library created.
|
242
289
|
"""
|
243
290
|
|
244
|
-
|
245
|
-
|
291
|
+
logger = self.__logger
|
292
|
+
params = self.params
|
293
|
+
|
294
|
+
if logger is not None:
|
295
|
+
return logger
|
246
296
|
|
247
297
|
logger = Logger(
|
248
|
-
|
298
|
+
params.enlogger)
|
249
299
|
|
250
300
|
self.__logger = logger
|
251
301
|
|
@@ -262,11 +312,14 @@ class Config:
|
|
262
312
|
:returns: Instance of the encryption instance created.
|
263
313
|
"""
|
264
314
|
|
265
|
-
|
266
|
-
|
315
|
+
crypts = self.__crypts
|
316
|
+
params = self.params
|
317
|
+
|
318
|
+
if crypts is not None:
|
319
|
+
return crypts
|
267
320
|
|
268
321
|
crypts = Crypts(
|
269
|
-
|
322
|
+
params.encrypts)
|
270
323
|
|
271
324
|
self.__crypts = crypts
|
272
325
|
|
encommon/config/files.py
CHANGED
@@ -9,14 +9,15 @@ is permitted, for more information consult the project license file.
|
|
9
9
|
|
10
10
|
from copy import deepcopy
|
11
11
|
from pathlib import Path
|
12
|
-
from typing import Any
|
13
12
|
from typing import Optional
|
14
13
|
from typing import TYPE_CHECKING
|
15
14
|
|
16
15
|
from .utils import config_load
|
17
16
|
from .utils import config_path
|
18
17
|
from .utils import config_paths
|
18
|
+
from ..types import DictStrAny
|
19
19
|
from ..types import merge_dicts
|
20
|
+
from ..types import sort_dict
|
20
21
|
|
21
22
|
if TYPE_CHECKING:
|
22
23
|
from ..utils.common import PATHABLE
|
@@ -31,7 +32,7 @@ class ConfigFile:
|
|
31
32
|
"""
|
32
33
|
|
33
34
|
path: Path
|
34
|
-
config:
|
35
|
+
config: DictStrAny
|
35
36
|
|
36
37
|
|
37
38
|
def __init__(
|
@@ -61,7 +62,7 @@ class ConfigFiles:
|
|
61
62
|
paths: tuple[Path, ...]
|
62
63
|
config: dict[str, ConfigFile]
|
63
64
|
|
64
|
-
|
65
|
+
__merge: Optional[DictStrAny]
|
65
66
|
|
66
67
|
|
67
68
|
def __init__(
|
@@ -79,13 +80,13 @@ class ConfigFiles:
|
|
79
80
|
str(x): ConfigFile(x)
|
80
81
|
for x in self.paths}
|
81
82
|
|
82
|
-
self.
|
83
|
+
self.__merge = None
|
83
84
|
|
84
85
|
|
85
86
|
@property
|
86
|
-
def
|
87
|
+
def merge(
|
87
88
|
self,
|
88
|
-
) ->
|
89
|
+
) -> DictStrAny:
|
89
90
|
"""
|
90
91
|
Return the configuration in dictionary format for files.
|
91
92
|
|
@@ -93,12 +94,12 @@ class ConfigFiles:
|
|
93
94
|
"""
|
94
95
|
|
95
96
|
config = self.config
|
96
|
-
|
97
|
+
merge = self.__merge
|
97
98
|
|
98
|
-
if
|
99
|
-
return deepcopy(
|
99
|
+
if merge is not None:
|
100
|
+
return deepcopy(merge)
|
100
101
|
|
101
|
-
|
102
|
+
merge = {}
|
102
103
|
|
103
104
|
|
104
105
|
for file in config.values():
|
@@ -106,11 +107,13 @@ class ConfigFiles:
|
|
106
107
|
source = file.config
|
107
108
|
|
108
109
|
merge_dicts(
|
109
|
-
dict1=
|
110
|
+
dict1=merge,
|
110
111
|
dict2=deepcopy(source),
|
111
112
|
force=False)
|
112
113
|
|
113
114
|
|
114
|
-
|
115
|
+
merge = sort_dict(merge)
|
115
116
|
|
116
|
-
|
117
|
+
self.__merge = merge
|
118
|
+
|
119
|
+
return deepcopy(merge)
|
encommon/config/logger.py
CHANGED
@@ -28,7 +28,7 @@ from typing import Optional
|
|
28
28
|
from typing import TYPE_CHECKING
|
29
29
|
|
30
30
|
from .utils import config_path
|
31
|
-
from ..times import
|
31
|
+
from ..times import Time
|
32
32
|
from ..types import Empty
|
33
33
|
from ..types.strings import COMMAD
|
34
34
|
from ..types.strings import COMMAS
|
@@ -83,7 +83,7 @@ class Message:
|
|
83
83
|
"""
|
84
84
|
|
85
85
|
__level: LOGLEVELS
|
86
|
-
__time:
|
86
|
+
__time: Time
|
87
87
|
__fields: dict[str, str] = {}
|
88
88
|
|
89
89
|
|
@@ -98,7 +98,7 @@ class Message:
|
|
98
98
|
"""
|
99
99
|
|
100
100
|
self.__level = level
|
101
|
-
self.__time =
|
101
|
+
self.__time = Time(time)
|
102
102
|
self.__fields = {}
|
103
103
|
|
104
104
|
items = kwargs.items()
|
@@ -122,6 +122,11 @@ class Message:
|
|
122
122
|
value = COMMAD.join(values)
|
123
123
|
|
124
124
|
|
125
|
+
if (isinstance(value, Time)
|
126
|
+
and key == 'elapsed'):
|
127
|
+
value = value.since
|
128
|
+
|
129
|
+
|
125
130
|
if (isinstance(value, float)
|
126
131
|
and key == 'elapsed'):
|
127
132
|
|
@@ -183,14 +188,14 @@ class Message:
|
|
183
188
|
@property
|
184
189
|
def time(
|
185
190
|
self,
|
186
|
-
) ->
|
191
|
+
) -> Time:
|
187
192
|
"""
|
188
193
|
Return the value for the attribute from class instance.
|
189
194
|
|
190
195
|
:returns: Value for the attribute from class instance.
|
191
196
|
"""
|
192
197
|
|
193
|
-
return
|
198
|
+
return Time(self.__time)
|
194
199
|
|
195
200
|
|
196
201
|
@property
|
encommon/config/params.py
CHANGED
@@ -8,73 +8,89 @@ is permitted, for more information consult the project license file.
|
|
8
8
|
|
9
9
|
|
10
10
|
from pathlib import Path
|
11
|
+
from typing import Annotated
|
12
|
+
from typing import Any
|
11
13
|
from typing import Optional
|
12
14
|
|
13
|
-
from pydantic import
|
15
|
+
from pydantic import Field
|
14
16
|
|
15
17
|
from .logger import LOGLEVELS
|
16
18
|
from ..crypts import CryptsParams
|
19
|
+
from ..types import BaseModel
|
17
20
|
|
18
21
|
|
19
22
|
|
20
23
|
class ConfigParams(BaseModel, extra='forbid'):
|
21
24
|
"""
|
22
25
|
Process and validate the core configuration parameters.
|
23
|
-
|
24
|
-
:param paths: Complete or relative path to config paths.
|
25
|
-
:param data: Keyword arguments passed to Pydantic model.
|
26
|
-
Parameter is picked up by autodoc, please ignore.
|
27
26
|
"""
|
28
27
|
|
29
|
-
paths:
|
28
|
+
paths: Annotated[
|
29
|
+
Optional[list[str]],
|
30
|
+
Field(None,
|
31
|
+
description='Location of configuration files',
|
32
|
+
min_length=1)]
|
30
33
|
|
31
34
|
|
32
35
|
|
33
36
|
class LoggerParams(BaseModel, extra='forbid'):
|
34
37
|
"""
|
35
38
|
Process and validate the core configuration parameters.
|
36
|
-
|
37
|
-
:param stdo_level: Minimum level for the message to pass.
|
38
|
-
:param file_level: Minimum level for the message to pass.
|
39
|
-
:param file_path: Enables writing to the filesystem path.
|
40
39
|
"""
|
41
40
|
|
42
|
-
stdo_level:
|
43
|
-
|
44
|
-
|
41
|
+
stdo_level: Annotated[
|
42
|
+
Optional[LOGLEVELS],
|
43
|
+
Field(None,
|
44
|
+
description='Minimum logging message level',
|
45
|
+
min_length=1)]
|
46
|
+
|
47
|
+
file_level: Annotated[
|
48
|
+
Optional[LOGLEVELS],
|
49
|
+
Field(None,
|
50
|
+
description='Minimum logging message level',
|
51
|
+
min_length=1)]
|
52
|
+
|
53
|
+
file_path: Annotated[
|
54
|
+
Optional[str],
|
55
|
+
Field(None,
|
56
|
+
description='Enable output to the log file',
|
57
|
+
min_length=1)]
|
45
58
|
|
46
59
|
|
47
60
|
def __init__(
|
48
61
|
self,
|
49
|
-
|
50
|
-
|
51
|
-
file_path: Optional[str | Path] = None,
|
62
|
+
/,
|
63
|
+
**data: Any,
|
52
64
|
) -> None:
|
53
65
|
"""
|
54
66
|
Initialize instance for class using provided parameters.
|
55
67
|
"""
|
56
68
|
|
57
|
-
|
58
|
-
file_path = str(file_path)
|
69
|
+
file_path = data.get('file_path')
|
59
70
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
71
|
+
if isinstance(file_path, Path):
|
72
|
+
data['file_path'] = str(file_path)
|
73
|
+
|
74
|
+
super().__init__(**data)
|
64
75
|
|
65
76
|
|
66
77
|
|
67
78
|
class Params(BaseModel, extra='forbid'):
|
68
79
|
"""
|
69
80
|
Process and validate the core configuration parameters.
|
70
|
-
|
71
|
-
:param enconfig: Configuration for the Config instance.
|
72
|
-
:param enlogger: Configuration for the Logger instance.
|
73
|
-
:param encrypts: Configuration for the Crypts instance.
|
74
|
-
:param data: Keyword arguments passed to Pydantic model.
|
75
|
-
Parameter is picked up by autodoc, please ignore.
|
76
81
|
"""
|
77
82
|
|
78
|
-
enconfig:
|
79
|
-
|
80
|
-
|
83
|
+
enconfig: Annotated[
|
84
|
+
Optional[ConfigParams],
|
85
|
+
Field(None,
|
86
|
+
description='Parameters for Config instance')]
|
87
|
+
|
88
|
+
enlogger: Annotated[
|
89
|
+
Optional[LoggerParams],
|
90
|
+
Field(None,
|
91
|
+
description='Parameters for Logger instance')]
|
92
|
+
|
93
|
+
encrypts: Annotated[
|
94
|
+
Optional[CryptsParams],
|
95
|
+
Field(None,
|
96
|
+
description='Parameters for Crypts instance')]
|