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
encommon/__init__.py
CHANGED
@@ -7,7 +7,6 @@ is permitted, for more information consult the project license file.
|
|
7
7
|
|
8
8
|
|
9
9
|
|
10
|
-
from os import environ
|
11
10
|
from pathlib import Path
|
12
11
|
|
13
12
|
|
@@ -16,14 +15,10 @@ PROJECT = Path(__file__).parent
|
|
16
15
|
WORKSPACE = PROJECT.parents[2]
|
17
16
|
|
18
17
|
VERSION = (
|
19
|
-
PROJECT
|
20
|
-
.joinpath('version.txt')
|
18
|
+
(PROJECT / 'version.txt')
|
21
19
|
.read_text(encoding='utf-8')
|
22
20
|
.splitlines()[0].strip())
|
23
21
|
|
24
|
-
__version__ = VERSION
|
25
|
-
|
26
22
|
|
27
23
|
|
28
|
-
|
29
|
-
environ.get('ENPYRWS') == '1')
|
24
|
+
__version__ = VERSION
|
@@ -0,0 +1,14 @@
|
|
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 .color import Color
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
__all__ = ['Color']
|
encommon/colors/color.py
ADDED
@@ -0,0 +1,518 @@
|
|
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 contextlib import suppress
|
11
|
+
from typing import Union
|
12
|
+
|
13
|
+
from ..types import strplwr
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
class Color:
|
18
|
+
"""
|
19
|
+
Covert colors to various forms using provided hex value.
|
20
|
+
|
21
|
+
Example
|
22
|
+
-------
|
23
|
+
>>> color = Color('#003333')
|
24
|
+
>>> color.rgb
|
25
|
+
(0, 51, 51)
|
26
|
+
>>> color.hsl
|
27
|
+
(180, 100, 10)
|
28
|
+
>>> color.xyz
|
29
|
+
(1.7814, 2.6067, 3.5412)
|
30
|
+
>>> color.xy
|
31
|
+
(0.2247, 0.3287)
|
32
|
+
|
33
|
+
Example
|
34
|
+
-------
|
35
|
+
>>> color1 = Color('#003333')
|
36
|
+
>>> color2 = Color('#330000')
|
37
|
+
>>> color1 - color2
|
38
|
+
Color('#32CCCD')
|
39
|
+
>>> color1 + color2
|
40
|
+
Color('#333333')
|
41
|
+
|
42
|
+
:param source: Source color used when converting values.
|
43
|
+
"""
|
44
|
+
|
45
|
+
__source: str
|
46
|
+
|
47
|
+
|
48
|
+
def __init__(
|
49
|
+
self,
|
50
|
+
source: str,
|
51
|
+
) -> None:
|
52
|
+
"""
|
53
|
+
Initialize instance for class using provided parameters.
|
54
|
+
"""
|
55
|
+
|
56
|
+
if source[:1] == '#':
|
57
|
+
source = source[1:]
|
58
|
+
|
59
|
+
source = strplwr(source)
|
60
|
+
|
61
|
+
self.__source = source
|
62
|
+
|
63
|
+
|
64
|
+
def __repr__(
|
65
|
+
self,
|
66
|
+
) -> str:
|
67
|
+
"""
|
68
|
+
Built-in method for representing the values for instance.
|
69
|
+
|
70
|
+
:returns: String representation for values from instance.
|
71
|
+
"""
|
72
|
+
|
73
|
+
color = self.__str__()
|
74
|
+
|
75
|
+
return f"Color('{color}')"
|
76
|
+
|
77
|
+
|
78
|
+
def __hash__(
|
79
|
+
self,
|
80
|
+
) -> int:
|
81
|
+
"""
|
82
|
+
Built-in method called when performing hashing operation.
|
83
|
+
|
84
|
+
:returns: Boolean indicating outcome from the operation.
|
85
|
+
"""
|
86
|
+
|
87
|
+
color = int(
|
88
|
+
self.__source, 16)
|
89
|
+
|
90
|
+
return int(1e9 + color)
|
91
|
+
|
92
|
+
|
93
|
+
def __str__(
|
94
|
+
self,
|
95
|
+
) -> str:
|
96
|
+
"""
|
97
|
+
Built-in method for representing the values for instance.
|
98
|
+
|
99
|
+
:returns: String representation for values from instance.
|
100
|
+
"""
|
101
|
+
|
102
|
+
color = self.__source.upper()
|
103
|
+
|
104
|
+
return f'#{color}'
|
105
|
+
|
106
|
+
|
107
|
+
def __int__(
|
108
|
+
self,
|
109
|
+
) -> int:
|
110
|
+
"""
|
111
|
+
Built-in method representing numeric value for instance.
|
112
|
+
|
113
|
+
:returns: Numeric representation for value in instance.
|
114
|
+
"""
|
115
|
+
|
116
|
+
return int(self.__source, 16)
|
117
|
+
|
118
|
+
|
119
|
+
def __float__(
|
120
|
+
self,
|
121
|
+
) -> float:
|
122
|
+
"""
|
123
|
+
Built-in method representing numeric value for instance.
|
124
|
+
|
125
|
+
:returns: Numeric representation for value in instance.
|
126
|
+
"""
|
127
|
+
|
128
|
+
return float(self.__int__())
|
129
|
+
|
130
|
+
|
131
|
+
def __add__(
|
132
|
+
self,
|
133
|
+
other: Union[int, str, 'Color'],
|
134
|
+
) -> 'Color':
|
135
|
+
"""
|
136
|
+
Built-in method for mathematically processing the value.
|
137
|
+
|
138
|
+
:param other: Other value being compared with instance.
|
139
|
+
:returns: Python timedelta object containing the answer.
|
140
|
+
"""
|
141
|
+
|
142
|
+
if isinstance(other, str):
|
143
|
+
other = Color(other)
|
144
|
+
|
145
|
+
source = self.__int__()
|
146
|
+
_source = int(other)
|
147
|
+
|
148
|
+
outcome = abs(source + _source)
|
149
|
+
|
150
|
+
result = f'{outcome:06x}'
|
151
|
+
|
152
|
+
return Color(result)
|
153
|
+
|
154
|
+
|
155
|
+
def __sub__(
|
156
|
+
self,
|
157
|
+
other: Union[int, str, 'Color'],
|
158
|
+
) -> 'Color':
|
159
|
+
"""
|
160
|
+
Built-in method for mathematically processing the value.
|
161
|
+
|
162
|
+
:param other: Other value being compared with instance.
|
163
|
+
:returns: Python timedelta object containing the answer.
|
164
|
+
"""
|
165
|
+
|
166
|
+
if isinstance(other, str):
|
167
|
+
other = Color(other)
|
168
|
+
|
169
|
+
source = self.__int__()
|
170
|
+
_source = int(other)
|
171
|
+
|
172
|
+
outcome = abs(source - _source)
|
173
|
+
|
174
|
+
result = f'{outcome:06x}'
|
175
|
+
|
176
|
+
return Color(result)
|
177
|
+
|
178
|
+
|
179
|
+
def __eq__(
|
180
|
+
self,
|
181
|
+
other: object,
|
182
|
+
) -> bool:
|
183
|
+
"""
|
184
|
+
Built-in method for comparing this instance with another.
|
185
|
+
|
186
|
+
:param other: Other value being compared with instance.
|
187
|
+
:returns: Boolean indicating outcome from the operation.
|
188
|
+
"""
|
189
|
+
|
190
|
+
with suppress(Exception):
|
191
|
+
|
192
|
+
if isinstance(other, int):
|
193
|
+
other = f'{other:06x}'
|
194
|
+
|
195
|
+
if isinstance(other, str):
|
196
|
+
other = Color(other)
|
197
|
+
|
198
|
+
assert hasattr(other, 'source')
|
199
|
+
|
200
|
+
source = self.__source
|
201
|
+
_source = other.source
|
202
|
+
|
203
|
+
assert isinstance(_source, str)
|
204
|
+
|
205
|
+
return source == _source
|
206
|
+
|
207
|
+
return False
|
208
|
+
|
209
|
+
|
210
|
+
def __ne__(
|
211
|
+
self,
|
212
|
+
other: object,
|
213
|
+
) -> bool:
|
214
|
+
"""
|
215
|
+
Built-in method for comparing this instance with another.
|
216
|
+
|
217
|
+
:param other: Other value being compared with instance.
|
218
|
+
:returns: Boolean indicating outcome from the operation.
|
219
|
+
"""
|
220
|
+
|
221
|
+
return not self.__eq__(other)
|
222
|
+
|
223
|
+
|
224
|
+
def __gt__(
|
225
|
+
self,
|
226
|
+
other: Union[int, str, 'Color'],
|
227
|
+
) -> bool:
|
228
|
+
"""
|
229
|
+
Built-in method for comparing this instance with another.
|
230
|
+
|
231
|
+
:param other: Other value being compared with instance.
|
232
|
+
:returns: Boolean indicating outcome from the operation.
|
233
|
+
"""
|
234
|
+
|
235
|
+
with suppress(Exception):
|
236
|
+
|
237
|
+
if isinstance(other, int):
|
238
|
+
other = f'{other:06x}'
|
239
|
+
|
240
|
+
if isinstance(other, str):
|
241
|
+
other = Color(other)
|
242
|
+
|
243
|
+
assert hasattr(other, 'source')
|
244
|
+
|
245
|
+
source = self.__source
|
246
|
+
_source = other.source
|
247
|
+
|
248
|
+
assert isinstance(_source, str)
|
249
|
+
|
250
|
+
return source > _source
|
251
|
+
|
252
|
+
return False
|
253
|
+
|
254
|
+
|
255
|
+
def __ge__(
|
256
|
+
self,
|
257
|
+
other: Union[int, str, 'Color'],
|
258
|
+
) -> bool:
|
259
|
+
"""
|
260
|
+
Built-in method for comparing this instance with another.
|
261
|
+
|
262
|
+
:param other: Other value being compared with instance.
|
263
|
+
:returns: Boolean indicating outcome from the operation.
|
264
|
+
"""
|
265
|
+
|
266
|
+
with suppress(Exception):
|
267
|
+
|
268
|
+
if isinstance(other, int):
|
269
|
+
other = f'{other:06x}'
|
270
|
+
|
271
|
+
if isinstance(other, str):
|
272
|
+
other = Color(other)
|
273
|
+
|
274
|
+
assert hasattr(other, 'source')
|
275
|
+
|
276
|
+
source = self.__source
|
277
|
+
_source = other.source
|
278
|
+
|
279
|
+
assert isinstance(_source, str)
|
280
|
+
|
281
|
+
return source >= _source
|
282
|
+
|
283
|
+
return False
|
284
|
+
|
285
|
+
|
286
|
+
def __lt__(
|
287
|
+
self,
|
288
|
+
other: Union[int, str, 'Color'],
|
289
|
+
) -> bool:
|
290
|
+
"""
|
291
|
+
Built-in method for comparing this instance with another.
|
292
|
+
|
293
|
+
:param other: Other value being compared with instance.
|
294
|
+
:returns: Boolean indicating outcome from the operation.
|
295
|
+
"""
|
296
|
+
|
297
|
+
with suppress(Exception):
|
298
|
+
|
299
|
+
if isinstance(other, int):
|
300
|
+
other = f'{other:06x}'
|
301
|
+
|
302
|
+
if isinstance(other, str):
|
303
|
+
other = Color(other)
|
304
|
+
|
305
|
+
assert hasattr(other, 'source')
|
306
|
+
|
307
|
+
source = self.__source
|
308
|
+
_source = other.source
|
309
|
+
|
310
|
+
assert isinstance(_source, str)
|
311
|
+
|
312
|
+
return source < _source
|
313
|
+
|
314
|
+
return False
|
315
|
+
|
316
|
+
|
317
|
+
def __le__(
|
318
|
+
self,
|
319
|
+
other: Union[int, str, 'Color'],
|
320
|
+
) -> bool:
|
321
|
+
"""
|
322
|
+
Built-in method for comparing this instance with another.
|
323
|
+
|
324
|
+
:param other: Other value being compared with instance.
|
325
|
+
:returns: Boolean indicating outcome from the operation.
|
326
|
+
"""
|
327
|
+
|
328
|
+
with suppress(Exception):
|
329
|
+
|
330
|
+
if isinstance(other, int):
|
331
|
+
other = f'{other:06x}'
|
332
|
+
|
333
|
+
if isinstance(other, str):
|
334
|
+
other = Color(other)
|
335
|
+
|
336
|
+
assert hasattr(other, 'source')
|
337
|
+
|
338
|
+
source = self.__source
|
339
|
+
_source = other.source
|
340
|
+
|
341
|
+
assert isinstance(_source, str)
|
342
|
+
|
343
|
+
return source <= _source
|
344
|
+
|
345
|
+
return False
|
346
|
+
|
347
|
+
|
348
|
+
@property
|
349
|
+
def source(
|
350
|
+
self,
|
351
|
+
) -> str:
|
352
|
+
"""
|
353
|
+
Return the value for the attribute from class instance.
|
354
|
+
|
355
|
+
:returns: Value for the attribute from class instance.
|
356
|
+
"""
|
357
|
+
|
358
|
+
return self.__source
|
359
|
+
|
360
|
+
|
361
|
+
@property
|
362
|
+
def rgb(
|
363
|
+
self,
|
364
|
+
) -> tuple[int, int, int]:
|
365
|
+
"""
|
366
|
+
Return the value for the attribute from class instance.
|
367
|
+
|
368
|
+
:returns: Value for the attribute from class instance.
|
369
|
+
"""
|
370
|
+
|
371
|
+
color = self.__source
|
372
|
+
|
373
|
+
return (
|
374
|
+
int(color[0:2], 16),
|
375
|
+
int(color[2:4], 16),
|
376
|
+
int(color[4:6], 16))
|
377
|
+
|
378
|
+
|
379
|
+
@property
|
380
|
+
def xyz(
|
381
|
+
self,
|
382
|
+
) -> tuple[float, float, float]:
|
383
|
+
"""
|
384
|
+
Return the value for the attribute from class instance.
|
385
|
+
|
386
|
+
:returns: Value for the attribute from class instance.
|
387
|
+
"""
|
388
|
+
|
389
|
+
_red, _grn, _blu = self.rgb
|
390
|
+
|
391
|
+
red = _red / 255.0
|
392
|
+
grn = _grn / 255.0
|
393
|
+
blu = _blu / 255.0
|
394
|
+
|
395
|
+
if red > 0.04045:
|
396
|
+
red += 0.055
|
397
|
+
red /= 1.055
|
398
|
+
red **= 2.4
|
399
|
+
|
400
|
+
else:
|
401
|
+
red = red / 12.92
|
402
|
+
|
403
|
+
if grn > 0.04045:
|
404
|
+
grn += 0.055
|
405
|
+
grn /= 1.055
|
406
|
+
grn **= 2.4
|
407
|
+
|
408
|
+
else:
|
409
|
+
grn = grn / 12.92
|
410
|
+
|
411
|
+
if blu > 0.04045:
|
412
|
+
blu += 0.055
|
413
|
+
blu /= 1.055
|
414
|
+
blu **= 2.4
|
415
|
+
|
416
|
+
else:
|
417
|
+
blu = blu / 12.92
|
418
|
+
|
419
|
+
red = red * 100
|
420
|
+
grn = grn * 100
|
421
|
+
blu = blu * 100
|
422
|
+
|
423
|
+
x = (
|
424
|
+
red * 0.4124
|
425
|
+
+ grn * 0.3576
|
426
|
+
+ blu * 0.1805)
|
427
|
+
|
428
|
+
y = (
|
429
|
+
red * 0.2126
|
430
|
+
+ grn * 0.7152
|
431
|
+
+ blu * 0.0722)
|
432
|
+
|
433
|
+
z = (
|
434
|
+
red * 0.0193
|
435
|
+
+ grn * 0.1192
|
436
|
+
+ blu * 0.9505)
|
437
|
+
|
438
|
+
x = round(x, 4)
|
439
|
+
y = round(y, 4)
|
440
|
+
z = round(z, 4)
|
441
|
+
|
442
|
+
return x, y, z
|
443
|
+
|
444
|
+
|
445
|
+
@property
|
446
|
+
def xy(
|
447
|
+
self,
|
448
|
+
) -> tuple[float, float]:
|
449
|
+
"""
|
450
|
+
Return the value for the attribute from class instance.
|
451
|
+
|
452
|
+
:returns: Value for the attribute from class instance.
|
453
|
+
"""
|
454
|
+
|
455
|
+
x, y, z = self.xyz
|
456
|
+
|
457
|
+
if x + y + z == 0:
|
458
|
+
return 0, 0
|
459
|
+
|
460
|
+
cx = x / (x + y + z)
|
461
|
+
cy = y / (x + y + z)
|
462
|
+
|
463
|
+
cx = round(cx, 4)
|
464
|
+
cy = round(cy, 4)
|
465
|
+
|
466
|
+
return cx, cy
|
467
|
+
|
468
|
+
|
469
|
+
@property
|
470
|
+
def hsl(
|
471
|
+
self,
|
472
|
+
) -> tuple[int, int, int]:
|
473
|
+
"""
|
474
|
+
Return the value for the attribute from class instance.
|
475
|
+
|
476
|
+
:returns: Value for the attribute from class instance.
|
477
|
+
"""
|
478
|
+
|
479
|
+
_red, _grn, _blu = self.rgb
|
480
|
+
|
481
|
+
red = _red / 255
|
482
|
+
grn = _grn / 255
|
483
|
+
blu = _blu / 255
|
484
|
+
|
485
|
+
mam = max(red, grn, blu)
|
486
|
+
mim = min(red, grn, blu)
|
487
|
+
|
488
|
+
hue = sat = 0.0
|
489
|
+
lev = (mam + mim) / 2
|
490
|
+
|
491
|
+
if mam != mim:
|
492
|
+
|
493
|
+
delta = mam - mim
|
494
|
+
|
495
|
+
sat = (
|
496
|
+
delta / (2 - mam - mim)
|
497
|
+
if lev > 0.5
|
498
|
+
else delta / (mam + mim))
|
499
|
+
|
500
|
+
if mam == red:
|
501
|
+
hue = (grn - blu) / delta
|
502
|
+
hue += 6 if grn < blu else 0
|
503
|
+
|
504
|
+
elif mam == grn:
|
505
|
+
hue = (blu - red) / delta
|
506
|
+
hue += 2
|
507
|
+
|
508
|
+
elif mam == blu:
|
509
|
+
hue = (red - grn) / delta
|
510
|
+
hue += 4
|
511
|
+
|
512
|
+
hue /= 6
|
513
|
+
|
514
|
+
hue = int(hue * 360)
|
515
|
+
sat = int(sat * 100)
|
516
|
+
lev = int(lev * 100)
|
517
|
+
|
518
|
+
return hue, sat, lev
|