dycw-utilities 0.129.6__py3-none-any.whl → 0.129.7__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dycw-utilities
3
- Version: 0.129.6
3
+ Version: 0.129.7
4
4
  Author-email: Derek Wan <d.wan@icloud.com>
5
5
  License-File: LICENSE
6
6
  Requires-Python: >=3.12
@@ -93,7 +93,7 @@ Requires-Dist: polars-lts-cpu<1.31,>=1.30.0; extra == 'zzz-test-iterables'
93
93
  Requires-Dist: whenever<0.9,>=0.8.4; extra == 'zzz-test-iterables'
94
94
  Provides-Extra: zzz-test-jupyter
95
95
  Requires-Dist: jupyterlab<4.3,>=4.2.0; extra == 'zzz-test-jupyter'
96
- Requires-Dist: pandas<2.3,>=2.2.2; extra == 'zzz-test-jupyter'
96
+ Requires-Dist: pandas<2.4,>=2.3.0; extra == 'zzz-test-jupyter'
97
97
  Requires-Dist: polars-lts-cpu<1.31,>=1.30.0; extra == 'zzz-test-jupyter'
98
98
  Provides-Extra: zzz-test-logging
99
99
  Requires-Dist: atomicwrites<1.5,>=1.4.1; extra == 'zzz-test-logging'
@@ -173,7 +173,7 @@ Requires-Dist: scipy<1.16,>=1.15.3; extra == 'zzz-test-scipy'
173
173
  Provides-Extra: zzz-test-sentinel
174
174
  Provides-Extra: zzz-test-shelve
175
175
  Provides-Extra: zzz-test-slack-sdk
176
- Requires-Dist: aiohttp<3.12.8,>=3.12.7; extra == 'zzz-test-slack-sdk'
176
+ Requires-Dist: aiohttp<3.12.10,>=3.12.9; extra == 'zzz-test-slack-sdk'
177
177
  Requires-Dist: slack-sdk<3.36,>=3.35.0; extra == 'zzz-test-slack-sdk'
178
178
  Provides-Extra: zzz-test-socket
179
179
  Provides-Extra: zzz-test-sqlalchemy
@@ -1,4 +1,4 @@
1
- utilities/__init__.py,sha256=Odk_y5HDH2OquSZJAdWdoTST_nZpx27fTwquoNg32dI,60
1
+ utilities/__init__.py,sha256=V6BzEBm23oBvaBdsKWGFjnWWR1qGDDjldECqyydnokk,60
2
2
  utilities/altair.py,sha256=Gpja-flOo-Db0PIPJLJsgzAlXWoKUjPU1qY-DQ829ek,9156
3
3
  utilities/asyncio.py,sha256=3n5EIcSq2xtEF1i4oR0oY2JmBq3NyugeHKFK39Mt22s,37987
4
4
  utilities/atomicwrites.py,sha256=geFjn9Pwn-tTrtoGjDDxWli9NqbYfy3gGL6ZBctiqSo,5393
@@ -78,7 +78,7 @@ utilities/tenacity.py,sha256=1PUvODiBVgeqIh7G5TRt5WWMSqjLYkEqP53itT97WQc,4914
78
78
  utilities/text.py,sha256=ymBFlP_cA8OgNnZRVNs7FAh7OG8HxE6YkiLEMZv5g_A,11297
79
79
  utilities/threading.py,sha256=GvBOp4CyhHfN90wGXZuA2VKe9fGzMaEa7oCl4f3nnPU,1009
80
80
  utilities/timer.py,sha256=Rkc49KSpHuC8s7vUxGO9DU55U9I6yDKnchsQqrUCVBs,4075
81
- utilities/traceback.py,sha256=Jg7HS3AwQ-W-msdwHp22_PSHZcR54PbmsSf115B6TSM,27435
81
+ utilities/traceback.py,sha256=Rf_4XIz6AQaBcTRr7Tiw7RCIv_O_bN7Hd-Cnr8SPXN4,28920
82
82
  utilities/types.py,sha256=gP04CcCOyFrG7BgblVCsrrChiuO2x842NDVW-GF7odo,18370
83
83
  utilities/typing.py,sha256=H6ysJkI830aRwLsMKz0SZIw4cpcsm7d6KhQOwr-SDh0,13817
84
84
  utilities/tzdata.py,sha256=yCf70NICwAeazN3_JcXhWvRqCy06XJNQ42j7r6gw3HY,1217
@@ -89,7 +89,7 @@ utilities/warnings.py,sha256=un1LvHv70PU-LLv8RxPVmugTzDJkkGXRMZTE2-fTQHw,1771
89
89
  utilities/whenever.py,sha256=jS31ZAY5OMxFxLja_Yo5Fidi87Pd-GoVZ7Vi_teqVDA,16743
90
90
  utilities/zipfile.py,sha256=24lQc9ATcJxHXBPc_tBDiJk48pWyRrlxO2fIsFxU0A8,699
91
91
  utilities/zoneinfo.py,sha256=-5j7IQ9nb7gR43rdgA7ms05im-XuqhAk9EJnQBXxCoQ,1874
92
- dycw_utilities-0.129.6.dist-info/METADATA,sha256=tC_nJcnk-38KjYuNvAhfUg4mKnytwE71-7ndZfBs0bQ,12803
93
- dycw_utilities-0.129.6.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
94
- dycw_utilities-0.129.6.dist-info/licenses/LICENSE,sha256=gppZp16M6nSVpBbUBrNL6JuYfvKwZiKgV7XoKKsHzqo,1066
95
- dycw_utilities-0.129.6.dist-info/RECORD,,
92
+ dycw_utilities-0.129.7.dist-info/METADATA,sha256=SnavcALe7H7k-aZL5l6A8TunsE1JBzlrep0hD7Y6fkw,12804
93
+ dycw_utilities-0.129.7.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
94
+ dycw_utilities-0.129.7.dist-info/licenses/LICENSE,sha256=gppZp16M6nSVpBbUBrNL6JuYfvKwZiKgV7XoKKsHzqo,1066
95
+ dycw_utilities-0.129.7.dist-info/RECORD,,
utilities/__init__.py CHANGED
@@ -1,3 +1,3 @@
1
1
  from __future__ import annotations
2
2
 
3
- __version__ = "0.129.6"
3
+ __version__ = "0.129.7"
utilities/traceback.py CHANGED
@@ -26,6 +26,7 @@ from typing import (
26
26
  runtime_checkable,
27
27
  )
28
28
 
29
+ from utilities.datetime import get_datetime, get_now
29
30
  from utilities.errors import ImpossibleCaseError
30
31
  from utilities.functions import (
31
32
  ensure_not_none,
@@ -45,8 +46,9 @@ from utilities.reprlib import (
45
46
  yield_call_args_repr,
46
47
  yield_mapping_repr,
47
48
  )
48
- from utilities.types import TBaseException, TCallable
49
+ from utilities.types import MaybeCallableDateTime, TBaseException, TCallable
49
50
  from utilities.version import get_version
51
+ from utilities.whenever import serialize_duration
50
52
 
51
53
  if TYPE_CHECKING:
52
54
  from collections.abc import Callable, Iterable, Iterator
@@ -60,6 +62,7 @@ if TYPE_CHECKING:
60
62
  _T = TypeVar("_T")
61
63
  _CALL_ARGS = "_CALL_ARGS"
62
64
  _INDENT = 4 * " "
65
+ _START = get_now()
63
66
 
64
67
 
65
68
  ##
@@ -78,6 +81,7 @@ class RichTracebackFormatter(Formatter):
78
81
  /,
79
82
  *,
80
83
  defaults: StrMapping | None = None,
84
+ start: MaybeCallableDateTime | None = _START,
81
85
  version: MaybeCallableVersionLike | None = None,
82
86
  max_width: int = RICH_MAX_WIDTH,
83
87
  indent_size: int = RICH_INDENT_SIZE,
@@ -89,7 +93,8 @@ class RichTracebackFormatter(Formatter):
89
93
  post: Callable[[str], str] | None = None,
90
94
  ) -> None:
91
95
  super().__init__(fmt, datefmt, style, validate, defaults=defaults)
92
- self._version = version
96
+ self._start = get_datetime(datetime=start)
97
+ self._version = get_version(version=version)
93
98
  self._max_width = max_width
94
99
  self._indent_size = indent_size
95
100
  self._max_length = max_length
@@ -110,6 +115,7 @@ class RichTracebackFormatter(Formatter):
110
115
  exc_value = ensure_not_none(exc_value, desc="exc_value")
111
116
  error = get_rich_traceback(
112
117
  exc_value,
118
+ start=self._start,
113
119
  version=self._version,
114
120
  max_width=self._max_width,
115
121
  indent_size=self._indent_size,
@@ -263,6 +269,7 @@ class ExcChainTB(Generic[TBaseException]):
263
269
  errors: list[
264
270
  ExcGroupTB[TBaseException] | ExcTB[TBaseException] | TBaseException
265
271
  ] = field(default_factory=list)
272
+ start: MaybeCallableDateTime | None = field(default=_START, repr=False)
266
273
  version: MaybeCallableVersionLike | None = field(default=None, repr=False)
267
274
  max_width: int = RICH_MAX_WIDTH
268
275
  indent_size: int = RICH_INDENT_SIZE
@@ -292,7 +299,7 @@ class ExcChainTB(Generic[TBaseException]):
292
299
  """Format the traceback."""
293
300
  lines: list[str] = []
294
301
  if header: # pragma: no cover
295
- lines.extend(_yield_header_lines(version=self.version))
302
+ lines.extend(_yield_header_lines(start=self.start, version=self.version))
296
303
  total = len(self.errors)
297
304
  for i, errors in enumerate(self.errors, start=1):
298
305
  lines.append(f"Exception chain {i}/{total}:")
@@ -315,6 +322,7 @@ class ExcGroupTB(Generic[TBaseException]):
315
322
  errors: list[
316
323
  ExcGroupTB[TBaseException] | ExcTB[TBaseException] | TBaseException
317
324
  ] = field(default_factory=list)
325
+ start: MaybeCallableDateTime | None = field(default=_START, repr=False)
318
326
  version: MaybeCallableVersionLike | None = field(default=None, repr=False)
319
327
  max_width: int = RICH_MAX_WIDTH
320
328
  indent_size: int = RICH_INDENT_SIZE
@@ -333,7 +341,7 @@ class ExcGroupTB(Generic[TBaseException]):
333
341
  """Format the traceback."""
334
342
  lines: list[str] = [] # skipif-ci
335
343
  if header: # pragma: no cover
336
- lines.extend(_yield_header_lines(version=self.version))
344
+ lines.extend(_yield_header_lines(start=self.start, version=self.version))
337
345
  lines.append("Exception group:") # skipif-ci
338
346
  match self.exc_group: # skipif-ci
339
347
  case ExcTB() as exc_tb:
@@ -363,6 +371,7 @@ class ExcTB(Generic[TBaseException]):
363
371
 
364
372
  frames: list[_Frame] = field(default_factory=list)
365
373
  error: TBaseException
374
+ start: MaybeCallableDateTime | None = field(default=_START, repr=False)
366
375
  version: MaybeCallableVersionLike | None = field(default=None, repr=False)
367
376
  max_width: int = RICH_MAX_WIDTH
368
377
  indent_size: int = RICH_INDENT_SIZE
@@ -391,7 +400,7 @@ class ExcTB(Generic[TBaseException]):
391
400
  total = len(self)
392
401
  lines: list[str] = []
393
402
  if header: # pragma: no cover
394
- lines.extend(_yield_header_lines(version=self.version))
403
+ lines.extend(_yield_header_lines(start=self.start, version=self.version))
395
404
  for i, frame in enumerate(self.frames):
396
405
  is_head = i < total - 1
397
406
  lines.append(
@@ -485,6 +494,7 @@ def get_rich_traceback(
485
494
  error: TBaseException,
486
495
  /,
487
496
  *,
497
+ start: MaybeCallableDateTime | None = _START,
488
498
  version: MaybeCallableVersionLike | None = None,
489
499
  max_width: int = RICH_MAX_WIDTH,
490
500
  indent_size: int = RICH_INDENT_SIZE,
@@ -506,6 +516,7 @@ def get_rich_traceback(
506
516
  err_recast = cast("TBaseException", err)
507
517
  return _get_rich_traceback_non_chain(
508
518
  err_recast,
519
+ start=start,
509
520
  version=version,
510
521
  max_width=max_width,
511
522
  indent_size=indent_size,
@@ -520,6 +531,7 @@ def get_rich_traceback(
520
531
  errors=[
521
532
  _get_rich_traceback_non_chain(
522
533
  e,
534
+ start=start,
523
535
  version=version,
524
536
  max_width=max_width,
525
537
  indent_size=indent_size,
@@ -530,6 +542,7 @@ def get_rich_traceback(
530
542
  )
531
543
  for e in errs_recast
532
544
  ],
545
+ start=start,
533
546
  version=version,
534
547
  max_width=max_width,
535
548
  indent_size=indent_size,
@@ -544,6 +557,7 @@ def _get_rich_traceback_non_chain(
544
557
  error: ExceptionGroup[Any] | TBaseException,
545
558
  /,
546
559
  *,
560
+ start: MaybeCallableDateTime | None = _START,
547
561
  version: MaybeCallableVersionLike | None = None,
548
562
  max_width: int = RICH_MAX_WIDTH,
549
563
  indent_size: int = RICH_INDENT_SIZE,
@@ -567,6 +581,7 @@ def _get_rich_traceback_non_chain(
567
581
  errors = [
568
582
  _get_rich_traceback_non_chain(
569
583
  e,
584
+ start=start,
570
585
  version=version,
571
586
  max_width=max_width,
572
587
  indent_size=indent_size,
@@ -580,6 +595,7 @@ def _get_rich_traceback_non_chain(
580
595
  return ExcGroupTB(
581
596
  exc_group=exc_group_or_exc_tb,
582
597
  errors=errors,
598
+ start=start,
583
599
  version=version,
584
600
  max_width=max_width,
585
601
  indent_size=indent_size,
@@ -591,6 +607,7 @@ def _get_rich_traceback_non_chain(
591
607
  case BaseException() as base_exc:
592
608
  return _get_rich_traceback_base_one(
593
609
  base_exc,
610
+ start=start,
594
611
  version=version,
595
612
  max_width=max_width,
596
613
  indent_size=indent_size,
@@ -607,6 +624,7 @@ def _get_rich_traceback_base_one(
607
624
  error: TBaseException,
608
625
  /,
609
626
  *,
627
+ start: MaybeCallableDateTime | None = _START,
610
628
  version: MaybeCallableVersionLike | None = None,
611
629
  max_width: int = RICH_MAX_WIDTH,
612
630
  indent_size: int = RICH_INDENT_SIZE,
@@ -638,6 +656,7 @@ def _get_rich_traceback_base_one(
638
656
  return ExcTB(
639
657
  frames=frames,
640
658
  error=error,
659
+ start=start,
641
660
  version=version,
642
661
  max_width=max_width,
643
662
  indent_size=indent_size,
@@ -793,13 +812,25 @@ def _merge_frames(
793
812
 
794
813
 
795
814
  def _yield_header_lines(
796
- *, version: MaybeCallableVersionLike | None = None
815
+ *,
816
+ start: MaybeCallableDateTime | None = _START,
817
+ version: MaybeCallableVersionLike | None = None,
797
818
  ) -> Iterator[str]:
798
819
  """Yield the header lines."""
799
- from utilities.tzlocal import get_now_local
820
+ from utilities.tzlocal import get_local_time_zone, get_now_local
800
821
  from utilities.whenever import serialize_zoned_datetime
801
822
 
802
- yield f"Date/time | {serialize_zoned_datetime(get_now_local())}"
823
+ now = get_now_local()
824
+ start_use = get_datetime(datetime=start)
825
+ start_use = (
826
+ None if start_use is None else start_use.astimezone(get_local_time_zone())
827
+ )
828
+ yield f"Date/time | {serialize_zoned_datetime(now)}"
829
+ start_str = "" if start_use is None else serialize_zoned_datetime(start_use)
830
+ yield f"Started | {start_str}"
831
+ duration = None if start_use is None else (now - start_use)
832
+ duration_str = "" if duration is None else serialize_duration(duration)
833
+ yield f"Duration | {duration_str}"
803
834
  yield f"User | {getuser()}"
804
835
  yield f"Host | {gethostname()}"
805
836
  version_use = "" if version is None else get_version(version=version)