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/times/windows.py
CHANGED
@@ -21,7 +21,7 @@ from sqlalchemy.orm import sessionmaker
|
|
21
21
|
|
22
22
|
from .common import PARSABLE
|
23
23
|
from .params import WindowsParams
|
24
|
-
from .
|
24
|
+
from .time import Time
|
25
25
|
from .window import Window
|
26
26
|
|
27
27
|
if TYPE_CHECKING:
|
@@ -114,8 +114,8 @@ class Windows:
|
|
114
114
|
# pylint: disable=unsubscriptable-object
|
115
115
|
sessionmaker[Session])
|
116
116
|
|
117
|
-
__start:
|
118
|
-
__stop:
|
117
|
+
__start: Time
|
118
|
+
__stop: Time
|
119
119
|
|
120
120
|
__windows: WINDOWS
|
121
121
|
|
@@ -147,8 +147,8 @@ class Windows:
|
|
147
147
|
self.__make_engine()
|
148
148
|
|
149
149
|
|
150
|
-
start =
|
151
|
-
stop =
|
150
|
+
start = Time(start)
|
151
|
+
stop = Time(stop)
|
152
152
|
|
153
153
|
assert stop > start
|
154
154
|
|
@@ -249,27 +249,27 @@ class Windows:
|
|
249
249
|
@property
|
250
250
|
def start(
|
251
251
|
self,
|
252
|
-
) ->
|
252
|
+
) -> Time:
|
253
253
|
"""
|
254
254
|
Return the value for the attribute from class instance.
|
255
255
|
|
256
256
|
:returns: Value for the attribute from class instance.
|
257
257
|
"""
|
258
258
|
|
259
|
-
return
|
259
|
+
return Time(self.__start)
|
260
260
|
|
261
261
|
|
262
262
|
@property
|
263
263
|
def stop(
|
264
264
|
self,
|
265
|
-
) ->
|
265
|
+
) -> Time:
|
266
266
|
"""
|
267
267
|
Return the value for the attribute from class instance.
|
268
268
|
|
269
269
|
:returns: Value for the attribute from class instance.
|
270
270
|
"""
|
271
271
|
|
272
|
-
return
|
272
|
+
return Time(self.__stop)
|
273
273
|
|
274
274
|
|
275
275
|
@property
|
@@ -386,7 +386,7 @@ class Windows:
|
|
386
386
|
|
387
387
|
for unique, window in items:
|
388
388
|
|
389
|
-
update =
|
389
|
+
update = Time('now')
|
390
390
|
|
391
391
|
append = WindowsTable(
|
392
392
|
group=group,
|
encommon/types/__init__.py
CHANGED
@@ -7,27 +7,45 @@ is permitted, for more information consult the project license file.
|
|
7
7
|
|
8
8
|
|
9
9
|
|
10
|
+
from .classes import BaseModel
|
11
|
+
from .classes import clsname
|
12
|
+
from .classes import lattrs
|
10
13
|
from .dicts import merge_dicts
|
11
14
|
from .dicts import sort_dict
|
12
15
|
from .empty import Empty
|
16
|
+
from .lists import inlist
|
13
17
|
from .notate import delate
|
14
18
|
from .notate import getate
|
15
19
|
from .notate import setate
|
16
20
|
from .strings import hasstr
|
17
21
|
from .strings import inrepr
|
18
22
|
from .strings import instr
|
19
|
-
from .strings import
|
23
|
+
from .strings import rplstr
|
24
|
+
from .strings import strplwr
|
25
|
+
from .types import DictStrAny
|
26
|
+
from .types import NCFalse
|
27
|
+
from .types import NCNone
|
28
|
+
from .types import NCTrue
|
20
29
|
|
21
30
|
|
22
31
|
|
23
32
|
__all__ = [
|
33
|
+
'BaseModel',
|
34
|
+
'clsname',
|
24
35
|
'delate',
|
36
|
+
'DictStrAny',
|
25
37
|
'Empty',
|
26
38
|
'getate',
|
27
39
|
'hasstr',
|
40
|
+
'inlist',
|
28
41
|
'inrepr',
|
29
42
|
'instr',
|
43
|
+
'lattrs',
|
30
44
|
'merge_dicts',
|
45
|
+
'rplstr',
|
31
46
|
'setate',
|
32
47
|
'sort_dict',
|
33
|
-
'
|
48
|
+
'strplwr',
|
49
|
+
'NCTrue',
|
50
|
+
'NCFalse',
|
51
|
+
'NCNone']
|
@@ -0,0 +1,84 @@
|
|
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 pydantic import BaseModel as Pydantic
|
11
|
+
|
12
|
+
from .types import DictStrAny
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
class BaseModel(Pydantic, extra='forbid'):
|
17
|
+
"""
|
18
|
+
Pydantic base model but with added methods and routines.
|
19
|
+
|
20
|
+
:param data: Keyword arguments passed to Pydantic model.
|
21
|
+
"""
|
22
|
+
|
23
|
+
|
24
|
+
@property
|
25
|
+
def model_dumped(
|
26
|
+
self,
|
27
|
+
) -> DictStrAny:
|
28
|
+
"""
|
29
|
+
Return the facts about the attributes from the instance.
|
30
|
+
|
31
|
+
:returns: Facts about the attributes from the instance.
|
32
|
+
"""
|
33
|
+
|
34
|
+
return self.model_dump()
|
35
|
+
|
36
|
+
|
37
|
+
@property
|
38
|
+
def model_pruned(
|
39
|
+
self,
|
40
|
+
) -> DictStrAny:
|
41
|
+
"""
|
42
|
+
Return the facts about the attributes from the instance.
|
43
|
+
|
44
|
+
:returns: Facts about the attributes from the instance.
|
45
|
+
"""
|
46
|
+
|
47
|
+
return self.model_dump(
|
48
|
+
exclude_none=True)
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
def clsname(
|
53
|
+
cls: object,
|
54
|
+
) -> str:
|
55
|
+
"""
|
56
|
+
Return the actual definition name for the Python class.
|
57
|
+
|
58
|
+
:param cls: Provided Python class related to operation.
|
59
|
+
:returns: Actual definition name for the Python class.
|
60
|
+
"""
|
61
|
+
|
62
|
+
assert hasattr(
|
63
|
+
cls, '__class__')
|
64
|
+
|
65
|
+
_cls = cls.__class__
|
66
|
+
|
67
|
+
assert hasattr(
|
68
|
+
_cls, '__name__')
|
69
|
+
|
70
|
+
return str(_cls.__name__)
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
def lattrs(
|
75
|
+
cls: object,
|
76
|
+
) -> list[str]:
|
77
|
+
"""
|
78
|
+
Return the list of attributes which are found in class.
|
79
|
+
|
80
|
+
:param cls: Provided Python class related to operation.
|
81
|
+
:returns: List of attributes which are found in class.
|
82
|
+
"""
|
83
|
+
|
84
|
+
return list(cls.__dict__)
|
encommon/types/lists.py
ADDED
@@ -0,0 +1,33 @@
|
|
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 typing import Any
|
11
|
+
from typing import Sequence
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
def inlist(
|
16
|
+
needle: Any, # noqa: ANN401
|
17
|
+
haystack: Sequence[Any],
|
18
|
+
) -> bool:
|
19
|
+
"""
|
20
|
+
Return the boolean indicating whether needle in haystack.
|
21
|
+
|
22
|
+
Example
|
23
|
+
-------
|
24
|
+
>>> haystack = [1, 2, 3]
|
25
|
+
>>> inlist(2, haystack)
|
26
|
+
True
|
27
|
+
|
28
|
+
:param needle: Provided item that may be within haystack.
|
29
|
+
:param haystack: List of items which may contain needle.
|
30
|
+
:returns: Boolean indicating whether needle in haystack.
|
31
|
+
"""
|
32
|
+
|
33
|
+
return needle in haystack
|
encommon/types/notate.py
CHANGED
@@ -15,6 +15,7 @@ from typing import Optional
|
|
15
15
|
from typing import Union
|
16
16
|
|
17
17
|
from .empty import Empty
|
18
|
+
from .types import DictStrAny
|
18
19
|
|
19
20
|
|
20
21
|
|
@@ -25,7 +26,7 @@ _RECURSE = dict
|
|
25
26
|
|
26
27
|
|
27
28
|
_SETABLE = Union[
|
28
|
-
|
29
|
+
DictStrAny,
|
29
30
|
list[Any]]
|
30
31
|
|
31
32
|
_GETABLE = Union[
|
encommon/types/strings.py
CHANGED
@@ -21,22 +21,24 @@ SPACED = ' '
|
|
21
21
|
|
22
22
|
|
23
23
|
|
24
|
-
def
|
25
|
-
value:
|
24
|
+
def strplwr(
|
25
|
+
value: Any, # noqa: ANN401
|
26
26
|
) -> str:
|
27
27
|
"""
|
28
28
|
Return the provided string but stripped and lower cased.
|
29
29
|
|
30
30
|
Example
|
31
31
|
-------
|
32
|
-
>>>
|
32
|
+
>>> strplwr(' Foo ')
|
33
33
|
'foo'
|
34
34
|
|
35
35
|
:param value: String which will be stripped and lowered.
|
36
36
|
:returns: Provided string but stripped and lower cased.
|
37
37
|
"""
|
38
38
|
|
39
|
-
|
39
|
+
_value = str(value)
|
40
|
+
|
41
|
+
return _value.strip().lower()
|
40
42
|
|
41
43
|
|
42
44
|
|
@@ -108,3 +110,31 @@ def instr(
|
|
108
110
|
"""
|
109
111
|
|
110
112
|
return hasstr(str(haystack), needle)
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
def rplstr(
|
117
|
+
source: str,
|
118
|
+
match: str,
|
119
|
+
value: Any, # noqa: ANN401
|
120
|
+
) -> str:
|
121
|
+
"""
|
122
|
+
Return the source string with the match value replaced.
|
123
|
+
|
124
|
+
Example
|
125
|
+
-------
|
126
|
+
>>> rplstr('foo', 'foo', 'bar')
|
127
|
+
'bar'
|
128
|
+
|
129
|
+
:param source: String that to be processed and returned.
|
130
|
+
:param match: What will be replaced within the string.
|
131
|
+
:param value: Replace value for the string is matched.
|
132
|
+
:returns: Source string with the match value replaced.
|
133
|
+
"""
|
134
|
+
|
135
|
+
match = str(match)
|
136
|
+
value = str(value)
|
137
|
+
|
138
|
+
return (
|
139
|
+
str(source)
|
140
|
+
.replace(match, value))
|
@@ -0,0 +1,74 @@
|
|
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 typing import TYPE_CHECKING
|
11
|
+
|
12
|
+
from ..classes import clsname
|
13
|
+
from ..classes import lattrs
|
14
|
+
from ...config import LoggerParams
|
15
|
+
|
16
|
+
if TYPE_CHECKING:
|
17
|
+
from ...config import Config
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
def test_BaseModel() -> None:
|
22
|
+
"""
|
23
|
+
Perform various tests associated with relevant routines.
|
24
|
+
"""
|
25
|
+
|
26
|
+
params = LoggerParams(
|
27
|
+
stdo_level='info')
|
28
|
+
|
29
|
+
dumped = params.model_dumped
|
30
|
+
pruned = params.model_pruned
|
31
|
+
|
32
|
+
assert dumped == {
|
33
|
+
'file_level': None,
|
34
|
+
'file_path': None,
|
35
|
+
'stdo_level': 'info'}
|
36
|
+
|
37
|
+
assert pruned == {
|
38
|
+
'stdo_level': 'info'}
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
def test_clsname(
|
43
|
+
config: 'Config',
|
44
|
+
) -> None:
|
45
|
+
"""
|
46
|
+
Perform various tests associated with relevant routines.
|
47
|
+
|
48
|
+
:param config: Primary class instance for configuration.
|
49
|
+
"""
|
50
|
+
|
51
|
+
assert clsname(config) == 'Config'
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
def test_lattrs(
|
56
|
+
config: 'Config',
|
57
|
+
) -> None:
|
58
|
+
"""
|
59
|
+
Perform various tests associated with relevant routines.
|
60
|
+
|
61
|
+
:param config: Primary class instance for configuration.
|
62
|
+
"""
|
63
|
+
|
64
|
+
attrs = lattrs(config)
|
65
|
+
|
66
|
+
assert attrs == [
|
67
|
+
'_Config__model',
|
68
|
+
'_Config__files',
|
69
|
+
'_Config__cargs',
|
70
|
+
'_Config__sargs',
|
71
|
+
'_Config__params',
|
72
|
+
'_Config__paths',
|
73
|
+
'_Config__logger',
|
74
|
+
'_Config__crypts']
|
@@ -10,6 +10,7 @@ is permitted, for more information consult the project license file.
|
|
10
10
|
from copy import copy
|
11
11
|
from copy import deepcopy
|
12
12
|
|
13
|
+
from ..classes import lattrs
|
13
14
|
from ..empty import Empty
|
14
15
|
from ..empty import EmptyType
|
15
16
|
|
@@ -23,7 +24,7 @@ def test_EmptyType() -> None:
|
|
23
24
|
empty = EmptyType()
|
24
25
|
|
25
26
|
|
26
|
-
attrs =
|
27
|
+
attrs = lattrs(empty)
|
27
28
|
|
28
29
|
assert attrs == [
|
29
30
|
'_EmptyType__empty']
|
@@ -0,0 +1,23 @@
|
|
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 ..lists import inlist
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
def test_inlist() -> None:
|
15
|
+
"""
|
16
|
+
Perform various tests associated with relevant routines.
|
17
|
+
"""
|
18
|
+
|
19
|
+
needle = 123
|
20
|
+
|
21
|
+
haystack = [123, 456]
|
22
|
+
|
23
|
+
assert inlist(needle, haystack)
|
@@ -10,16 +10,17 @@ is permitted, for more information consult the project license file.
|
|
10
10
|
from ..strings import hasstr
|
11
11
|
from ..strings import inrepr
|
12
12
|
from ..strings import instr
|
13
|
-
from ..strings import
|
13
|
+
from ..strings import rplstr
|
14
|
+
from ..strings import strplwr
|
14
15
|
|
15
16
|
|
16
17
|
|
17
|
-
def
|
18
|
+
def test_strplwr() -> None:
|
18
19
|
"""
|
19
20
|
Perform various tests associated with relevant routines.
|
20
21
|
"""
|
21
22
|
|
22
|
-
assert
|
23
|
+
assert strplwr(' Foo ') == 'foo'
|
23
24
|
|
24
25
|
|
25
26
|
|
@@ -59,3 +60,14 @@ def test_instr() -> None:
|
|
59
60
|
item = MyClass()
|
60
61
|
|
61
62
|
assert instr('MyClass', item)
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
def test_rplstr() -> None:
|
67
|
+
"""
|
68
|
+
Perform various tests associated with relevant routines.
|
69
|
+
"""
|
70
|
+
|
71
|
+
string = rplstr('foo', 'o', 'O')
|
72
|
+
|
73
|
+
assert string == 'fOO'
|
encommon/types/types.py
ADDED
@@ -0,0 +1,20 @@
|
|
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 typing import Any
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
DictStrAny = dict[str, Any]
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
NCTrue = True
|
19
|
+
NCFalse = False
|
20
|
+
NCNone = None
|
encommon/utils/__init__.py
CHANGED
@@ -16,6 +16,8 @@ from .paths import resolve_paths
|
|
16
16
|
from .paths import stats_path
|
17
17
|
from .sample import load_sample
|
18
18
|
from .sample import prep_sample
|
19
|
+
from .sample import read_sample
|
20
|
+
from .sample import rvrt_sample
|
19
21
|
from .stdout import array_ansi
|
20
22
|
from .stdout import kvpair_ansi
|
21
23
|
from .stdout import make_ansi
|
@@ -32,7 +34,9 @@ __all__ = [
|
|
32
34
|
'make_ansi',
|
33
35
|
'prep_sample',
|
34
36
|
'print_ansi',
|
37
|
+
'read_sample',
|
35
38
|
'read_text',
|
39
|
+
'rvrt_sample',
|
36
40
|
'resolve_path',
|
37
41
|
'resolve_paths',
|
38
42
|
'rgxp_match',
|
encommon/utils/paths.py
CHANGED
@@ -13,6 +13,7 @@ from typing import Optional
|
|
13
13
|
from typing import TYPE_CHECKING
|
14
14
|
|
15
15
|
from .match import rgxp_match
|
16
|
+
from ..types import rplstr
|
16
17
|
from ..types import sort_dict
|
17
18
|
|
18
19
|
if TYPE_CHECKING:
|
@@ -50,13 +51,11 @@ def resolve_path(
|
|
50
51
|
|
51
52
|
for old, new in items:
|
52
53
|
|
53
|
-
|
54
|
-
|
54
|
+
old = str(old)
|
55
|
+
new = str(new)
|
55
56
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
path = path.replace(old, new)
|
57
|
+
path = rplstr(
|
58
|
+
path, old, new)
|
60
59
|
|
61
60
|
return Path(path).resolve()
|
62
61
|
|