encommon 0.22.4__py3-none-any.whl → 0.22.6__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/colors/color.py CHANGED
@@ -7,6 +7,7 @@ is permitted, for more information consult the project license file.
7
7
 
8
8
 
9
9
 
10
+ from colorsys import hls_to_rgb
10
11
  from contextlib import suppress
11
12
  from typing import Union
12
13
 
@@ -61,6 +62,51 @@ class Color:
61
62
  self.__source = source
62
63
 
63
64
 
65
+ @classmethod
66
+ def from_hsl(
67
+ cls,
68
+ hue: int,
69
+ sat: int,
70
+ lev: int,
71
+ ) -> 'Color':
72
+ """
73
+ Initialize instance for class using provided parameters.
74
+ """
75
+
76
+ h, s, l = ( # noqa: E741
77
+ hue / 360,
78
+ sat / 100,
79
+ lev / 100)
80
+
81
+ r, g, b = hls_to_rgb(h, l, s)
82
+
83
+ color = (
84
+ f'{round(r * 255):02X}'
85
+ f'{round(g * 255):02X}'
86
+ f'{round(b * 255):02X}')
87
+
88
+ return cls(color)
89
+
90
+
91
+ @classmethod
92
+ def from_rgb(
93
+ cls,
94
+ red: int,
95
+ green: int,
96
+ blue: int,
97
+ ) -> 'Color':
98
+ """
99
+ Initialize instance for class using provided parameters.
100
+ """
101
+
102
+ value = (
103
+ f'{red:02X}'
104
+ f'{green:02X}'
105
+ f'{blue:02X}')
106
+
107
+ return cls(value)
108
+
109
+
64
110
  def __repr__(
65
111
  self,
66
112
  ) -> str:
@@ -84,6 +84,7 @@ def test_Color_rgb(
84
84
  """
85
85
 
86
86
  assert Color(source).rgb == expect
87
+ assert Color.from_rgb(*expect) == source
87
88
 
88
89
 
89
90
 
@@ -155,7 +156,7 @@ def test_Color_xy(
155
156
  ('ffff00', (60, 100, 50)),
156
157
  ('00ffff', (180, 100, 50)),
157
158
  ('ff00ff', (300, 100, 50)),
158
- ('800080', (300, 100, 25))])
159
+ ('80007F', (300, 100, 25))])
159
160
  def test_Color_hsl(
160
161
  source: str,
161
162
  expect: tuple[int, ...],
@@ -168,6 +169,7 @@ def test_Color_hsl(
168
169
  """
169
170
 
170
171
  assert Color(source).hsl == expect
172
+ assert Color.from_hsl(*expect) == source
171
173
 
172
174
 
173
175
 
@@ -100,8 +100,8 @@ def test_Timers(
100
100
  '_Timers__params',
101
101
  '_Timers__store',
102
102
  '_Timers__group',
103
- '_Timers__store_engine',
104
- '_Timers__store_session',
103
+ '_Timers__sengine',
104
+ '_Timers__session',
105
105
  '_Timers__timers']
106
106
 
107
107
 
@@ -111,8 +111,8 @@ def test_Windows(
111
111
  '_Windows__params',
112
112
  '_Windows__store',
113
113
  '_Windows__group',
114
- '_Windows__store_engine',
115
- '_Windows__store_session',
114
+ '_Windows__sengine',
115
+ '_Windows__session',
116
116
  '_Windows__start',
117
117
  '_Windows__stop',
118
118
  '_Windows__windows']
encommon/times/timers.py CHANGED
@@ -107,8 +107,8 @@ class Timers:
107
107
  __store: str
108
108
  __group: str
109
109
 
110
- __store_engine: Engine
111
- __store_session: (
110
+ __sengine: Engine
111
+ __session: (
112
112
  # pylint: disable=unsubscriptable-object
113
113
  sessionmaker[Session])
114
114
 
@@ -152,17 +152,18 @@ class Timers:
152
152
  Construct instances using the configuration parameters.
153
153
  """
154
154
 
155
- store = self.__store
156
-
157
- engine = create_engine(store)
155
+ sengine = create_engine(
156
+ self.__store,
157
+ pool_pre_ping=True)
158
158
 
159
159
  (SQLBase.metadata
160
- .create_all(engine))
160
+ .create_all(sengine))
161
161
 
162
- session = sessionmaker(engine)
162
+ session = (
163
+ sessionmaker(sengine))
163
164
 
164
- self.__store_engine = engine
165
- self.__store_session = session
165
+ self.__sengine = sengine
166
+ self.__session = session
166
167
 
167
168
 
168
169
  @property
@@ -214,7 +215,7 @@ class Timers:
214
215
  :returns: Value for the attribute from class instance.
215
216
  """
216
217
 
217
- return self.__store_engine
218
+ return self.__sengine
218
219
 
219
220
 
220
221
  @property
@@ -227,7 +228,7 @@ class Timers:
227
228
  :returns: Value for the attribute from class instance.
228
229
  """
229
230
 
230
- return self.__store_session()
231
+ return self.__session()
231
232
 
232
233
 
233
234
  @property
encommon/times/windows.py CHANGED
@@ -109,8 +109,8 @@ class Windows:
109
109
  __store: str
110
110
  __group: str
111
111
 
112
- __store_engine: Engine
113
- __store_session: (
112
+ __sengine: Engine
113
+ __session: (
114
114
  # pylint: disable=unsubscriptable-object
115
115
  sessionmaker[Session])
116
116
 
@@ -168,17 +168,18 @@ class Windows:
168
168
  Construct instances using the configuration parameters.
169
169
  """
170
170
 
171
- store = self.__store
172
-
173
- engine = create_engine(store)
171
+ sengine = create_engine(
172
+ self.__store,
173
+ pool_pre_ping=True)
174
174
 
175
175
  (SQLBase.metadata
176
- .create_all(engine))
176
+ .create_all(sengine))
177
177
 
178
- session = sessionmaker(engine)
178
+ session = (
179
+ sessionmaker(sengine))
179
180
 
180
- self.__store_engine = engine
181
- self.__store_session = session
181
+ self.__sengine = sengine
182
+ self.__session = session
182
183
 
183
184
 
184
185
  @property
@@ -230,7 +231,7 @@ class Windows:
230
231
  :returns: Value for the attribute from class instance.
231
232
  """
232
233
 
233
- return self.__store_engine
234
+ return self.__sengine
234
235
 
235
236
 
236
237
  @property
@@ -243,7 +244,7 @@ class Windows:
243
244
  :returns: Value for the attribute from class instance.
244
245
  """
245
246
 
246
- return self.__store_session()
247
+ return self.__session()
247
248
 
248
249
 
249
250
  @property
@@ -7,6 +7,7 @@ is permitted, for more information consult the project license file.
7
7
 
8
8
 
9
9
 
10
+ from .files import append_text
10
11
  from .files import read_text
11
12
  from .files import save_text
12
13
  from .match import fuzz_match
@@ -27,6 +28,7 @@ from .stdout import strip_ansi
27
28
 
28
29
 
29
30
  __all__ = [
31
+ 'append_text',
30
32
  'array_ansi',
31
33
  'fuzz_match',
32
34
  'kvpair_ansi',
encommon/utils/files.py CHANGED
@@ -23,6 +23,8 @@ def read_text(
23
23
 
24
24
  Example
25
25
  -------
26
+ >>> path.exists()
27
+ False
26
28
  >>> save_text(path, 'foo')
27
29
  'foo'
28
30
  >>> read_text(path)
@@ -52,6 +54,8 @@ def save_text(
52
54
 
53
55
  Example
54
56
  -------
57
+ >>> path.exists()
58
+ False
55
59
  >>> save_text(path, 'foo')
56
60
  'foo'
57
61
  >>> read_text(path)
@@ -69,3 +73,38 @@ def save_text(
69
73
  encoding='utf-8')
70
74
 
71
75
  return read_text(path)
76
+
77
+
78
+
79
+ def append_text(
80
+ path: str | Path,
81
+ content: str,
82
+ ) -> None:
83
+ """
84
+ Append the provided text content into provided file path.
85
+
86
+ .. testsetup::
87
+ >>> tmpdir = getfixture('tmpdir')
88
+ >>> path = Path(f'{tmpdir}/text.txt')
89
+
90
+ Example
91
+ -------
92
+ >>> path.exists()
93
+ False
94
+ >>> append_text(path, 'foo')
95
+ >>> append_text(path, 'foo')
96
+ >>> read_text(path)
97
+ 'foofoo'
98
+
99
+ :param path: Complete or relative path to the text file.
100
+ :param content: Content that will be written to the file.
101
+ """
102
+
103
+ path = Path(path).resolve()
104
+
105
+ with path.open(
106
+ mode='a',
107
+ encoding='utf-8',
108
+ ) as file:
109
+
110
+ file.write(f'{content}')
@@ -9,6 +9,7 @@ is permitted, for more information consult the project license file.
9
9
 
10
10
  from pathlib import Path
11
11
 
12
+ from ..files import append_text
12
13
  from ..files import read_text
13
14
  from ..files import save_text
14
15
 
@@ -33,3 +34,30 @@ def test_readsave_text(
33
34
  f'{tmp_path}/test.txt')
34
35
 
35
36
  assert loaded == content
37
+
38
+
39
+
40
+ def test_append_text(
41
+ tmp_path: Path,
42
+ ) -> None:
43
+ """
44
+ Perform various tests associated with relevant routines.
45
+
46
+ :param tmp_path: pytest object for temporal filesystem.
47
+ """
48
+
49
+ content = 'pytest'
50
+
51
+ append_text(
52
+ f'{tmp_path}/test.txt',
53
+ content)
54
+
55
+ append_text(
56
+ f'{tmp_path}/test.txt',
57
+ content)
58
+
59
+ loaded = read_text(
60
+ f'{tmp_path}/test.txt')
61
+
62
+ assert loaded == (
63
+ f'{content}{content}')
encommon/version.txt CHANGED
@@ -1 +1 @@
1
- 0.22.4
1
+ 0.22.6
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: encommon
3
- Version: 0.22.4
3
+ Version: 0.22.6
4
4
  Summary: Enasis Network Common Library
5
5
  License: MIT
6
6
  Project-URL: Source, https://github.com/enasisnetwork/encommon
@@ -20,6 +20,7 @@ Requires-Dist: python-dateutil
20
20
  Requires-Dist: pyyaml
21
21
  Requires-Dist: snaptime
22
22
  Requires-Dist: sqlalchemy
23
+ Dynamic: license-file
23
24
 
24
25
  # Enasis Network Common Library
25
26
 
@@ -1,11 +1,11 @@
1
1
  encommon/__init__.py,sha256=YDGzuhpk5Gd1hq54LI0hw1NrrDvrJDrvH20TEy_0l5E,443
2
2
  encommon/conftest.py,sha256=I7Zl2cMytnA-mwSPh0rRjsU0YSlES94jQq6mocRhVUE,1884
3
3
  encommon/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
- encommon/version.txt,sha256=-eRxdwnwDKJRp0_JuBOL0dSCuOs0VzMGRMBCywRYzlQ,7
4
+ encommon/version.txt,sha256=9re3L5NjSNkeHKRqeABthCK7OCnb0x1tZy-Fuc591KY,7
5
5
  encommon/colors/__init__.py,sha256=XRiGimMj8oo040NO5a5ZsbsIUxaGVW4tf4xWTPWgnZY,269
6
- encommon/colors/color.py,sha256=YmmJzwTGdTafe_cWENvvoyW4YCyeycVIqCDJYLr4k-w,10918
6
+ encommon/colors/color.py,sha256=vdOqOsJYJcrGq0b4udegrn4E8gcuVGx6iTRg3_s8Z-Q,11798
7
7
  encommon/colors/test/__init__.py,sha256=PjrnBYT0efyvbaGeNx94dm3tP3EVHUHSVs-VGeLEv5g,218
8
- encommon/colors/test/test_color.py,sha256=ljAcVJ_DMeDcL_8cG05-uvxu_jErylUf3RDaswpn9-g,4596
8
+ encommon/colors/test/test_color.py,sha256=o0CRVdKhfya304IWrk0Vr1ZsmPqUyD7WxqHzG-E3KHM,4686
9
9
  encommon/config/__init__.py,sha256=iZdbW7A4m7iN4xt5cEeQqo0Klqs-CaPLdD5ocLmUYi8,856
10
10
  encommon/config/config.py,sha256=dgJD9Ftj7i309ZBecbILcNGW2WALKdIjDnwa9WoggyM,7000
11
11
  encommon/config/files.py,sha256=dSuShvIbQXFiNmpkwNVHCKDI-phBWC03OJVUfKJnfX0,2433
@@ -39,22 +39,22 @@ encommon/times/params.py,sha256=qg0mLkXVsl54m72kd9uXRvmYKqUR_Ag5PBfnTsrwQhE,4360
39
39
  encommon/times/parse.py,sha256=_PF12z-UOa75SyeUpBXVn7Jjt-c-Pfnzt6pAs_PjXmQ,6496
40
40
  encommon/times/time.py,sha256=Px_9Ifae7GKSY557FAbG1g9cwy3a6VZL09puAbinztQ,11745
41
41
  encommon/times/timer.py,sha256=xxS6KVXFuRLq-RkXWMR7MMX5x0HGrEhLlOhRCecuCZY,3225
42
- encommon/times/timers.py,sha256=JwvBIfWbXjwoIDQ08k2MAOoMif0Q1jsIJjmFWMxSRGA,9807
42
+ encommon/times/timers.py,sha256=4kRUd_posGCLSi6hW8aBDypNgnUjnfkbuKpAr4mjOLg,9815
43
43
  encommon/times/unitime.py,sha256=MwYUJBdX_Rj7pW8QoMtZMUyHa4lsdZKryTdBCpVjnpY,1316
44
44
  encommon/times/utils.py,sha256=PJ5QsKb3_pYEnD3Sz81d8QDhYQtTIj4HJfMoC9gNwmo,3100
45
45
  encommon/times/window.py,sha256=tnOPz57cwIXVnOEGh7WPvBPhdjenvw1bYxV4mz721n0,8490
46
- encommon/times/windows.py,sha256=oxEsCsM8qPQ5AbB8IRK_ONEWzLgXPpft8yR6xUKrb_4,10853
46
+ encommon/times/windows.py,sha256=DaouFEVwiBz5JfOHqJX5b13dsCF4RU5FO1bd3E23HIU,10861
47
47
  encommon/times/test/__init__.py,sha256=PjrnBYT0efyvbaGeNx94dm3tP3EVHUHSVs-VGeLEv5g,218
48
48
  encommon/times/test/test_duration.py,sha256=3Tw6Y_ah36GCJl4vZ76z4Jt7rIxcm9P18-A69qsbLjI,4224
49
49
  encommon/times/test/test_params.py,sha256=kHvs-WvKfPQCdCDnPU9tAyMVXmzH3eUjwQN-QdWBeh4,1407
50
50
  encommon/times/test/test_parse.py,sha256=3Dihhu8xKmgbcq_dqKcO-itAeGtqAJxjGFQ6dPsJ4XM,4210
51
51
  encommon/times/test/test_time.py,sha256=XTgtsil2dgkeBUlJyORsNKUapcZWDFvOU-JwtypA6zw,2257
52
52
  encommon/times/test/test_timer.py,sha256=cBZvO-k-FG7k4LICLLGVFxNBJuTjH4-eL4FNaa14uyY,1563
53
- encommon/times/test/test_timers.py,sha256=zW6czbR5Ujz2cM4K935HCpO6Rx9EHxCgpFqktGYw8Xs,3892
53
+ encommon/times/test/test_timers.py,sha256=HePWaNNH4MTDZoa2H-S_XkmN32lZLXW3g5xv-zTCyl0,3881
54
54
  encommon/times/test/test_unitime.py,sha256=5i4UjBCw8R9h-Lw963GfB_dHBMEQhjvv1k-t27Wyyls,510
55
55
  encommon/times/test/test_utils.py,sha256=WkzHJY6zOt02Ujg5FItOo1nPtktz5ss8ODmG1tRQaaw,2056
56
56
  encommon/times/test/test_window.py,sha256=6ySO5DaYzg1bsVNCqB6u71rKWc0vpolxQ09ruoswN2c,6138
57
- encommon/times/test/test_windows.py,sha256=Sq31BCvJtEN9OGGYXFKiagVZP0kc1n6HuaEBNwbkuks,4496
57
+ encommon/times/test/test_windows.py,sha256=drcPbtGxr7Y8hKiU7XM3rkHYG5tkrq6oG-KRwj6Er2c,4485
58
58
  encommon/types/__init__.py,sha256=rly7loMD1R7YU83u90KqPYiifjZAX_UAXpVGcB_Xerk,1269
59
59
  encommon/types/classes.py,sha256=FYFTu8Uj-74JWudHOlhaOrsXXPxitorBfM9_QM3EGSU,1689
60
60
  encommon/types/dicts.py,sha256=IuLoVdtilhM83ujT74mcz0Zi1HI87P4k7wjnnyMxPag,2821
@@ -72,15 +72,15 @@ encommon/types/test/test_funcs.py,sha256=dYVJgihEj1j3F-OxH0mYSIMoDwZbjvgMnvJKea8
72
72
  encommon/types/test/test_lists.py,sha256=uRdON1vnDT21TBl2prlO15SHIkN7YOApZzHS78R-Bvs,1139
73
73
  encommon/types/test/test_notate.py,sha256=KTOqlHUuS7ed80_h0n7TJNkAqoeULrkbiMH6sPw0lak,9520
74
74
  encommon/types/test/test_strings.py,sha256=oXusioFMdknHeBdwlP_GakDVS9Tf2YBndjonj22UfmM,1277
75
- encommon/utils/__init__.py,sha256=bBgh81wX_TwLgWkx0aBAyVLHNphrfcyQc1AF7-ziyNI,1027
75
+ encommon/utils/__init__.py,sha256=Wb-YFSoGlcAW36LsaQTc_IYiqDbb2d8m_ggej42LNeI,1077
76
76
  encommon/utils/common.py,sha256=-bjGJ2UJa-WTOsVYiuZcVj1gkyH5OlRdRkJtxPw8J6k,555
77
- encommon/utils/files.py,sha256=2uj10JfvKZHdLHNF992_LUvQ4rfMRCZGqJd7LrxKDnE,1458
77
+ encommon/utils/files.py,sha256=mP8p9mcYcK3dGqWcLvYxnYamqa0udmtTbXWVPo6i9W4,2208
78
78
  encommon/utils/match.py,sha256=XvmmMKQ1q8_21zzPGuVvaZf6XwHXPZn4IWIYBEqVCQM,2471
79
79
  encommon/utils/paths.py,sha256=u8-vTONG3QdnpkKfVpl19WssH95bCHg1gHlnRwzyAFM,3509
80
80
  encommon/utils/sample.py,sha256=wcT_me9L-U6atd8kEew4q_4B-iIn8vV1LhEDoVr-cFw,4834
81
81
  encommon/utils/stdout.py,sha256=nzXvdnvgjfdtLlAdIsOZurjGMfUX239gZZxPPQK9BIw,8595
82
82
  encommon/utils/test/__init__.py,sha256=PjrnBYT0efyvbaGeNx94dm3tP3EVHUHSVs-VGeLEv5g,218
83
- encommon/utils/test/test_files.py,sha256=-hdl4UOo-vH1H5gTL1r9Ib3P26DtWaD2YV32P08ykvc,679
83
+ encommon/utils/test/test_files.py,sha256=Nc7EteuZpnaFaF8OaqzEhuui9_SYHG1SK1OcoX9jEa8,1175
84
84
  encommon/utils/test/test_match.py,sha256=QagKpTFdRo23-Y55fSaJrSMpt5jIebScKbz0h8tivrI,1124
85
85
  encommon/utils/test/test_paths.py,sha256=4AzIhQyYFEWhRWHgOZCCzomQ3Zs3EVwRnDQDa6Nq1Mc,1942
86
86
  encommon/utils/test/test_sample.py,sha256=Qf-W0XbjTe5PfG87sdVizL2ymUPRTdX0qQtLGHaTgx8,3539
@@ -131,8 +131,8 @@ encommon/webkit/test/test_moderate.py,sha256=KitKGBtwHOQm0pXXZA5nl9MwAi2pbHOsKhM
131
131
  encommon/webkit/test/test_numeric.py,sha256=9Jqiyo-Bh572QJSyd3gqRwYTifnqqzE7_cNCmLn0CG0,3531
132
132
  encommon/webkit/test/test_statate.py,sha256=4VvmyJhsK3TSK-hq3TzkzwPkXY-GPTU_7uJf-zG_y_s,1760
133
133
  encommon/webkit/test/test_tagues.py,sha256=LQWk6rSBoBxAu-YmUOU8uWNki5RBzk5lp0dbFpySg68,1431
134
- encommon-0.22.4.dist-info/LICENSE,sha256=otnXKCtMjPlbHs0wgZ_BWULrp3g_2dWQJ6icRk9nkgg,1071
135
- encommon-0.22.4.dist-info/METADATA,sha256=Lza7EHPRbAHTVhizIOg3YUEHJAyAbVAx3MtNkHJaNwU,4282
136
- encommon-0.22.4.dist-info/WHEEL,sha256=jB7zZ3N9hIM9adW7qlTAyycLYW9npaWKLRzaoVcLKcM,91
137
- encommon-0.22.4.dist-info/top_level.txt,sha256=bP8q7-5tLDNm-3XPlqn_bDENfYNug5801H_xfz3BEAM,9
138
- encommon-0.22.4.dist-info/RECORD,,
134
+ encommon-0.22.6.dist-info/licenses/LICENSE,sha256=otnXKCtMjPlbHs0wgZ_BWULrp3g_2dWQJ6icRk9nkgg,1071
135
+ encommon-0.22.6.dist-info/METADATA,sha256=UY0Gl0EMFAOEIPZCq6_sWMH5xtVlmtkOyZm3o_Fsv5k,4304
136
+ encommon-0.22.6.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
137
+ encommon-0.22.6.dist-info/top_level.txt,sha256=bP8q7-5tLDNm-3XPlqn_bDENfYNug5801H_xfz3BEAM,9
138
+ encommon-0.22.6.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.8.2)
2
+ Generator: setuptools (78.1.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5