dycw-utilities 0.166.30__py3-none-any.whl → 0.185.8__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 (96) hide show
  1. dycw_utilities-0.185.8.dist-info/METADATA +33 -0
  2. dycw_utilities-0.185.8.dist-info/RECORD +90 -0
  3. {dycw_utilities-0.166.30.dist-info → dycw_utilities-0.185.8.dist-info}/WHEEL +1 -1
  4. {dycw_utilities-0.166.30.dist-info → dycw_utilities-0.185.8.dist-info}/entry_points.txt +1 -0
  5. utilities/__init__.py +1 -1
  6. utilities/altair.py +17 -10
  7. utilities/asyncio.py +50 -72
  8. utilities/atools.py +9 -11
  9. utilities/cachetools.py +16 -11
  10. utilities/click.py +76 -19
  11. utilities/concurrent.py +1 -1
  12. utilities/constants.py +492 -0
  13. utilities/contextlib.py +23 -30
  14. utilities/contextvars.py +1 -23
  15. utilities/core.py +2581 -0
  16. utilities/dataclasses.py +16 -119
  17. utilities/docker.py +387 -0
  18. utilities/enum.py +1 -1
  19. utilities/errors.py +2 -16
  20. utilities/fastapi.py +5 -5
  21. utilities/fpdf2.py +2 -1
  22. utilities/functions.py +34 -265
  23. utilities/http.py +2 -3
  24. utilities/hypothesis.py +84 -29
  25. utilities/importlib.py +17 -1
  26. utilities/iterables.py +39 -575
  27. utilities/jinja2.py +145 -0
  28. utilities/jupyter.py +5 -3
  29. utilities/libcst.py +1 -1
  30. utilities/lightweight_charts.py +4 -6
  31. utilities/logging.py +24 -24
  32. utilities/math.py +1 -36
  33. utilities/more_itertools.py +4 -6
  34. utilities/numpy.py +2 -1
  35. utilities/operator.py +2 -2
  36. utilities/orjson.py +42 -43
  37. utilities/os.py +4 -147
  38. utilities/packaging.py +129 -0
  39. utilities/parse.py +35 -15
  40. utilities/pathlib.py +3 -120
  41. utilities/platform.py +8 -90
  42. utilities/polars.py +38 -32
  43. utilities/postgres.py +37 -33
  44. utilities/pottery.py +20 -18
  45. utilities/pqdm.py +3 -4
  46. utilities/psutil.py +2 -3
  47. utilities/pydantic.py +25 -0
  48. utilities/pydantic_settings.py +87 -16
  49. utilities/pydantic_settings_sops.py +16 -3
  50. utilities/pyinstrument.py +4 -4
  51. utilities/pytest.py +96 -125
  52. utilities/pytest_plugins/pytest_regressions.py +2 -2
  53. utilities/pytest_regressions.py +32 -11
  54. utilities/random.py +2 -8
  55. utilities/redis.py +98 -94
  56. utilities/reprlib.py +11 -118
  57. utilities/shellingham.py +66 -0
  58. utilities/shutil.py +25 -0
  59. utilities/slack_sdk.py +13 -12
  60. utilities/sqlalchemy.py +57 -30
  61. utilities/sqlalchemy_polars.py +16 -25
  62. utilities/subprocess.py +2590 -0
  63. utilities/tabulate.py +32 -0
  64. utilities/testbook.py +8 -8
  65. utilities/text.py +24 -99
  66. utilities/throttle.py +159 -0
  67. utilities/time.py +18 -0
  68. utilities/timer.py +31 -14
  69. utilities/traceback.py +16 -23
  70. utilities/types.py +42 -2
  71. utilities/typing.py +26 -14
  72. utilities/uuid.py +1 -1
  73. utilities/version.py +202 -45
  74. utilities/whenever.py +53 -150
  75. dycw_utilities-0.166.30.dist-info/METADATA +0 -41
  76. dycw_utilities-0.166.30.dist-info/RECORD +0 -98
  77. dycw_utilities-0.166.30.dist-info/licenses/LICENSE +0 -21
  78. utilities/aeventkit.py +0 -388
  79. utilities/atomicwrites.py +0 -182
  80. utilities/cryptography.py +0 -41
  81. utilities/getpass.py +0 -8
  82. utilities/git.py +0 -19
  83. utilities/gzip.py +0 -31
  84. utilities/json.py +0 -70
  85. utilities/pickle.py +0 -25
  86. utilities/re.py +0 -156
  87. utilities/sentinel.py +0 -73
  88. utilities/socket.py +0 -8
  89. utilities/string.py +0 -20
  90. utilities/tempfile.py +0 -77
  91. utilities/typed_settings.py +0 -152
  92. utilities/tzdata.py +0 -11
  93. utilities/tzlocal.py +0 -28
  94. utilities/warnings.py +0 -65
  95. utilities/zipfile.py +0 -25
  96. utilities/zoneinfo.py +0 -133
utilities/contextlib.py CHANGED
@@ -1,6 +1,5 @@
1
1
  from __future__ import annotations
2
2
 
3
- import re
4
3
  from asyncio import create_task, get_event_loop
5
4
  from contextlib import (
6
5
  _AsyncGeneratorContextManager,
@@ -90,12 +89,13 @@ def enhanced_context_manager[**P, T_co](
90
89
  with gcm as value:
91
90
  yield value
92
91
  finally:
93
- _ = signal(SIGABRT, sigabrt0) if sigabrt else None
94
- _ = signal(SIGFPE, sigfpe0) if sigfpe else None
95
- _ = signal(SIGILL, sigill0) if sigill else None
96
- _ = signal(SIGINT, sigint0) if sigint else None
97
- _ = signal(SIGSEGV, sigsegv0) if sigsegv else None
98
- _ = signal(SIGTERM, sigterm0) if sigterm else None
92
+ with _suppress_signal_error():
93
+ _ = signal(SIGABRT, sigabrt0) if sigabrt else None
94
+ _ = signal(SIGFPE, sigfpe0) if sigfpe else None
95
+ _ = signal(SIGILL, sigill0) if sigill else None
96
+ _ = signal(SIGINT, sigint0) if sigint else None
97
+ _ = signal(SIGSEGV, sigsegv0) if sigsegv else None
98
+ _ = signal(SIGTERM, sigterm0) if sigterm else None
99
99
 
100
100
  return wrapped
101
101
 
@@ -173,12 +173,13 @@ def enhanced_async_context_manager[**P, T_co](
173
173
  async with agcm as value:
174
174
  yield value
175
175
  finally:
176
- _ = signal(SIGABRT, sigabrt0) if sigabrt else None
177
- _ = signal(SIGFPE, sigfpe0) if sigfpe else None
178
- _ = signal(SIGILL, sigill0) if sigill else None
179
- _ = signal(SIGINT, sigint0) if sigint else None
180
- _ = signal(SIGSEGV, sigsegv0) if sigsegv else None
181
- _ = signal(SIGTERM, sigterm0) if sigterm else None
176
+ with _suppress_signal_error():
177
+ _ = signal(SIGABRT, sigabrt0) if sigabrt else None
178
+ _ = signal(SIGFPE, sigfpe0) if sigfpe else None
179
+ _ = signal(SIGILL, sigill0) if sigill else None
180
+ _ = signal(SIGINT, sigint0) if sigint else None
181
+ _ = signal(SIGSEGV, sigsegv0) if sigsegv else None
182
+ _ = signal(SIGTERM, sigterm0) if sigterm else None
182
183
 
183
184
  return wrapped
184
185
 
@@ -191,7 +192,8 @@ def _swap_handler(
191
192
  ) -> _HANDLER:
192
193
  orig_handler = getsignal(signum)
193
194
  new_handler = _make_handler(signum, obj)
194
- _ = signal(signum, new_handler)
195
+ with _suppress_signal_error():
196
+ _ = signal(signum, new_handler)
195
197
  return orig_handler
196
198
 
197
199
 
@@ -220,24 +222,15 @@ def _make_handler(
220
222
  return new_handler
221
223
 
222
224
 
223
- ##
224
-
225
-
226
- _SUPER_OBJECT_HAS_NO_ATTRIBUTE = re.compile(r"'super' object has no attribute '\w+'")
227
-
228
-
229
225
  @contextmanager
230
- def suppress_super_object_attribute_error() -> Iterator[None]:
231
- """Suppress the super() attribute error, for mix-ins."""
226
+ def _suppress_signal_error() -> Iterator[None]:
232
227
  try:
233
228
  yield
234
- except AttributeError as error:
235
- if not _SUPER_OBJECT_HAS_NO_ATTRIBUTE.search(error.args[0]):
236
- raise
229
+ except ValueError as error:
230
+ (msg,) = error.args
231
+ if msg == "signal only works in main thread of the main interpreter":
232
+ return
233
+ raise # pragma: no cover
237
234
 
238
235
 
239
- __all__ = [
240
- "enhanced_async_context_manager",
241
- "enhanced_context_manager",
242
- "suppress_super_object_attribute_error",
243
- ]
236
+ __all__ = ["enhanced_async_context_manager", "enhanced_context_manager"]
utilities/contextvars.py CHANGED
@@ -1,15 +1,6 @@
1
1
  from __future__ import annotations
2
2
 
3
- from contextlib import contextmanager
4
3
  from contextvars import ContextVar
5
- from typing import TYPE_CHECKING
6
-
7
- if TYPE_CHECKING:
8
- from collections.abc import Iterator
9
-
10
-
11
- ##
12
-
13
4
 
14
5
  _GLOBAL_BREAKPOINT = ContextVar("GLOBAL_BREAKPOINT", default=False)
15
6
 
@@ -25,17 +16,4 @@ def set_global_breakpoint() -> None:
25
16
  _ = _GLOBAL_BREAKPOINT.set(True)
26
17
 
27
18
 
28
- ##
29
-
30
-
31
- @contextmanager
32
- def yield_set_context(var: ContextVar[bool], /) -> Iterator[None]:
33
- """Yield a context var as being set."""
34
- token = var.set(True)
35
- try:
36
- yield
37
- finally:
38
- _ = var.reset(token)
39
-
40
-
41
- __all__ = ["global_breakpoint", "set_global_breakpoint", "yield_set_context"]
19
+ __all__ = ["global_breakpoint", "set_global_breakpoint"]