encommon 0.14.0__py3-none-any.whl → 0.16.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.
Files changed (53) 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 +27 -27
  5. encommon/config/files.py +14 -14
  6. encommon/config/logger.py +7 -7
  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 +45 -18
  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/crypts.py +2 -2
  16. encommon/crypts/params.py +28 -12
  17. encommon/crypts/test/test_crypts.py +5 -5
  18. encommon/crypts/test/test_hashes.py +2 -1
  19. encommon/times/__init__.py +2 -2
  20. encommon/times/common.py +2 -2
  21. encommon/times/params.py +76 -48
  22. encommon/times/parse.py +3 -3
  23. encommon/times/test/test_duration.py +3 -2
  24. encommon/times/test/test_time.py +123 -0
  25. encommon/times/test/test_timer.py +5 -4
  26. encommon/times/test/test_timers.py +10 -9
  27. encommon/times/test/test_window.py +4 -3
  28. encommon/times/test/test_windows.py +7 -6
  29. encommon/times/{times.py → time.py} +62 -15
  30. encommon/times/timer.py +10 -10
  31. encommon/times/timers.py +5 -5
  32. encommon/times/unitime.py +9 -0
  33. encommon/times/window.py +31 -31
  34. encommon/times/windows.py +12 -12
  35. encommon/types/classes.py +2 -15
  36. encommon/types/lists.py +6 -0
  37. encommon/types/notate.py +2 -1
  38. encommon/types/strings.py +5 -0
  39. encommon/types/test/test_classes.py +2 -2
  40. encommon/types/test/test_empty.py +2 -1
  41. encommon/utils/sample.py +8 -7
  42. encommon/utils/stdout.py +4 -5
  43. encommon/utils/test/test_paths.py +3 -3
  44. encommon/utils/test/test_sample.py +2 -2
  45. encommon/utils/test/test_stdout.py +3 -3
  46. encommon/version.txt +1 -1
  47. {encommon-0.14.0.dist-info → encommon-0.16.0.dist-info}/METADATA +1 -1
  48. encommon-0.16.0.dist-info/RECORD +84 -0
  49. {encommon-0.14.0.dist-info → encommon-0.16.0.dist-info}/WHEEL +1 -1
  50. encommon/times/test/test_times.py +0 -122
  51. encommon-0.14.0.dist-info/RECORD +0 -84
  52. {encommon-0.14.0.dist-info → encommon-0.16.0.dist-info}/LICENSE +0 -0
  53. {encommon-0.14.0.dist-info → encommon-0.16.0.dist-info}/top_level.txt +0 -0
@@ -24,14 +24,63 @@ from .utils import strftime
24
24
 
25
25
 
26
26
 
27
- class Times:
27
+ class Time:
28
28
  """
29
29
  Interact with various time functions through one wrapper.
30
30
 
31
+ .. testsetup::
32
+ >>> time = Time('1/1/2000 12:00am')
33
+
34
+ Example
35
+ -------
36
+ >>> time = Time('1/1/2000 12:00am')
37
+ >>> time.stamp()
38
+ '2000-01-01T00:00:00.000000+0000'
39
+ >>> time.stamp('%m/%d/%Y')
40
+ '01/01/2000'
41
+
42
+ Example
43
+ -------
44
+ >>> time.epoch
45
+ 946684800.0
46
+ >>> time.time
47
+ datetime.time(0, 0)
48
+ >>> time.simple
49
+ '2000-01-01T00:00:00+0000'
50
+ >>> time.human
51
+ '01/01/2000 12:00AM UTC'
52
+
53
+ Example
54
+ -------
55
+ >>> time.before
56
+ Time('1999-12-31T23:59:59.999999+0000')
57
+ >>> time.after
58
+ Time('2000-01-01T00:00:00.000001+0000')
59
+
31
60
  Example
32
61
  -------
33
- >>> Times('1/1/2000 12:00am')
34
- Times('2000-01-01T00:00:00.000000+0000')
62
+ >>> time.shift('-1d')
63
+ Time('1999-12-31T00:00:00.000000+0000')
64
+
65
+ Example
66
+ -------
67
+ >>> time.shifz('US/Central')
68
+ Time('1999-12-31T18:00:00.000000-0600')
69
+
70
+ Example
71
+ -------
72
+ >>> time = Time('-1s')
73
+ >>> int(time.since)
74
+ 1
75
+
76
+ Example
77
+ -------
78
+ >>> time1 = Time('1/1/2000 12:00am')
79
+ >>> time2 = Time('1/1/2000 12:00am')
80
+ >>> time1 - time2
81
+ 0.0
82
+ >>> time1 + time2
83
+ 1893369600.0
35
84
 
36
85
  :param source: Time in various forms that will be parsed.
37
86
  :param anchor: Optional relative time; for snap notation.
@@ -73,7 +122,7 @@ class Times:
73
122
  :returns: String representation for values from instance.
74
123
  """
75
124
 
76
- return f"Times('{self.subsec}')"
125
+ return f"Time('{self.subsec}')"
77
126
 
78
127
 
79
128
  def __hash__(
@@ -85,9 +134,7 @@ class Times:
85
134
  :returns: Boolean indicating outcome from the operation.
86
135
  """
87
136
 
88
- hashed = int(self.mpoch)
89
-
90
- return int(1e9 + hashed)
137
+ return hash(self.__source)
91
138
 
92
139
 
93
140
  def __str__(
@@ -398,7 +445,7 @@ class Times:
398
445
  @property
399
446
  def before(
400
447
  self,
401
- ) -> 'Times':
448
+ ) -> 'Time':
402
449
  """
403
450
  Return new object containing time just before the time.
404
451
 
@@ -410,13 +457,13 @@ class Times:
410
457
  source -= timedelta(
411
458
  microseconds=1)
412
459
 
413
- return Times(source)
460
+ return Time(source)
414
461
 
415
462
 
416
463
  @property
417
464
  def after(
418
465
  self,
419
- ) -> 'Times':
466
+ ) -> 'Time':
420
467
  """
421
468
  Return new object containing time just after the time.
422
469
 
@@ -428,7 +475,7 @@ class Times:
428
475
  source += timedelta(
429
476
  microseconds=1)
430
477
 
431
- return Times(source)
478
+ return Time(source)
432
479
 
433
480
 
434
481
  def stamp(
@@ -462,7 +509,7 @@ class Times:
462
509
  def shift(
463
510
  self,
464
511
  notate: str,
465
- ) -> 'Times':
512
+ ) -> 'Time':
466
513
  """
467
514
  Return the new instance of object shifted using snaptime.
468
515
 
@@ -472,14 +519,14 @@ class Times:
472
519
 
473
520
  source = self.__source
474
521
 
475
- return Times(
522
+ return Time(
476
523
  notate, anchor=source)
477
524
 
478
525
 
479
526
  def shifz(
480
527
  self,
481
528
  tzname: str,
482
- ) -> 'Times':
529
+ ) -> 'Time':
483
530
  """
484
531
  Return the new instance of object shifted using datetime.
485
532
 
@@ -498,5 +545,5 @@ class Times:
498
545
  source
499
546
  .astimezone(tzinfo))
500
547
 
501
- return Times(
548
+ return Time(
502
549
  source, tzname=tzname)
encommon/times/timer.py CHANGED
@@ -11,7 +11,7 @@ from typing import Optional
11
11
 
12
12
  from .common import NUMERIC
13
13
  from .common import PARSABLE
14
- from .times import Times
14
+ from .time import Time
15
15
 
16
16
 
17
17
 
@@ -36,7 +36,7 @@ class Timer:
36
36
  """
37
37
 
38
38
  __timer: float
39
- __times: Times
39
+ __time: Time
40
40
 
41
41
 
42
42
  def __init__(
@@ -50,10 +50,10 @@ class Timer:
50
50
  """
51
51
 
52
52
  timer = float(timer)
53
- start = Times(start)
53
+ start = Time(start)
54
54
 
55
55
  self.__timer = timer
56
- self.__times = start
56
+ self.__time = start
57
57
 
58
58
 
59
59
  @property
@@ -70,16 +70,16 @@ class Timer:
70
70
 
71
71
 
72
72
  @property
73
- def times(
73
+ def time(
74
74
  self,
75
- ) -> Times:
75
+ ) -> Time:
76
76
  """
77
77
  Return the value for the attribute from class instance.
78
78
 
79
79
  :returns: Value for the attribute from class instance.
80
80
  """
81
81
 
82
- return self.__times
82
+ return self.__time
83
83
 
84
84
 
85
85
  @property
@@ -92,7 +92,7 @@ class Timer:
92
92
  :returns: Seconds that have elapsed since the interval.
93
93
  """
94
94
 
95
- return self.times.since
95
+ return self.time.since
96
96
 
97
97
 
98
98
  @property
@@ -141,7 +141,7 @@ class Timer:
141
141
  :param value: Override the time updated for timer value.
142
142
  """
143
143
 
144
- value = Times(
144
+ value = Time(
145
145
  value or 'now')
146
146
 
147
- self.__times = value
147
+ self.__time = value
encommon/times/timers.py CHANGED
@@ -21,8 +21,8 @@ from sqlalchemy.orm import sessionmaker
21
21
 
22
22
  from .common import PARSABLE
23
23
  from .params import TimersParams
24
+ from .time import Time
24
25
  from .timer import Timer
25
- from .times import Times
26
26
 
27
27
  if TYPE_CHECKING:
28
28
  from .params import TimerParams
@@ -97,7 +97,7 @@ class Timers:
97
97
  >>> timers.ready('one')
98
98
  True
99
99
 
100
- :param params: Parameters for instantiating the instance.
100
+ :param params: Parameters used to instantiate the class.
101
101
  :param store: Optional database path for keeping state.
102
102
  :param group: Optional override for default group name.
103
103
  """
@@ -322,12 +322,12 @@ class Timers:
322
322
 
323
323
  for unique, timer in items:
324
324
 
325
- update = Times('now')
325
+ update = Time('now')
326
326
 
327
327
  append = TimersTable(
328
328
  group=group,
329
329
  unique=unique,
330
- last=timer.times.subsec,
330
+ last=timer.time.subsec,
331
331
  update=update.subsec)
332
332
 
333
333
  session.merge(append)
@@ -374,7 +374,7 @@ class Timers:
374
374
  Create a new timer using the provided input parameters.
375
375
 
376
376
  :param unique: Unique identifier for the related child.
377
- :param params: Parameters for instantiating the instance.
377
+ :param params: Parameters used to instantiate the class.
378
378
  :returns: Newly constructed instance of related class.
379
379
  """
380
380
 
encommon/times/unitime.py CHANGED
@@ -19,6 +19,15 @@ def unitime(
19
19
  """
20
20
  Return the seconds in integer format for provided input.
21
21
 
22
+ Example
23
+ -------
24
+ >>> unitime('1d')
25
+ 86400
26
+ >>> unitime('1y')
27
+ 31536000
28
+ >>> unitime('1w3d4h')
29
+ 878400
30
+
22
31
  :param input: Input that will be converted into seconds.
23
32
  :returns: Seconds in integer format for provided input.
24
33
  """
encommon/times/window.py CHANGED
@@ -17,7 +17,7 @@ from croniter import croniter
17
17
  from .common import PARSABLE
18
18
  from .common import SCHEDULE
19
19
  from .parse import parse_time
20
- from .times import Times
20
+ from .time import Time
21
21
 
22
22
 
23
23
 
@@ -42,13 +42,13 @@ class Window:
42
42
  """
43
43
 
44
44
  __window: SCHEDULE
45
- __start: Times
46
- __stop: Times
47
- __anchor: Times
45
+ __start: Time
46
+ __stop: Time
47
+ __anchor: Time
48
48
  __delay: float
49
49
 
50
- __wlast: Times
51
- __wnext: Times
50
+ __wlast: Time
51
+ __wnext: Time
52
52
 
53
53
 
54
54
  def __init__(
@@ -67,9 +67,9 @@ class Window:
67
67
  anchor = anchor or start
68
68
 
69
69
  window = copy(window)
70
- start = Times(start)
71
- stop = Times(stop)
72
- anchor = Times(anchor)
70
+ start = Time(start)
71
+ stop = Time(stop)
72
+ anchor = Time(anchor)
73
73
  delay = float(delay)
74
74
 
75
75
  assert stop > start
@@ -114,40 +114,40 @@ class Window:
114
114
  @property
115
115
  def start(
116
116
  self,
117
- ) -> Times:
117
+ ) -> Time:
118
118
  """
119
119
  Return the value for the attribute from class instance.
120
120
 
121
121
  :returns: Value for the attribute from class instance.
122
122
  """
123
123
 
124
- return Times(self.__start)
124
+ return Time(self.__start)
125
125
 
126
126
 
127
127
  @property
128
128
  def stop(
129
129
  self,
130
- ) -> Times:
130
+ ) -> Time:
131
131
  """
132
132
  Return the value for the attribute from class instance.
133
133
 
134
134
  :returns: Value for the attribute from class instance.
135
135
  """
136
136
 
137
- return Times(self.__stop)
137
+ return Time(self.__stop)
138
138
 
139
139
 
140
140
  @property
141
141
  def anchor(
142
142
  self,
143
- ) -> Times:
143
+ ) -> Time:
144
144
  """
145
145
  Return the value for the attribute from class instance.
146
146
 
147
147
  :returns: Value for the attribute from class instance.
148
148
  """
149
149
 
150
- return Times(self.__anchor)
150
+ return Time(self.__anchor)
151
151
 
152
152
 
153
153
  @property
@@ -166,51 +166,51 @@ class Window:
166
166
  @property
167
167
  def last(
168
168
  self,
169
- ) -> Times:
169
+ ) -> Time:
170
170
  """
171
171
  Return the value for the attribute from class instance.
172
172
 
173
173
  :returns: Value for the attribute from class instance.
174
174
  """
175
175
 
176
- return Times(self.__wlast)
176
+ return Time(self.__wlast)
177
177
 
178
178
 
179
179
  @property
180
180
  def next(
181
181
  self,
182
- ) -> Times:
182
+ ) -> Time:
183
183
  """
184
184
  Return the value for the attribute from class instance.
185
185
 
186
186
  :returns: Value for the attribute from class instance.
187
187
  """
188
188
 
189
- return Times(self.__wnext)
189
+ return Time(self.__wnext)
190
190
 
191
191
 
192
192
  @property
193
193
  def soonest(
194
194
  self,
195
- ) -> Times:
195
+ ) -> Time:
196
196
  """
197
197
  Return the value for the attribute from class instance.
198
198
 
199
199
  :returns: Value for the attribute from class instance.
200
200
  """
201
- return Times(Times() - self.delay)
201
+ return Time(Time() - self.delay)
202
202
 
203
203
 
204
204
  @property
205
205
  def latest(
206
206
  self,
207
- ) -> Times:
207
+ ) -> Time:
208
208
  """
209
209
  Return the value for the attribute from class instance.
210
210
 
211
211
  :returns: Value for the attribute from class instance.
212
212
  """
213
- return Times(self.stop - self.delay)
213
+ return Time(self.stop - self.delay)
214
214
 
215
215
 
216
216
  @property
@@ -230,7 +230,7 @@ class Window:
230
230
  self,
231
231
  anchor: PARSABLE,
232
232
  backward: bool = False,
233
- ) -> tuple[Times, Times]:
233
+ ) -> tuple[Time, Time]:
234
234
  """
235
235
  Determine next and last windows for window using anchor.
236
236
 
@@ -299,7 +299,7 @@ class Window:
299
299
  :param value: Override the time updated for window value.
300
300
  """
301
301
 
302
- value = Times(
302
+ value = Time(
303
303
  value or 'now')
304
304
 
305
305
  wlast, wnext = (
@@ -314,7 +314,7 @@ def window_croniter( # noqa: CFQ004
314
314
  schedule: str,
315
315
  anchor: PARSABLE,
316
316
  backward: bool = False,
317
- ) -> tuple[Times, Times]:
317
+ ) -> tuple[Time, Time]:
318
318
  """
319
319
  Determine next and previous times for cronjob schedule.
320
320
 
@@ -365,8 +365,8 @@ def window_croniter( # noqa: CFQ004
365
365
 
366
366
 
367
367
  return (
368
- Times(wlast),
369
- Times(wnext))
368
+ Time(wlast),
369
+ Time(wnext))
370
370
 
371
371
 
372
372
 
@@ -374,7 +374,7 @@ def window_interval(
374
374
  schedule: dict[str, int],
375
375
  anchor: PARSABLE,
376
376
  backward: bool = False,
377
- ) -> tuple[Times, Times]:
377
+ ) -> tuple[Time, Time]:
378
378
  """
379
379
  Determine next and previous times for interval schedule.
380
380
 
@@ -403,5 +403,5 @@ def window_interval(
403
403
 
404
404
 
405
405
  return (
406
- Times(wlast),
407
- Times(wnext))
406
+ Time(wlast),
407
+ Time(wnext))
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 .times import Times
24
+ from .time import Time
25
25
  from .window import Window
26
26
 
27
27
  if TYPE_CHECKING:
@@ -97,7 +97,7 @@ class Windows:
97
97
  >>> [windows.ready('one') for x in range(3)]
98
98
  [True, True, False]
99
99
 
100
- :param params: Parameters for instantiating the instance.
100
+ :param params: Parameters used to instantiate the class.
101
101
  :param start: Determine the start for scheduling window.
102
102
  :param stop: Determine the ending for scheduling window.
103
103
  :param store: Optional database path for keeping state.
@@ -114,8 +114,8 @@ class Windows:
114
114
  # pylint: disable=unsubscriptable-object
115
115
  sessionmaker[Session])
116
116
 
117
- __start: Times
118
- __stop: Times
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 = Times(start)
151
- stop = Times(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
- ) -> Times:
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 Times(self.__start)
259
+ return Time(self.__start)
260
260
 
261
261
 
262
262
  @property
263
263
  def stop(
264
264
  self,
265
- ) -> Times:
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 Times(self.__stop)
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 = Times('now')
389
+ update = Time('now')
390
390
 
391
391
  append = WindowsTable(
392
392
  group=group,
@@ -439,7 +439,7 @@ class Windows:
439
439
  Create a new window using the provided input parameters.
440
440
 
441
441
  :param unique: Unique identifier for the related child.
442
- :param params: Parameters for instantiating the instance.
442
+ :param params: Parameters used to instantiate the class.
443
443
  :returns: Newly constructed instance of related class.
444
444
  """
445
445
 
encommon/types/classes.py CHANGED
@@ -7,8 +7,6 @@ is permitted, for more information consult the project license file.
7
7
 
8
8
 
9
9
 
10
- from typing import Any
11
-
12
10
  from pydantic import BaseModel as Pydantic
13
11
 
14
12
  from .types import DictStrAny
@@ -23,19 +21,8 @@ class BaseModel(Pydantic, extra='forbid'):
23
21
  """
24
22
 
25
23
 
26
- def __init__(
27
- self,
28
- **data: Any,
29
- ) -> None:
30
- """
31
- Initialize instance for class using provided parameters.
32
- """
33
-
34
- super().__init__(**data)
35
-
36
-
37
24
  @property
38
- def model_dumped(
25
+ def endumped(
39
26
  self,
40
27
  ) -> DictStrAny:
41
28
  """
@@ -48,7 +35,7 @@ class BaseModel(Pydantic, extra='forbid'):
48
35
 
49
36
 
50
37
  @property
51
- def model_pruned(
38
+ def enpruned(
52
39
  self,
53
40
  ) -> DictStrAny:
54
41
  """
encommon/types/lists.py CHANGED
@@ -19,6 +19,12 @@ def inlist(
19
19
  """
20
20
  Return the boolean indicating whether needle in haystack.
21
21
 
22
+ Example
23
+ -------
24
+ >>> haystack = [1, 2, 3]
25
+ >>> inlist(2, haystack)
26
+ True
27
+
22
28
  :param needle: Provided item that may be within haystack.
23
29
  :param haystack: List of items which may contain needle.
24
30
  :returns: Boolean indicating whether 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
- dict[str, Any],
29
+ DictStrAny,
29
30
  list[Any]]
30
31
 
31
32
  _GETABLE = Union[
encommon/types/strings.py CHANGED
@@ -121,6 +121,11 @@ def rplstr(
121
121
  """
122
122
  Return the source string with the match value replaced.
123
123
 
124
+ Example
125
+ -------
126
+ >>> rplstr('foo', 'foo', 'bar')
127
+ 'bar'
128
+
124
129
  :param source: String that to be processed and returned.
125
130
  :param match: What will be replaced within the string.
126
131
  :param value: Replace value for the string is matched.
@@ -26,8 +26,8 @@ def test_BaseModel() -> None:
26
26
  params = LoggerParams(
27
27
  stdo_level='info')
28
28
 
29
- dumped = params.model_dumped
30
- pruned = params.model_pruned
29
+ dumped = params.endumped
30
+ pruned = params.enpruned
31
31
 
32
32
  assert dumped == {
33
33
  'file_level': None,
@@ -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 = list(empty.__dict__)
27
+ attrs = lattrs(empty)
27
28
 
28
29
  assert attrs == [
29
30
  '_EmptyType__empty']