encommon 0.14.0__py3-none-any.whl → 0.15.0__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. encommon/colors/__init__.py +2 -2
  2. encommon/colors/{colors.py → color.py} +24 -24
  3. encommon/colors/test/{test_colors.py → test_color.py} +16 -16
  4. encommon/config/config.py +15 -15
  5. encommon/config/files.py +14 -14
  6. encommon/config/logger.py +6 -6
  7. encommon/config/params.py +47 -30
  8. encommon/config/paths.py +13 -13
  9. encommon/config/test/__init__.py +1 -1
  10. encommon/config/test/test_config.py +10 -16
  11. encommon/config/test/test_files.py +8 -7
  12. encommon/config/test/test_logger.py +11 -10
  13. encommon/config/test/test_paths.py +11 -10
  14. encommon/config/utils.py +2 -2
  15. encommon/crypts/params.py +28 -12
  16. encommon/crypts/test/test_crypts.py +5 -5
  17. encommon/crypts/test/test_hashes.py +2 -1
  18. encommon/times/__init__.py +2 -2
  19. encommon/times/common.py +2 -2
  20. encommon/times/params.py +76 -48
  21. encommon/times/parse.py +3 -3
  22. encommon/times/test/test_duration.py +3 -2
  23. encommon/times/test/test_time.py +123 -0
  24. encommon/times/test/test_timer.py +5 -4
  25. encommon/times/test/test_timers.py +10 -9
  26. encommon/times/test/test_window.py +4 -3
  27. encommon/times/test/test_windows.py +7 -6
  28. encommon/times/{times.py → time.py} +61 -12
  29. encommon/times/timer.py +10 -10
  30. encommon/times/timers.py +3 -3
  31. encommon/times/unitime.py +9 -0
  32. encommon/times/window.py +31 -31
  33. encommon/times/windows.py +10 -10
  34. encommon/types/classes.py +0 -13
  35. encommon/types/lists.py +6 -0
  36. encommon/types/notate.py +2 -1
  37. encommon/types/strings.py +5 -0
  38. encommon/types/test/test_empty.py +2 -1
  39. encommon/utils/sample.py +6 -5
  40. encommon/utils/stdout.py +2 -2
  41. encommon/utils/test/test_paths.py +3 -3
  42. encommon/utils/test/test_sample.py +2 -2
  43. encommon/utils/test/test_stdout.py +3 -3
  44. encommon/version.txt +1 -1
  45. {encommon-0.14.0.dist-info → encommon-0.15.0.dist-info}/METADATA +1 -1
  46. encommon-0.15.0.dist-info/RECORD +84 -0
  47. {encommon-0.14.0.dist-info → encommon-0.15.0.dist-info}/WHEEL +1 -1
  48. encommon/times/test/test_times.py +0 -122
  49. encommon-0.14.0.dist-info/RECORD +0 -84
  50. {encommon-0.14.0.dist-info → encommon-0.15.0.dist-info}/LICENSE +0 -0
  51. {encommon-0.14.0.dist-info → encommon-0.15.0.dist-info}/top_level.txt +0 -0
encommon/times/params.py CHANGED
@@ -7,13 +7,16 @@ is permitted, for more information consult the project license file.
7
7
 
8
8
 
9
9
 
10
- from typing import Any
10
+ from typing import Annotated
11
11
  from typing import Optional
12
12
 
13
+ from pydantic import Field
14
+
13
15
  from .common import PARSABLE
14
16
  from .common import SCHEDULE
15
- from .times import Times
17
+ from .time import Time
16
18
  from ..types import BaseModel
19
+ from ..types import DictStrAny
17
20
 
18
21
 
19
22
 
@@ -25,33 +28,40 @@ _WINDOWS = dict[str, 'WindowParams']
25
28
  class TimerParams(BaseModel, extra='forbid'):
26
29
  """
27
30
  Process and validate the core configuration parameters.
28
-
29
- :param timer: Seconds that are used for related timer.
30
- :param start: Optional time for when the timer started.
31
31
  """
32
32
 
33
- timer: float
34
- start: Optional[str] = None
33
+ timer: Annotated[
34
+ float,
35
+ Field(...,
36
+ description='Seconds used for the interval')]
37
+
38
+ start: Annotated[
39
+ str,
40
+ Field(...,
41
+ description='Optional value of timer start',
42
+ min_length=1)]
35
43
 
36
44
 
37
45
  def __init__(
38
46
  self,
39
47
  timer: int | float,
40
- start: Optional[PARSABLE] = None,
48
+ start: PARSABLE = 'now',
41
49
  ) -> None:
42
50
  """
43
51
  Initialize instance for class using provided parameters.
44
52
  """
45
53
 
54
+ data: DictStrAny = {}
55
+
56
+
46
57
  if timer is not None:
47
58
  timer = float(timer)
48
59
 
49
60
  if start is not None:
50
- start = Times(start)
61
+ start = Time(start)
51
62
 
52
63
 
53
- data: dict[str, Any] = {
54
- 'timer': timer}
64
+ data['timer'] = timer
55
65
 
56
66
  if start is not None:
57
67
  data['start'] = start.subsec
@@ -64,11 +74,13 @@ class TimerParams(BaseModel, extra='forbid'):
64
74
  class TimersParams(BaseModel, extra='forbid'):
65
75
  """
66
76
  Process and validate the core configuration parameters.
67
-
68
- :param timers: Seconds that are used for related timer.
69
77
  """
70
78
 
71
- timers: _TIMERS
79
+ timers: Annotated[
80
+ _TIMERS,
81
+ Field(...,
82
+ description='Seconds used for the interval',
83
+ min_length=0)]
72
84
 
73
85
 
74
86
  def __init__(
@@ -79,65 +91,81 @@ class TimersParams(BaseModel, extra='forbid'):
79
91
  Initialize instance for class using provided parameters.
80
92
  """
81
93
 
82
- if timers is None:
83
- timers = {}
94
+ timers = timers or {}
84
95
 
85
- super().__init__(
86
- timers=timers)
96
+ super().__init__(**{
97
+ 'timers': timers})
87
98
 
88
99
 
89
100
 
90
101
  class WindowParams(BaseModel, extra='forbid'):
91
102
  """
92
103
  Process and validate the core configuration parameters.
93
-
94
- :param window: Parameters for defining scheduled time.
95
- :param start: Determine the start for scheduling window.
96
- :param stop: Determine the ending for scheduling window.
97
- :param anchor: Optionally define time anchor for window.
98
- :param delay: Period of time schedulng will be delayed.
99
104
  """
100
105
 
101
- window: SCHEDULE
102
-
103
- start: Optional[str] = None
104
- stop: Optional[str] = None
105
- anchor: Optional[str] = None
106
- delay: float = 0.0
106
+ window: Annotated[
107
+ SCHEDULE,
108
+ Field(...,
109
+ description='Period for scheduling window',
110
+ min_length=1)]
111
+
112
+ start: Annotated[
113
+ Optional[str],
114
+ Field(None,
115
+ description='Determine when scope begins',
116
+ min_length=1)]
117
+
118
+ stop: Annotated[
119
+ Optional[str],
120
+ Field(None,
121
+ description='Determine when scope ends',
122
+ min_length=1)]
123
+
124
+ anchor: Annotated[
125
+ Optional[str],
126
+ Field(None,
127
+ description='Optional anchor of the window',
128
+ min_length=1)]
129
+
130
+ delay: Annotated[
131
+ float,
132
+ Field(...,
133
+ description='Time period of schedule delay',
134
+ ge=0)]
107
135
 
108
136
 
109
137
  def __init__(
110
138
  self,
111
139
  window: SCHEDULE | int,
140
+ *,
112
141
  start: Optional[PARSABLE] = None,
113
142
  stop: Optional[PARSABLE] = None,
114
143
  anchor: Optional[PARSABLE] = None,
115
- delay: Optional[int | float] = None,
144
+ delay: int | float = 0.0,
116
145
  ) -> None:
117
146
  """
118
147
  Initialize instance for class using provided parameters.
119
148
  """
120
149
 
150
+ data: DictStrAny = {}
151
+
121
152
 
122
153
  if isinstance(window, int):
123
154
  window = {'seconds': window}
124
155
 
125
-
126
156
  if start is not None:
127
- start = Times(start)
157
+ start = Time(start)
128
158
 
129
159
  if stop is not None:
130
- stop = Times(stop)
160
+ stop = Time(stop)
131
161
 
132
162
  if anchor is not None:
133
- anchor = Times(anchor)
163
+ anchor = Time(anchor)
134
164
 
135
- if delay is not None:
136
- delay = float(delay)
165
+ delay = float(delay)
137
166
 
138
167
 
139
- data: dict[str, Any] = {
140
- 'window': window}
168
+ data['window'] = window
141
169
 
142
170
  if start is not None:
143
171
  data['start'] = start.subsec
@@ -148,8 +176,7 @@ class WindowParams(BaseModel, extra='forbid'):
148
176
  if anchor is not None:
149
177
  data['anchor'] = anchor.subsec
150
178
 
151
- if delay is not None:
152
- data['delay'] = delay
179
+ data['delay'] = delay
153
180
 
154
181
 
155
182
  super().__init__(**data)
@@ -159,11 +186,13 @@ class WindowParams(BaseModel, extra='forbid'):
159
186
  class WindowsParams(BaseModel, extra='forbid'):
160
187
  """
161
188
  Process and validate the core configuration parameters.
162
-
163
- :param windows: Parameters for defining scheduled time.
164
189
  """
165
190
 
166
- windows: _WINDOWS
191
+ windows: Annotated[
192
+ _WINDOWS,
193
+ Field(...,
194
+ description='Period for scheduling windows',
195
+ min_length=0)]
167
196
 
168
197
 
169
198
  def __init__(
@@ -174,8 +203,7 @@ class WindowsParams(BaseModel, extra='forbid'):
174
203
  Initialize instance for class using provided parameters.
175
204
  """
176
205
 
177
- if windows is None:
178
- windows = {}
206
+ windows = windows or {}
179
207
 
180
- super().__init__(
181
- windows=windows)
208
+ super().__init__(**{
209
+ 'windows': windows})
encommon/times/parse.py CHANGED
@@ -26,7 +26,7 @@ from .utils import strptime
26
26
  from .utils import utcdatetime
27
27
 
28
28
  if TYPE_CHECKING:
29
- from .times import Times # noqa: F401
29
+ from .time import Time # noqa: F401
30
30
 
31
31
 
32
32
 
@@ -51,7 +51,7 @@ def parse_time(
51
51
  +----------------------+----------------------------+
52
52
  | 'max', float('inf') | Uses the maximum time |
53
53
  +----------------------+----------------------------+
54
- | object | Provide datetime or Times |
54
+ | object | Provide datetime or Time |
55
55
  +----------------------+----------------------------+
56
56
  | 2000-01-01T00:00:00Z | Uses strptime and dateutil |
57
57
  +----------------------+----------------------------+
@@ -169,7 +169,7 @@ def shift_time(
169
169
 
170
170
  parsed = snap(anchor, notate)
171
171
 
172
- assert parsed.tzinfo is not None
172
+ assert parsed.tzinfo
173
173
 
174
174
  return parse_time(
175
175
  parsed, tzname=tzname)
@@ -9,6 +9,7 @@ is permitted, for more information consult the project license file.
9
9
 
10
10
  from ..duration import Duration
11
11
  from ...types import inrepr
12
+ from ...types import lattrs
12
13
  from ...types.strings import COMMAS
13
14
 
14
15
 
@@ -21,7 +22,7 @@ def test_Duration() -> None:
21
22
  durate = Duration(95401)
22
23
 
23
24
 
24
- attrs = list(durate.__dict__)
25
+ attrs = lattrs(durate)
25
26
 
26
27
  assert attrs == [
27
28
  '_Duration__source',
@@ -58,7 +59,7 @@ def test_Duration() -> None:
58
59
 
59
60
  assert durate.source == 95401
60
61
 
61
- assert durate.smart is True
62
+ assert durate.smart
62
63
 
63
64
  assert durate.groups == 7
64
65
 
@@ -0,0 +1,123 @@
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 ..common import STAMP_SIMPLE
11
+ from ..common import UNIXEPOCH
12
+ from ..common import UNIXHPOCH
13
+ from ..common import UNIXMPOCH
14
+ from ..time import Time
15
+ from ...types import inrepr
16
+ from ...types import instr
17
+ from ...types import lattrs
18
+
19
+
20
+
21
+ def test_Time() -> None:
22
+ """
23
+ Perform various tests associated with relevant routines.
24
+ """
25
+
26
+ time = Time(
27
+ UNIXEPOCH,
28
+ format=STAMP_SIMPLE)
29
+
30
+
31
+ attrs = lattrs(time)
32
+
33
+ assert attrs == [
34
+ '_Time__source']
35
+
36
+
37
+ assert inrepr(
38
+ "Time('1970-01-01T00:00",
39
+ time)
40
+
41
+ assert hash(time) > 0
42
+
43
+ assert instr(
44
+ '1970-01-01T00:00:00.000',
45
+ time)
46
+
47
+
48
+ assert int(time) == 0
49
+ assert float(time) == 0.0
50
+
51
+ assert time + 1 == Time(1)
52
+ assert time - 1 == Time(-1)
53
+
54
+ assert time == Time(0)
55
+ assert time != Time(-1)
56
+ assert time != 'invalid'
57
+
58
+ assert time > Time(-1)
59
+ assert time >= Time(0)
60
+ assert time < Time(1)
61
+ assert time <= Time(0)
62
+
63
+
64
+ assert time.source.year == 1970
65
+
66
+ assert time.epoch == 0.0
67
+
68
+ assert time.spoch == 0
69
+
70
+ assert time.mpoch == 0.0
71
+
72
+ assert str(time.time) == '00:00:00'
73
+
74
+ assert time.simple == UNIXEPOCH
75
+
76
+ assert time.subsec == UNIXMPOCH
77
+
78
+ assert time.human == UNIXHPOCH
79
+
80
+ assert time.elapsed >= 1672531200
81
+
82
+ assert time.since >= 1672531200
83
+
84
+ assert time.before == (
85
+ '1969-12-31T23:59:59.999999Z')
86
+
87
+ assert time.after == (
88
+ '1970-01-01T00:00:00.000001Z')
89
+
90
+ assert time.stamp() == UNIXMPOCH
91
+
92
+ time = time.shift('+1y')
93
+ assert time == '1971-01-01'
94
+
95
+ time = time.shifz('UTC-1')
96
+ assert time == (
97
+ '12/31/1970 23:00 -0100')
98
+
99
+
100
+
101
+ def test_Time_tzname() -> None:
102
+ """
103
+ Perform various tests associated with relevant routines.
104
+ """
105
+
106
+ time1 = Time(
107
+ '1970-01-01T00:00:00Z')
108
+
109
+ time2 = time1.shifz(
110
+ 'US/Central')
111
+
112
+
113
+ delta = time1 - time2
114
+
115
+ assert -1 < delta < 1
116
+
117
+
118
+ stamp1 = time1.stamp(
119
+ tzname='US/Central')
120
+
121
+ stamp2 = time2.stamp()
122
+
123
+ assert stamp1 == stamp2
@@ -11,10 +11,11 @@ from time import sleep
11
11
 
12
12
  from pytest import fixture
13
13
 
14
+ from ..time import Time
14
15
  from ..timer import Timer
15
- from ..times import Times
16
16
  from ...types import inrepr
17
17
  from ...types import instr
18
+ from ...types import lattrs
18
19
 
19
20
 
20
21
 
@@ -40,11 +41,11 @@ def test_Timer(
40
41
  """
41
42
 
42
43
 
43
- attrs = list(timer.__dict__)
44
+ attrs = lattrs(timer)
44
45
 
45
46
  assert attrs == [
46
47
  '_Timer__timer',
47
- '_Timer__times']
48
+ '_Timer__time']
48
49
 
49
50
 
50
51
  assert inrepr(
@@ -60,7 +61,7 @@ def test_Timer(
60
61
 
61
62
  assert timer.timer == 1
62
63
 
63
- assert timer.times >= Times('-1s')
64
+ assert timer.time >= Time('-1s')
64
65
 
65
66
  assert timer.since <= 1
66
67
 
@@ -9,18 +9,19 @@ is permitted, for more information consult the project license file.
9
9
 
10
10
  from pathlib import Path
11
11
  from time import sleep
12
- from typing import Any
13
12
 
14
13
  from pytest import fixture
15
14
  from pytest import raises
16
15
 
17
16
  from ..params import TimerParams
18
17
  from ..params import TimersParams
18
+ from ..time import Time
19
19
  from ..timers import Timers
20
20
  from ..timers import TimersTable
21
- from ..times import Times
21
+ from ...types import DictStrAny
22
22
  from ...types import inrepr
23
23
  from ...types import instr
24
+ from ...types import lattrs
24
25
 
25
26
 
26
27
 
@@ -36,7 +37,7 @@ def timers(
36
37
  """
37
38
 
38
39
 
39
- source: dict[str, Any] = {
40
+ source: DictStrAny = {
40
41
  'one': {'timer': 1},
41
42
  'two': {'timer': 1}}
42
43
 
@@ -93,7 +94,7 @@ def test_Timers(
93
94
  """
94
95
 
95
96
 
96
- attrs = list(timers.__dict__)
97
+ attrs = lattrs(timers)
97
98
 
98
99
  assert attrs == [
99
100
  '_Timers__params',
@@ -115,27 +116,27 @@ def test_Timers(
115
116
  timers)
116
117
 
117
118
 
118
- assert timers.params is not None
119
+ assert timers.params
119
120
 
120
121
  assert timers.store[:6] == 'sqlite'
121
122
 
122
123
  assert timers.group == 'default'
123
124
 
124
- assert timers.store_engine is not None
125
+ assert timers.store_engine
125
126
 
126
- assert timers.store_session is not None
127
+ assert timers.store_session
127
128
 
128
129
  assert len(timers.children) == 2
129
130
 
130
131
 
131
132
  timer = timers.children['one']
132
133
 
133
- assert timer.times >= Times('-1s')
134
+ assert timer.time >= Time('-1s')
134
135
 
135
136
 
136
137
  timer = timers.children['two']
137
138
 
138
- assert timer.times == '1970-01-01'
139
+ assert timer.time == '1970-01-01'
139
140
 
140
141
 
141
142
 
@@ -13,12 +13,13 @@ from typing import TYPE_CHECKING
13
13
  from pytest import fixture
14
14
  from pytest import mark
15
15
 
16
- from ..times import Times
16
+ from ..time import Time
17
17
  from ..window import Window
18
18
  from ..window import window_croniter
19
19
  from ..window import window_interval
20
20
  from ...types import inrepr
21
21
  from ...types import instr
22
+ from ...types import lattrs
22
23
 
23
24
  if TYPE_CHECKING:
24
25
  from ..common import PARSABLE
@@ -51,7 +52,7 @@ def test_Window(
51
52
  """
52
53
 
53
54
 
54
- attrs = list(window.__dict__)
55
+ attrs = lattrs(window)
55
56
 
56
57
  assert attrs == [
57
58
  '_Window__window',
@@ -169,7 +170,7 @@ def test_Window_cover(
169
170
  assert window.walked
170
171
 
171
172
 
172
- anchor = Times('-0s@s')
173
+ anchor = Time('-0s@s')
173
174
 
174
175
 
175
176
  window = Window(
@@ -9,7 +9,6 @@ is permitted, for more information consult the project license file.
9
9
 
10
10
  from pathlib import Path
11
11
  from time import sleep
12
- from typing import Any
13
12
 
14
13
  from pytest import fixture
15
14
  from pytest import raises
@@ -18,8 +17,10 @@ from ..params import WindowParams
18
17
  from ..params import WindowsParams
19
18
  from ..windows import Windows
20
19
  from ..windows import WindowsTable
20
+ from ...types import DictStrAny
21
21
  from ...types import inrepr
22
22
  from ...types import instr
23
+ from ...types import lattrs
23
24
 
24
25
 
25
26
 
@@ -35,7 +36,7 @@ def windows(
35
36
  """
36
37
 
37
38
 
38
- source: dict[str, Any] = {
39
+ source: DictStrAny = {
39
40
  'one': WindowParams(
40
41
  window='* * * * *',
41
42
  start=310,
@@ -104,7 +105,7 @@ def test_Windows(
104
105
  """
105
106
 
106
107
 
107
- attrs = list(windows.__dict__)
108
+ attrs = lattrs(windows)
108
109
 
109
110
  assert attrs == [
110
111
  '_Windows__params',
@@ -128,15 +129,15 @@ def test_Windows(
128
129
  windows)
129
130
 
130
131
 
131
- assert windows.params is not None
132
+ assert windows.params
132
133
 
133
134
  assert windows.store[:6] == 'sqlite'
134
135
 
135
136
  assert windows.group == 'default'
136
137
 
137
- assert windows.store_engine is not None
138
+ assert windows.store_engine
138
139
 
139
- assert windows.store_session is not None
140
+ assert windows.store_session
140
141
 
141
142
  assert windows.start == (
142
143
  '1970-01-01T00:05:10Z')