dycw-utilities 0.148.4__py3-none-any.whl → 0.174.12__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.

Potentially problematic release.


This version of dycw-utilities might be problematic. Click here for more details.

Files changed (83) hide show
  1. dycw_utilities-0.174.12.dist-info/METADATA +41 -0
  2. dycw_utilities-0.174.12.dist-info/RECORD +104 -0
  3. dycw_utilities-0.174.12.dist-info/WHEEL +4 -0
  4. {dycw_utilities-0.148.4.dist-info → dycw_utilities-0.174.12.dist-info}/entry_points.txt +3 -0
  5. utilities/__init__.py +1 -1
  6. utilities/{eventkit.py → aeventkit.py} +12 -11
  7. utilities/altair.py +7 -6
  8. utilities/asyncio.py +113 -64
  9. utilities/atomicwrites.py +1 -1
  10. utilities/atools.py +64 -4
  11. utilities/cachetools.py +9 -6
  12. utilities/click.py +145 -49
  13. utilities/concurrent.py +1 -1
  14. utilities/contextlib.py +4 -2
  15. utilities/contextvars.py +20 -1
  16. utilities/cryptography.py +3 -3
  17. utilities/dataclasses.py +15 -28
  18. utilities/docker.py +292 -0
  19. utilities/enum.py +2 -2
  20. utilities/errors.py +1 -1
  21. utilities/fastapi.py +8 -3
  22. utilities/fpdf2.py +2 -2
  23. utilities/functions.py +20 -297
  24. utilities/git.py +19 -0
  25. utilities/grp.py +28 -0
  26. utilities/hypothesis.py +360 -78
  27. utilities/inflect.py +1 -1
  28. utilities/iterables.py +12 -58
  29. utilities/jinja2.py +148 -0
  30. utilities/json.py +1 -1
  31. utilities/libcst.py +7 -7
  32. utilities/logging.py +74 -85
  33. utilities/math.py +8 -4
  34. utilities/more_itertools.py +4 -6
  35. utilities/operator.py +1 -1
  36. utilities/orjson.py +86 -34
  37. utilities/os.py +49 -2
  38. utilities/parse.py +2 -2
  39. utilities/pathlib.py +66 -34
  40. utilities/permissions.py +297 -0
  41. utilities/platform.py +5 -5
  42. utilities/polars.py +932 -420
  43. utilities/polars_ols.py +1 -1
  44. utilities/postgres.py +299 -174
  45. utilities/pottery.py +8 -73
  46. utilities/pqdm.py +3 -3
  47. utilities/pwd.py +28 -0
  48. utilities/pydantic.py +11 -0
  49. utilities/pydantic_settings.py +240 -0
  50. utilities/pydantic_settings_sops.py +76 -0
  51. utilities/pyinstrument.py +5 -5
  52. utilities/pytest.py +155 -46
  53. utilities/pytest_plugins/pytest_randomly.py +1 -1
  54. utilities/pytest_plugins/pytest_regressions.py +7 -3
  55. utilities/pytest_regressions.py +2 -3
  56. utilities/random.py +11 -6
  57. utilities/re.py +1 -1
  58. utilities/redis.py +101 -64
  59. utilities/sentinel.py +10 -0
  60. utilities/shelve.py +4 -1
  61. utilities/shutil.py +25 -0
  62. utilities/slack_sdk.py +8 -3
  63. utilities/sqlalchemy.py +422 -352
  64. utilities/sqlalchemy_polars.py +28 -52
  65. utilities/string.py +1 -1
  66. utilities/subprocess.py +864 -0
  67. utilities/tempfile.py +62 -4
  68. utilities/testbook.py +50 -0
  69. utilities/text.py +165 -42
  70. utilities/timer.py +2 -2
  71. utilities/traceback.py +46 -36
  72. utilities/types.py +62 -23
  73. utilities/typing.py +479 -19
  74. utilities/uuid.py +42 -5
  75. utilities/version.py +27 -26
  76. utilities/whenever.py +661 -151
  77. utilities/zoneinfo.py +80 -22
  78. dycw_utilities-0.148.4.dist-info/METADATA +0 -41
  79. dycw_utilities-0.148.4.dist-info/RECORD +0 -95
  80. dycw_utilities-0.148.4.dist-info/WHEEL +0 -4
  81. dycw_utilities-0.148.4.dist-info/licenses/LICENSE +0 -21
  82. utilities/period.py +0 -237
  83. utilities/typed_settings.py +0 -144
utilities/zoneinfo.py CHANGED
@@ -7,7 +7,8 @@ from zoneinfo import ZoneInfo
7
7
 
8
8
  from whenever import ZonedDateTime
9
9
 
10
- from utilities.tzlocal import LOCAL_TIME_ZONE
10
+ from utilities.types import TIME_ZONES
11
+ from utilities.tzlocal import LOCAL_TIME_ZONE, LOCAL_TIME_ZONE_NAME
11
12
 
12
13
  if TYPE_CHECKING:
13
14
  from utilities.types import TimeZone, TimeZoneLike
@@ -19,57 +20,114 @@ UTC = ZoneInfo("UTC")
19
20
  ##
20
21
 
21
22
 
22
- def ensure_time_zone(obj: TimeZoneLike, /) -> ZoneInfo:
23
- """Ensure the object is a time zone."""
23
+ def to_zone_info(obj: TimeZoneLike, /) -> ZoneInfo:
24
+ """Convert to a time-zone."""
24
25
  match obj:
25
26
  case ZoneInfo() as zone_info:
26
27
  return zone_info
27
- case ZonedDateTime() as datetime:
28
- return ZoneInfo(datetime.tz)
29
- case "local":
28
+ case ZonedDateTime() as date_time:
29
+ return ZoneInfo(date_time.tz)
30
+ case "local" | "localtime":
30
31
  return LOCAL_TIME_ZONE
31
32
  case str() as key:
32
33
  return ZoneInfo(key)
33
34
  case dt.tzinfo() as tzinfo:
34
35
  if tzinfo is dt.UTC:
35
36
  return UTC
36
- raise _EnsureTimeZoneInvalidTZInfoError(time_zone=obj)
37
- case dt.datetime() as datetime:
38
- if datetime.tzinfo is None:
39
- raise _EnsureTimeZonePlainDateTimeError(datetime=datetime)
40
- return ensure_time_zone(datetime.tzinfo)
41
- case _ as never:
37
+ raise _ToZoneInfoInvalidTZInfoError(time_zone=obj)
38
+ case dt.datetime() as date_time:
39
+ if date_time.tzinfo is None:
40
+ raise _ToZoneInfoPlainDateTimeError(date_time=date_time)
41
+ return to_zone_info(date_time.tzinfo)
42
+ case never:
42
43
  assert_never(never)
43
44
 
44
45
 
45
46
  @dataclass(kw_only=True, slots=True)
46
- class EnsureTimeZoneError(Exception): ...
47
+ class ToTimeZoneError(Exception): ...
47
48
 
48
49
 
49
50
  @dataclass(kw_only=True, slots=True)
50
- class _EnsureTimeZoneInvalidTZInfoError(EnsureTimeZoneError):
51
+ class _ToZoneInfoInvalidTZInfoError(ToTimeZoneError):
51
52
  time_zone: dt.tzinfo
52
53
 
53
54
  @override
54
55
  def __str__(self) -> str:
55
- return f"Unsupported time zone: {self.time_zone}"
56
+ return f"Invalid time-zone: {self.time_zone}"
56
57
 
57
58
 
58
59
  @dataclass(kw_only=True, slots=True)
59
- class _EnsureTimeZonePlainDateTimeError(EnsureTimeZoneError):
60
- datetime: dt.datetime
60
+ class _ToZoneInfoPlainDateTimeError(ToTimeZoneError):
61
+ date_time: dt.datetime
61
62
 
62
63
  @override
63
64
  def __str__(self) -> str:
64
- return f"Plain datetime: {self.datetime}"
65
+ return f"Plain date-time: {self.date_time}"
65
66
 
66
67
 
67
68
  ##
68
69
 
69
70
 
70
- def get_time_zone_name(time_zone: TimeZoneLike, /) -> TimeZone:
71
- """Get the name of a time zone."""
72
- return cast("TimeZone", ensure_time_zone(time_zone).key)
71
+ def to_time_zone_name(obj: TimeZoneLike, /) -> TimeZone:
72
+ """Convert to a time zone name."""
73
+ match obj:
74
+ case ZoneInfo() as zone_info:
75
+ return cast("TimeZone", zone_info.key)
76
+ case ZonedDateTime() as date_time:
77
+ return cast("TimeZone", date_time.tz)
78
+ case "local" | "localtime":
79
+ return LOCAL_TIME_ZONE_NAME
80
+ case str() as time_zone:
81
+ if time_zone in TIME_ZONES:
82
+ return time_zone
83
+ raise _ToTimeZoneNameInvalidKeyError(time_zone=time_zone)
84
+ case dt.tzinfo() as tzinfo:
85
+ if tzinfo is dt.UTC:
86
+ return cast("TimeZone", UTC.key)
87
+ raise _ToTimeZoneNameInvalidTZInfoError(time_zone=obj)
88
+ case dt.datetime() as date_time:
89
+ if date_time.tzinfo is None:
90
+ raise _ToTimeZoneNamePlainDateTimeError(date_time=date_time)
91
+ return to_time_zone_name(date_time.tzinfo)
92
+ case never:
93
+ assert_never(never)
94
+
95
+
96
+ @dataclass(kw_only=True, slots=True)
97
+ class ToTimeZoneNameError(Exception): ...
98
+
99
+
100
+ @dataclass(kw_only=True, slots=True)
101
+ class _ToTimeZoneNameInvalidKeyError(ToTimeZoneNameError):
102
+ time_zone: str
103
+
104
+ @override
105
+ def __str__(self) -> str:
106
+ return f"Invalid time-zone: {self.time_zone!r}"
107
+
108
+
109
+ @dataclass(kw_only=True, slots=True)
110
+ class _ToTimeZoneNameInvalidTZInfoError(ToTimeZoneNameError):
111
+ time_zone: dt.tzinfo
112
+
113
+ @override
114
+ def __str__(self) -> str:
115
+ return f"Invalid time-zone: {self.time_zone}"
116
+
117
+
118
+ @dataclass(kw_only=True, slots=True)
119
+ class _ToTimeZoneNamePlainDateTimeError(ToTimeZoneNameError):
120
+ date_time: dt.datetime
121
+
122
+ @override
123
+ def __str__(self) -> str:
124
+ return f"Plain date-time: {self.date_time}"
73
125
 
74
126
 
75
- __all__ = ["UTC", "EnsureTimeZoneError", "ensure_time_zone", "get_time_zone_name"]
127
+ __all__ = [
128
+ "UTC",
129
+ "ToTimeZoneError",
130
+ "ToTimeZoneNameError",
131
+ "to_time_zone_name",
132
+ "to_zone_info",
133
+ ]
@@ -1,41 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: dycw-utilities
3
- Version: 0.148.4
4
- Author-email: Derek Wan <d.wan@icloud.com>
5
- License-File: LICENSE
6
- Requires-Python: >=3.12
7
- Requires-Dist: atomicwrites<1.5,>=1.4.1
8
- Requires-Dist: typing-extensions<4.15,>=4.14.0
9
- Requires-Dist: tzlocal<5.4,>=5.3.1
10
- Requires-Dist: whenever<0.9,>=0.8.6
11
- Provides-Extra: logging
12
- Requires-Dist: coloredlogs<15.1,>=15.0.1; extra == 'logging'
13
- Provides-Extra: test
14
- Requires-Dist: dycw-pytest-only<2.2,>=2.1.1; extra == 'test'
15
- Requires-Dist: hypothesis<6.136,>=6.135.24; extra == 'test'
16
- Requires-Dist: pudb<2025.2,>=2025.1; extra == 'test'
17
- Requires-Dist: pytest-asyncio<1.2,>=1.1.0; extra == 'test'
18
- Requires-Dist: pytest-cov<6.3,>=6.2.1; extra == 'test'
19
- Requires-Dist: pytest-instafail<0.6,>=0.5.0; extra == 'test'
20
- Requires-Dist: pytest-lazy-fixtures<1.2,>=1.1.4; extra == 'test'
21
- Requires-Dist: pytest-randomly<3.17,>=3.16.0; extra == 'test'
22
- Requires-Dist: pytest-regressions<2.9,>=2.8.1; extra == 'test'
23
- Requires-Dist: pytest-repeat<0.10,>=0.9.4; extra == 'test'
24
- Requires-Dist: pytest-rerunfailures<16,>=15.1; extra == 'test'
25
- Requires-Dist: pytest-rng<1.1,>=1.0.0; extra == 'test'
26
- Requires-Dist: pytest-timeout<2.5,>=2.4.0; extra == 'test'
27
- Requires-Dist: pytest-xdist<3.9,>=3.8.0; extra == 'test'
28
- Requires-Dist: pytest<8.5,>=8.4.1; extra == 'test'
29
- Description-Content-Type: text/markdown
30
-
31
- [![PyPI version](https://badge.fury.io/py/dycw-utilities.svg)](https://badge.fury.io/py/dycw-utilities)
32
-
33
- # `dycw-utilities`
34
-
35
- [All the Python functions I don't want to write twice.](https://github.com/nvim-lua/plenary.nvim)
36
-
37
- ## Installation
38
-
39
- - `pip install dycw-utilities`
40
-
41
- or with [extras](https://github.com/dycw/python-utilities/blob/master/pyproject.toml).
@@ -1,95 +0,0 @@
1
- utilities/__init__.py,sha256=VDgRGy8SY-uljlJ76REYaNomUoE5yqIY42dKSUSpjuY,60
2
- utilities/altair.py,sha256=92E2lCdyHY4Zb-vCw6rEJIsWdKipuu-Tu2ab1ufUfAk,9079
3
- utilities/asyncio.py,sha256=z0w3fb-U5Ml5YXVaFFPClizXaQmjDO6YgZg-V9QL0VQ,16021
4
- utilities/atomicwrites.py,sha256=xcOWenTBRS0oat3kg7Sqe51AohNThMQ2ixPL7QCG8hw,5795
5
- utilities/atools.py,sha256=9im2g8OCf-Iynqa8bAv8N0Ycj9QvrJmGO7yLCZEdgII,986
6
- utilities/cachetools.py,sha256=v1-9sXHLdOLiwmkq6NB0OUbxeKBuVVN6wmAWefWoaHI,2744
7
- utilities/click.py,sha256=AyM__WPPvsIFaZZ5wyVrYvWCdK-mTH1nmlcX0sHDTz8,16668
8
- utilities/concurrent.py,sha256=ZdhcNeBl1-HaAPY3h7bZ5ccuYdfdq2ATHplvZdnzlhk,2858
9
- utilities/contextlib.py,sha256=THWVU14w3kgVM7TSxn2oHqVdBbdeliABR9gRXiPpo2U,7440
10
- utilities/contextvars.py,sha256=RsSGGrbQqqZ67rOydnM7WWIsM2lIE31UHJLejnHJPWY,505
11
- utilities/cryptography.py,sha256=_CiK_K6c_-uQuUhsUNjNjTL-nqxAh4_1zTfS11Xe120,972
12
- utilities/cvxpy.py,sha256=Rv1-fD-XYerosCavRF8Pohop2DBkU3AlFaGTfD8AEAA,13776
13
- utilities/dataclasses.py,sha256=1-REGxtzCo2BbGkjLw5idjbTaiItpOiWvMNbVkJrFXM,32663
14
- utilities/enum.py,sha256=IEPMGiNJBcofGPuoGZErf4bMNSBE4SLs32nvm2r81h0,5791
15
- utilities/errors.py,sha256=k_VvqSi6geTYhlzRRQaGN2j6ZGng-AD8SnX7Znrirm4,1484
16
- utilities/eventkit.py,sha256=s9p3WjGc7h7TdbSgVfHrRNNiuOXcQoVQ5sFCbJyqg48,12646
17
- utilities/fastapi.py,sha256=3wpd63Tw9paSyy7STpAD7GGe8fLkLaRC6TPCwIGm1BU,1361
18
- utilities/fpdf2.py,sha256=776PkEX5xEK-whFOzqaVaQVHPy1Xf01kCSyj7TEp80g,1886
19
- utilities/functions.py,sha256=qefAfW0zz7OEiRuBtKF-3tI3NaufcwAULRIFv24gZ2Q,28533
20
- utilities/functools.py,sha256=I00ru2gQPakZw2SHVeKIKXfTv741655s6HI0lUoE0D4,1552
21
- utilities/getpass.py,sha256=DfN5UgMAtFCqS3dSfFHUfqIMZX2shXvwphOz_6J6f6A,103
22
- utilities/gzip.py,sha256=fkGP3KdsBfXlstodT4wtlp-PwNyUsogpbDCVVVGdsm4,781
23
- utilities/hashlib.py,sha256=SVTgtguur0P4elppvzOBbLEjVM3Pea0eWB61yg2ilxo,309
24
- utilities/http.py,sha256=TsavEfHlRtlLaeV21Z6KZh0qbPw-kvD1zsQdZ7Kep5Q,977
25
- utilities/hypothesis.py,sha256=GisBvkK1qTjNWWJlVZLHrOlws2vDM-92lOtOUqsua4w,38067
26
- utilities/importlib.py,sha256=mV1xT_O_zt_GnZZ36tl3xOmMaN_3jErDWY54fX39F6Y,429
27
- utilities/inflect.py,sha256=UWOsMRJUJXqcR3rgrQmb35mat-Theu5xo-M9E33eTIE,586
28
- utilities/ipython.py,sha256=V2oMYHvEKvlNBzxDXdLvKi48oUq2SclRg5xasjaXStw,763
29
- utilities/iterables.py,sha256=y7ymCCjCrc-RYwwE3xWWKJO_2zn-_pPe_z2ybM5kpkY,43952
30
- utilities/json.py,sha256=DiqnVZbDVmm0fohQCvFYg-B0QPFI02jaN7wmMjntaoQ,2107
31
- utilities/jupyter.py,sha256=ft5JA7fBxXKzP-L9W8f2-wbF0QeYc_2uLQNFDVk4Z-M,2917
32
- utilities/libcst.py,sha256=XTT8cCYAYfI9ZIdxjiTCqbF45cN-viDNDa7GE5mR2T4,5615
33
- utilities/lightweight_charts.py,sha256=YM3ojBvJxuCSUBu_KrhFBmaMCvRPvupKC3qkm-UVZq4,2751
34
- utilities/logging.py,sha256=6Rv6Mt7peHWPZ-wYNUvXQt67QXCOpVXdnkgT88XKiKQ,19416
35
- utilities/math.py,sha256=_6vrDyjtaqE_OFE-F2DNWrDG_J_kMl3nFAJsok9v_bY,26862
36
- utilities/memory_profiler.py,sha256=XzN56jDCa5aqXS_DxEjb_K4L6aIWh_5zyKi6OhcIxw0,853
37
- utilities/modules.py,sha256=iuvLluJya-hvl1Q25-Jk3dLgx2Es3ck4SjJiEkAlVTs,3195
38
- utilities/more_itertools.py,sha256=NEGXDT8COaxziaJFTiXYKX0gffwfKhCAMrq-Kgh0w8c,10937
39
- utilities/numpy.py,sha256=Xn23sA2ZbVNqwUYEgNJD3XBYH6IbCri_WkHSNhg3NkY,26122
40
- utilities/operator.py,sha256=nhxn5q6CFNzUm1wpTwWPCu9JGCqVHSlaJf0o1-efoII,3616
41
- utilities/optuna.py,sha256=C-fhWYiXHVPo1l8QctYkFJ4DyhbSrGorzP1dJb_qvd8,1933
42
- utilities/orjson.py,sha256=iJho5gCkTlT2KWSXqopvi24WCxEhM5_fiz17mbNvkGg,40113
43
- utilities/os.py,sha256=y25oqJoyrkdQ7aU5ShePPXKk6YTwd97x6yEx4UcRYu4,3788
44
- utilities/parse.py,sha256=JcJn5yXKhIWXBCwgBdPsyu7Hvcuw6kyEdqvaebCaI9k,17951
45
- utilities/pathlib.py,sha256=FnteXeVeMOSc6QTN7oF6UrobjOX9gXv_5tG1slg83W8,8496
46
- utilities/period.py,sha256=REuz2xaChNa5Iw69xNnbUPlUSLdUgmhOu4YEOiPeTrg,8328
47
- utilities/pickle.py,sha256=MBT2xZCsv0pH868IXLGKnlcqNx2IRVKYNpRcqiQQqxw,653
48
- utilities/platform.py,sha256=Ue9LSxYvg9yUXGKuz5aZoy_qkUEXde-v6B09exgSctU,2813
49
- utilities/polars.py,sha256=BgiDryAVOapi41ddfJqN0wYh_sDj8BNEYtPB36LaHdo,71824
50
- utilities/polars_ols.py,sha256=Uc9V5kvlWZ5cU93lKZ-cfAKdVFFw81tqwLW9PxtUvMs,5618
51
- utilities/postgres.py,sha256=Q1auvVqwUrIP6yhwvjCXg7zQbWgQ9czuJIa99eK6soM,8993
52
- utilities/pottery.py,sha256=w2X80PXWwzdHdqSYJP6ESrPNNDP3xzpyuJn-fp-Vt3M,5969
53
- utilities/pqdm.py,sha256=BTsYPtbKQWwX-iXF4qCkfPG7DPxIB54J989n83bXrIo,3092
54
- utilities/psutil.py,sha256=KUlu4lrUw9Zg1V7ZGetpWpGb9DB8l_SSDWGbANFNCPU,2104
55
- utilities/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
56
- utilities/pyinstrument.py,sha256=E3U4T6qzTGVcGzAiShl9BL3acO-uu_dHZVgSbkSBd7A,864
57
- utilities/pytest.py,sha256=TUguQEeUiftUWW-aLJEQmZr-J6W2bwpkUt9Y-q2ua14,7904
58
- utilities/pytest_regressions.py,sha256=50h6hqX60U6dkYaB6tW-XEDhSH4y_FQ5LgJ0pGF1Wo4,4102
59
- utilities/random.py,sha256=YWYzWxQDeyJRiuHGnO1OxF6dDucpq7qc1tH_ealwCRg,4130
60
- utilities/re.py,sha256=6qxeV0rQZaBDKWcB7apSBmxtg_XzoGY-EdegTkMn-ZY,4578
61
- utilities/redis.py,sha256=MNxDTbTQTkUOtIikJY9UbfozTC3zuJpAUBsw02LLXTA,28377
62
- utilities/reprlib.py,sha256=ssYTcBW-TeRh3fhCJv57sopTZHF5FrPyyUg9yp5XBlo,3953
63
- utilities/scipy.py,sha256=wZJM7fEgBAkLSYYvSmsg5ac-QuwAI0BGqHVetw1_Hb0,947
64
- utilities/sentinel.py,sha256=3jIwgpMekWgDAxPDA_hXMP2St43cPhciKN3LWiZ7kv0,1248
65
- utilities/shelve.py,sha256=HZsMwK4tcIfg3sh0gApx4-yjQnrY4o3V3ZRimvRhoW0,738
66
- utilities/slack_sdk.py,sha256=ppFBvKgfg5IRWiIoKPtpTyzBtBF4XmwEvU3I5wLJikM,2140
67
- utilities/socket.py,sha256=K77vfREvzoVTrpYKo6MZakol0EYu2q1sWJnnZqL0So0,118
68
- utilities/sqlalchemy.py,sha256=q2aYUDAC3SE88Lt6XaKa3CLzT_ePaWvQu_OuRk19x9g,35520
69
- utilities/sqlalchemy_polars.py,sha256=18AoEbeNJUKF3-5hroNy9J5LQwS_QJAXbMfKc9sChtk,14250
70
- utilities/statsmodels.py,sha256=koyiBHvpMcSiBfh99wFUfSggLNx7cuAw3rwyfAhoKpQ,3410
71
- utilities/string.py,sha256=MB0X6UPTUc06JdAdj-PctZ238IXeCjE5dAJibNw6ZrU,587
72
- utilities/tempfile.py,sha256=VqmZJAhTJ1OaVywFzk5eqROV8iJbW9XQ_QYAV0bpdRo,1384
73
- utilities/text.py,sha256=ymBFlP_cA8OgNnZRVNs7FAh7OG8HxE6YkiLEMZv5g_A,11297
74
- utilities/threading.py,sha256=GvBOp4CyhHfN90wGXZuA2VKe9fGzMaEa7oCl4f3nnPU,1009
75
- utilities/timer.py,sha256=oXfTii6ymu57niP0BDGZjFD55LEHi2a19kqZKiTgaFQ,2588
76
- utilities/traceback.py,sha256=zofhzIedpUHrzDNiRJDVzm_wuu_tlTQvVqK4quxVlgM,9151
77
- utilities/typed_settings.py,sha256=-mzQP5ZCIGWOhm7nPxlajWQhgtX657HVnRCfUYGKQKs,4433
78
- utilities/types.py,sha256=iDfk_Z96v7cIxPlgGYMap0fYmjgRUJ7uQzPPCQe1odY,18115
79
- utilities/typing.py,sha256=Z-_XDaWyT_6wIo3qfNK-hvRlzxP2Jxa9PgXzm5rDYRA,13790
80
- utilities/tzdata.py,sha256=fgNVj66yUbCSI_-vrRVzSD3gtf-L_8IEJEPjP_Jel5Y,266
81
- utilities/tzlocal.py,sha256=KyCXEgCTjqGFx-389JdTuhMRUaT06U1RCMdWoED-qro,728
82
- utilities/uuid.py,sha256=32p7DGHGM2Btx6PcBvCZvERSWbpupMXqx6FppPoSoTU,612
83
- utilities/version.py,sha256=ufhJMmI6KPs1-3wBI71aj5wCukd3sP_m11usLe88DNA,5117
84
- utilities/warnings.py,sha256=un1LvHv70PU-LLv8RxPVmugTzDJkkGXRMZTE2-fTQHw,1771
85
- utilities/whenever.py,sha256=nG9IbFcJTKQJuRxoS35I7ww7pRwKHc1MHxff7vVmJls,44131
86
- utilities/zipfile.py,sha256=24lQc9ATcJxHXBPc_tBDiJk48pWyRrlxO2fIsFxU0A8,699
87
- utilities/zoneinfo.py,sha256=oEH-nL3t4h9uawyZqWDtNtDAl6M-CLpLYGI_nI6DulM,1971
88
- utilities/pytest_plugins/__init__.py,sha256=U4S_2y3zgLZVfMenHRaJFBW8yqh2mUBuI291LGQVOJ8,35
89
- utilities/pytest_plugins/pytest_randomly.py,sha256=NXzCcGKbpgYouz5yehKb4jmxmi2SexKKpgF4M65bi10,414
90
- utilities/pytest_plugins/pytest_regressions.py,sha256=Iwhfv_OJH7UCPZCfoh7ugZ2Xjqjil-BBBsOb8sDwiGI,1471
91
- dycw_utilities-0.148.4.dist-info/METADATA,sha256=VH2ptiCLL6fP3q4XBpXw-0nsTyTeHnHrxpuyT0A5tFE,1697
92
- dycw_utilities-0.148.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
93
- dycw_utilities-0.148.4.dist-info/entry_points.txt,sha256=BOD_SoDxwsfJYOLxhrSXhHP_T7iw-HXI9f2WVkzYxvQ,135
94
- dycw_utilities-0.148.4.dist-info/licenses/LICENSE,sha256=gppZp16M6nSVpBbUBrNL6JuYfvKwZiKgV7XoKKsHzqo,1066
95
- dycw_utilities-0.148.4.dist-info/RECORD,,
@@ -1,4 +0,0 @@
1
- Wheel-Version: 1.0
2
- Generator: hatchling 1.27.0
3
- Root-Is-Purelib: true
4
- Tag: py3-none-any
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2024 Derek Wan
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
utilities/period.py DELETED
@@ -1,237 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from dataclasses import dataclass
4
- from typing import TYPE_CHECKING, Any, Self, TypedDict, overload, override
5
- from zoneinfo import ZoneInfo
6
-
7
- from whenever import Date, DateDelta, PlainDateTime, TimeDelta, ZonedDateTime
8
-
9
- from utilities.dataclasses import replace_non_sentinel
10
- from utilities.functions import get_class_name
11
- from utilities.sentinel import Sentinel, sentinel
12
- from utilities.whenever import format_compact
13
- from utilities.zoneinfo import get_time_zone_name
14
-
15
- if TYPE_CHECKING:
16
- from utilities.types import TimeZoneLike
17
-
18
-
19
- class _PeriodAsDict[T: (Date, ZonedDateTime)](TypedDict):
20
- start: T
21
- end: T
22
-
23
-
24
- @dataclass(repr=False, order=True, unsafe_hash=True, kw_only=False)
25
- class DatePeriod:
26
- """A period of dates."""
27
-
28
- start: Date
29
- end: Date
30
-
31
- def __post_init__(self) -> None:
32
- if self.start > self.end:
33
- raise _PeriodInvalidError(start=self.start, end=self.end)
34
-
35
- def __add__(self, other: DateDelta, /) -> Self:
36
- """Offset the period."""
37
- return self.replace(start=self.start + other, end=self.end + other)
38
-
39
- def __contains__(self, other: Date, /) -> bool:
40
- """Check if a date/datetime lies in the period."""
41
- return self.start <= other <= self.end
42
-
43
- @override
44
- def __repr__(self) -> str:
45
- cls = get_class_name(self)
46
- return f"{cls}({self.start}, {self.end})"
47
-
48
- def __sub__(self, other: DateDelta, /) -> Self:
49
- """Offset the period."""
50
- return self.replace(start=self.start - other, end=self.end - other)
51
-
52
- @property
53
- def delta(self) -> DateDelta:
54
- """The delta of the period."""
55
- return self.end - self.start
56
-
57
- def format_compact(self) -> str:
58
- """Format the period in a compact fashion."""
59
- fc, start, end = format_compact, self.start, self.end
60
- if self.start == self.end:
61
- return f"{fc(start)}="
62
- if self.start.year_month() == self.end.year_month():
63
- return f"{fc(start)}-{fc(end, fmt='%d')}"
64
- if self.start.year == self.end.year:
65
- return f"{fc(start)}-{fc(end, fmt='%m%d')}"
66
- return f"{fc(start)}-{fc(end)}"
67
-
68
- def replace(
69
- self, *, start: Date | Sentinel = sentinel, end: Date | Sentinel = sentinel
70
- ) -> Self:
71
- """Replace elements of the period."""
72
- return replace_non_sentinel(self, start=start, end=end)
73
-
74
- def to_dict(self) -> _PeriodAsDict[Date]:
75
- """Convert the period to a dictionary."""
76
- return _PeriodAsDict(start=self.start, end=self.end)
77
-
78
-
79
- @dataclass(repr=False, order=True, unsafe_hash=True, kw_only=False)
80
- class ZonedDateTimePeriod:
81
- """A period of time."""
82
-
83
- start: ZonedDateTime
84
- end: ZonedDateTime
85
-
86
- def __post_init__(self) -> None:
87
- if self.start > self.end:
88
- raise _PeriodInvalidError(start=self.start, end=self.end)
89
- if self.start.tz != self.end.tz:
90
- raise _PeriodTimeZoneError(
91
- start=ZoneInfo(self.start.tz), end=ZoneInfo(self.end.tz)
92
- )
93
-
94
- def __add__(self, other: TimeDelta, /) -> Self:
95
- """Offset the period."""
96
- return self.replace(start=self.start + other, end=self.end + other)
97
-
98
- def __contains__(self, other: ZonedDateTime, /) -> bool:
99
- """Check if a date/datetime lies in the period."""
100
- return self.start <= other <= self.end
101
-
102
- @override
103
- def __repr__(self) -> str:
104
- cls = get_class_name(self)
105
- return f"{cls}({self.start.to_plain()}, {self.end.to_plain()}[{self.time_zone.key}])"
106
-
107
- def __sub__(self, other: TimeDelta, /) -> Self:
108
- """Offset the period."""
109
- return self.replace(start=self.start - other, end=self.end - other)
110
-
111
- @property
112
- def delta(self) -> TimeDelta:
113
- """The duration of the period."""
114
- return self.end - self.start
115
-
116
- @overload
117
- def exact_eq(self, period: ZonedDateTimePeriod, /) -> bool: ...
118
- @overload
119
- def exact_eq(self, start: ZonedDateTime, end: ZonedDateTime, /) -> bool: ...
120
- @overload
121
- def exact_eq(
122
- self, start: PlainDateTime, end: PlainDateTime, time_zone: ZoneInfo, /
123
- ) -> bool: ...
124
- def exact_eq(self, *args: Any) -> bool:
125
- """Check if a period is exactly equal to another."""
126
- if (len(args) == 1) and isinstance(args[0], ZonedDateTimePeriod):
127
- return self.start.exact_eq(args[0].start) and self.end.exact_eq(args[0].end)
128
- if (
129
- (len(args) == 2)
130
- and isinstance(args[0], ZonedDateTime)
131
- and isinstance(args[1], ZonedDateTime)
132
- ):
133
- return self.exact_eq(ZonedDateTimePeriod(args[0], args[1]))
134
- if (
135
- (len(args) == 3)
136
- and isinstance(args[0], PlainDateTime)
137
- and isinstance(args[1], PlainDateTime)
138
- and isinstance(args[2], ZoneInfo)
139
- ):
140
- return self.exact_eq(
141
- ZonedDateTimePeriod(
142
- args[0].assume_tz(args[2].key), args[1].assume_tz(args[2].key)
143
- )
144
- )
145
- raise _PeriodExactEqArgumentsError(args=args)
146
-
147
- def format_compact(self) -> str:
148
- """Format the period in a compact fashion."""
149
- fc, start, end = format_compact, self.start, self.end
150
- if start == end:
151
- if end.second != 0:
152
- return f"{fc(start)}="
153
- if end.minute != 0:
154
- return f"{fc(start, fmt='%Y%m%dT%H%M')}="
155
- return f"{fc(start, fmt='%Y%m%dT%H')}="
156
- if start.date() == end.date():
157
- if end.second != 0:
158
- return f"{fc(start.to_plain())}-{fc(end, fmt='%H%M%S')}"
159
- if end.minute != 0:
160
- return f"{fc(start.to_plain())}-{fc(end, fmt='%H%M')}"
161
- return f"{fc(start.to_plain())}-{fc(end, fmt='%H')}"
162
- if start.date().year_month() == end.date().year_month():
163
- if end.second != 0:
164
- return f"{fc(start.to_plain())}-{fc(end, fmt='%dT%H%M%S')}"
165
- if end.minute != 0:
166
- return f"{fc(start.to_plain())}-{fc(end, fmt='%dT%H%M')}"
167
- return f"{fc(start.to_plain())}-{fc(end, fmt='%dT%H')}"
168
- if start.year == end.year:
169
- if end.second != 0:
170
- return f"{fc(start.to_plain())}-{fc(end, fmt='%m%dT%H%M%S')}"
171
- if end.minute != 0:
172
- return f"{fc(start.to_plain())}-{fc(end, fmt='%m%dT%H%M')}"
173
- return f"{fc(start.to_plain())}-{fc(end, fmt='%m%dT%H')}"
174
- if end.second != 0:
175
- return f"{fc(start.to_plain())}-{fc(end)}"
176
- if end.minute != 0:
177
- return f"{fc(start.to_plain())}-{fc(end, fmt='%Y%m%dT%H%M')}"
178
- return f"{fc(start.to_plain())}-{fc(end, fmt='%Y%m%dT%H')}"
179
-
180
- def replace(
181
- self,
182
- *,
183
- start: ZonedDateTime | Sentinel = sentinel,
184
- end: ZonedDateTime | Sentinel = sentinel,
185
- ) -> Self:
186
- """Replace elements of the period."""
187
- return replace_non_sentinel(self, start=start, end=end)
188
-
189
- @property
190
- def time_zone(self) -> ZoneInfo:
191
- """The time zone of the period."""
192
- return ZoneInfo(self.start.tz)
193
-
194
- def to_dict(self) -> _PeriodAsDict[ZonedDateTime]:
195
- """Convert the period to a dictionary."""
196
- return _PeriodAsDict(start=self.start, end=self.end)
197
-
198
- def to_tz(self, time_zone: TimeZoneLike, /) -> Self:
199
- """Convert the time zone."""
200
- tz = get_time_zone_name(time_zone)
201
- return self.replace(start=self.start.to_tz(tz), end=self.end.to_tz(tz))
202
-
203
-
204
- @dataclass(kw_only=True, slots=True)
205
- class PeriodError(Exception): ...
206
-
207
-
208
- @dataclass(kw_only=True, slots=True)
209
- class _PeriodInvalidError[T: (Date, ZonedDateTime)](PeriodError):
210
- start: T
211
- end: T
212
-
213
- @override
214
- def __str__(self) -> str:
215
- return f"Invalid period; got {self.start} > {self.end}"
216
-
217
-
218
- @dataclass(kw_only=True, slots=True)
219
- class _PeriodTimeZoneError(PeriodError):
220
- start: ZoneInfo
221
- end: ZoneInfo
222
-
223
- @override
224
- def __str__(self) -> str:
225
- return f"Period must contain exactly one time zone; got {self.start} and {self.end}"
226
-
227
-
228
- @dataclass(kw_only=True, slots=True)
229
- class _PeriodExactEqArgumentsError(PeriodError):
230
- args: tuple[Any, ...]
231
-
232
- @override
233
- def __str__(self) -> str:
234
- return f"Invalid arguments; got {self.args}"
235
-
236
-
237
- __all__ = ["DatePeriod", "PeriodError", "ZonedDateTimePeriod"]