dycw-utilities 0.174.17__py3-none-any.whl → 0.174.19__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.3
2
2
  Name: dycw-utilities
3
- Version: 0.174.17
3
+ Version: 0.174.19
4
4
  Author: Derek Wan
5
5
  Author-email: Derek Wan <d.wan@icloud.com>
6
6
  Requires-Dist: atomicwrites>=1.4.1,<1.5
@@ -1,4 +1,4 @@
1
- utilities/__init__.py,sha256=kcADuh_nb8xfuYrat4AkfaKqdxp3l7xyrXWoJJ5JZLk,61
1
+ utilities/__init__.py,sha256=nyJKpGIkfnetD4-kNA4ZJixn2uq8SdQrflZtDYf_k2Q,61
2
2
  utilities/aeventkit.py,sha256=OmDBhYGgbsKrB7cdC5FFpJHUatX9O76eTeKVVTksp2Y,12673
3
3
  utilities/altair.py,sha256=rUK99g9x6CYDDfiZrf-aTx5fSRbL1Q8ctgKORowzXHg,9060
4
4
  utilities/asyncio.py,sha256=aJySVxBY0gqsIYnoNmH7-1r8djKuf4vSsU69VCD08t8,16772
@@ -12,7 +12,7 @@ utilities/contextvars.py,sha256=J8OhC7jqozAGYOCe2KUWysbPXNGe5JYz3HfaY_mIs08,883
12
12
  utilities/cryptography.py,sha256=5PFrzsNUGHay91dFgYnDKwYprXxahrBqztmUqViRzBk,956
13
13
  utilities/cvxpy.py,sha256=Rv1-fD-XYerosCavRF8Pohop2DBkU3AlFaGTfD8AEAA,13776
14
14
  utilities/dataclasses.py,sha256=xbU3QN1GFy7RC6hIJRZIeUZm7YRlodrgEWmahWG6k2g,32465
15
- utilities/docker.py,sha256=l_R9Eyhc-_JbkkaYXYKGZ0PZ_oukrSj8aKtD1NyAhMM,7879
15
+ utilities/docker.py,sha256=N__PKd3cnSRsXNEMHMLdLneLdyzfbr2ESkElcwrovvQ,7940
16
16
  utilities/enum.py,sha256=5l6pwZD1cjSlVW4ss-zBPspWvrbrYrdtJWcg6f5_J5w,5781
17
17
  utilities/errors.py,sha256=mFlDGSM0LI1jZ1pbqwLAH3ttLZ2JVIxyZLojw8tGVZU,1479
18
18
  utilities/fastapi.py,sha256=TqyKvBjiMS594sXPjrz-KRTLMb3l3D3rZ1zAYV7GfOk,1454
@@ -49,8 +49,8 @@ utilities/parse.py,sha256=g7Qm9eBOIeDId2tGA021CIaeF6jp1TI8rx4srdvlyoo,17937
49
49
  utilities/pathlib.py,sha256=N4Ip8R9eCM-6GfvxUJ3T9oQIle2C2P52F-13BCFRdTg,9345
50
50
  utilities/permissions.py,sha256=vLXlWztSVYffbrxptne7ksj6dU1HLekm4fEvS4ny_4Q,8944
51
51
  utilities/pickle.py,sha256=MBT2xZCsv0pH868IXLGKnlcqNx2IRVKYNpRcqiQQqxw,653
52
- utilities/platform.py,sha256=Grov52WxNOViJEZyRcm-b2m_Dp1T0waPjDCusR_9oqs,2791
53
- utilities/polars.py,sha256=cNFBLWgOMUAp_Sz4xtlto17uZswZRrcfQYC95QKyaY4,87483
52
+ utilities/platform.py,sha256=R3ldt2-DlI7la9ng6Rxt1CThd2lL0Ai2tC0TbabtCC0,2800
53
+ utilities/polars.py,sha256=JPzN4UqQDC7R4IXsIuXEIXRiwHSrkiSZcD8UOfwGPuE,87535
54
54
  utilities/polars_ols.py,sha256=LNTFNLPuYW7fcAHymlbnams_DhitToblYvib3mhKbwI,5615
55
55
  utilities/postgres.py,sha256=g3tEwTI8TdmiCbRME61ffQ0xaibdpXPu8mJOOHvjPKc,12532
56
56
  utilities/pottery.py,sha256=nA0SsF9irvfC0tk68YAr08tuL9lGRSlBKihSx7Ibk84,3963
@@ -81,7 +81,7 @@ utilities/sqlalchemy.py,sha256=HQYpd7LFxdTF5WYVWYtCJeEBI71EJm7ytvCGyAH9B-U,37163
81
81
  utilities/sqlalchemy_polars.py,sha256=JCGhB37raSR7fqeWV5dTsciRTMVzIdVT9YSqKT0piT0,13370
82
82
  utilities/statsmodels.py,sha256=koyiBHvpMcSiBfh99wFUfSggLNx7cuAw3rwyfAhoKpQ,3410
83
83
  utilities/string.py,sha256=shmBK87zZwzGyixuNuXCiUbqzfeZ9xlrFwz6JTaRvDk,582
84
- utilities/subprocess.py,sha256=FzVd1evvhaJR2U_tATJ37Y6YjF8O61XPeqYo8NLonG4,33123
84
+ utilities/subprocess.py,sha256=7GEv6T9F7z9nacPymzOUUAF6r6ChPjGgKlL64Zrh-AU,34909
85
85
  utilities/tempfile.py,sha256=Lx6qa16lL1XVH6WdmD_G9vlN6gLI8nrIurxmsFkPKvg,3022
86
86
  utilities/testbook.py,sha256=j1KmaVbrX9VrbeMgtPh5gk55myAsn3dyRUn7jGbPbRk,1294
87
87
  utilities/text.py,sha256=7SvwcSR2l_5cOrm1samGnR4C-ZI6qyFLHLzSpO1zeHQ,13958
@@ -98,7 +98,7 @@ utilities/warnings.py,sha256=un1LvHv70PU-LLv8RxPVmugTzDJkkGXRMZTE2-fTQHw,1771
98
98
  utilities/whenever.py,sha256=F4ek0-OBWxHYrZdmoZt76N2RnNyKY5KrEHt7rqO4AQE,60183
99
99
  utilities/zipfile.py,sha256=24lQc9ATcJxHXBPc_tBDiJk48pWyRrlxO2fIsFxU0A8,699
100
100
  utilities/zoneinfo.py,sha256=tdIScrTB2-B-LH0ukb1HUXKooLknOfJNwHk10MuMYvA,3619
101
- dycw_utilities-0.174.17.dist-info/WHEEL,sha256=RRVLqVugUmFOqBedBFAmA4bsgFcROUBiSUKlERi0Hcg,79
102
- dycw_utilities-0.174.17.dist-info/entry_points.txt,sha256=ykGI1ArwOPHqm2g5Cqh3ENdMxEej_a_FcOUov5EM5Oc,155
103
- dycw_utilities-0.174.17.dist-info/METADATA,sha256=vF_qKrCXt5r90r7OjWFLitGHfDgcAcVUDj6Y47YMvEQ,1710
104
- dycw_utilities-0.174.17.dist-info/RECORD,,
101
+ dycw_utilities-0.174.19.dist-info/WHEEL,sha256=RRVLqVugUmFOqBedBFAmA4bsgFcROUBiSUKlERi0Hcg,79
102
+ dycw_utilities-0.174.19.dist-info/entry_points.txt,sha256=ykGI1ArwOPHqm2g5Cqh3ENdMxEej_a_FcOUov5EM5Oc,155
103
+ dycw_utilities-0.174.19.dist-info/METADATA,sha256=g_N5AxOBCGnPuLyOGvWEVdKj0mdu7pSyW2R6FBaPCmE,1710
104
+ dycw_utilities-0.174.19.dist-info/RECORD,,
utilities/__init__.py CHANGED
@@ -1,3 +1,3 @@
1
1
  from __future__ import annotations
2
2
 
3
- __version__ = "0.174.17"
3
+ __version__ = "0.174.19"
utilities/docker.py CHANGED
@@ -269,6 +269,7 @@ def yield_docker_temp_dir(
269
269
  logger: LoggerLike | None = None,
270
270
  keep: bool = False,
271
271
  ) -> Iterator[Path]:
272
+ """Yield a temporary directory in a Docker container."""
272
273
  path = Path( # skipif-ci
273
274
  docker_exec(
274
275
  container,
utilities/platform.py CHANGED
@@ -16,7 +16,7 @@ System = Literal["windows", "mac", "linux"]
16
16
  def get_system() -> System:
17
17
  """Get the system/OS name."""
18
18
  sys = system()
19
- if sys == "Windows": # skipif-ci
19
+ if sys == "Windows": # skipif-not-windows
20
20
  return "windows"
21
21
  if sys == "Darwin": # skipif-not-macos
22
22
  return "mac"
utilities/polars.py CHANGED
@@ -2639,6 +2639,8 @@ def search_period(
2639
2639
  return None
2640
2640
  item: dt.datetime = series[index]["start"]
2641
2641
  return index if py_date_time > item else None
2642
+ case never:
2643
+ assert_never(never)
2642
2644
 
2643
2645
 
2644
2646
  ##
utilities/subprocess.py CHANGED
@@ -40,6 +40,7 @@ _HOST_KEY_ALGORITHMS = ["ssh-ed25519"]
40
40
  APT_UPDATE = ["apt", "update", "-y"]
41
41
  BASH_LC = ["bash", "-lc"]
42
42
  BASH_LS = ["bash", "-ls"]
43
+ GIT_BRANCH_SHOW_CURRENT = ["git", "branch", "--show-current"]
43
44
  MKTEMP_DIR_CMD = ["mktemp", "-d"]
44
45
  RESTART_SSHD = ["systemctl", "restart", "sshd"]
45
46
  UPDATE_CA_CERTIFICATES: str = "update-ca-certificates"
@@ -221,6 +222,37 @@ def expand_path(
221
222
  ##
222
223
 
223
224
 
225
+ def git_branch_current(path: PathLike, /) -> str:
226
+ """Show the current a branch."""
227
+ return run(*GIT_BRANCH_SHOW_CURRENT, cwd=path, return_=True)
228
+
229
+
230
+ ##
231
+
232
+
233
+ def git_checkout(branch: str, path: PathLike, /) -> None:
234
+ """Switch a branch."""
235
+ run(*git_checkout_cmd(branch), cwd=path)
236
+
237
+
238
+ def git_checkout_cmd(branch: str, /) -> list[str]:
239
+ """Command to use 'git checkout' to switch a branch."""
240
+ return ["git", "checkout", branch]
241
+
242
+
243
+ ##
244
+
245
+
246
+ def git_clone(
247
+ url: str, path: PathLike, /, *, sudo: bool = False, branch: str | None = None
248
+ ) -> None:
249
+ """Clone a repository."""
250
+ rm(path, sudo=sudo)
251
+ run(*maybe_sudo_cmd(*git_clone_cmd(url, path), sudo=sudo))
252
+ if branch is not None:
253
+ run(*maybe_sudo_cmd(*git_hard_reset_cmd(branch=branch), sudo=sudo), cwd=path)
254
+
255
+
224
256
  def git_clone_cmd(url: str, path: PathLike, /) -> list[str]:
225
257
  """Command to use 'git clone' to clone a repository."""
226
258
  return ["git", "clone", "--recurse-submodules", url, str(path)]
@@ -1089,14 +1121,26 @@ def tee_cmd(path: PathLike, /, *, append: bool = False) -> list[str]:
1089
1121
  ##
1090
1122
 
1091
1123
 
1124
+ def touch(path: PathLike, /, *, sudo: bool = False) -> None:
1125
+ """Change file access and modification times."""
1126
+ run(*maybe_sudo_cmd(*touch_cmd(path), sudo=sudo))
1127
+
1128
+
1092
1129
  def touch_cmd(path: PathLike, /) -> list[str]:
1130
+ """Command to use 'touch' to change file access and modification times."""
1093
1131
  return ["touch", str(path)]
1094
1132
 
1095
1133
 
1096
1134
  ##
1097
1135
 
1098
1136
 
1137
+ def uv_run(module: str, /, *args: str) -> None:
1138
+ """Run a command or script."""
1139
+ run(*uv_run_cmd(module, *args)) # pragma: no cover
1140
+
1141
+
1099
1142
  def uv_run_cmd(module: str, /, *args: str) -> list[str]:
1143
+ """Command to use 'uv' to run a command or script."""
1100
1144
  return [
1101
1145
  "uv",
1102
1146
  "run",
@@ -1114,6 +1158,17 @@ def uv_run_cmd(module: str, /, *args: str) -> list[str]:
1114
1158
  ##
1115
1159
 
1116
1160
 
1161
+ @contextmanager
1162
+ def yield_git_repo(url: str, /, *, branch: str | None = None) -> Iterator[Path]:
1163
+ """Yield a temporary git repository."""
1164
+ with TemporaryDirectory() as temp_dir:
1165
+ git_clone(url, temp_dir, branch=branch)
1166
+ yield temp_dir
1167
+
1168
+
1169
+ ##
1170
+
1171
+
1117
1172
  @contextmanager
1118
1173
  def yield_ssh_temp_dir(
1119
1174
  user: str,
@@ -1124,6 +1179,7 @@ def yield_ssh_temp_dir(
1124
1179
  logger: LoggerLike | None = None,
1125
1180
  keep: bool = False,
1126
1181
  ) -> Iterator[Path]:
1182
+ """Yield a temporary directory on a remote machine."""
1127
1183
  path = Path( # skipif-ci
1128
1184
  ssh(user, hostname, *MKTEMP_DIR_CMD, return_=True, retry=retry, logger=logger)
1129
1185
  )
@@ -1141,6 +1197,7 @@ __all__ = [
1141
1197
  "APT_UPDATE",
1142
1198
  "BASH_LC",
1143
1199
  "BASH_LS",
1200
+ "GIT_BRANCH_SHOW_CURRENT",
1144
1201
  "MKTEMP_DIR_CMD",
1145
1202
  "RESTART_SSHD",
1146
1203
  "UPDATE_CA_CERTIFICATES",
@@ -1160,6 +1217,10 @@ __all__ = [
1160
1217
  "cp_cmd",
1161
1218
  "echo_cmd",
1162
1219
  "expand_path",
1220
+ "git_branch_current",
1221
+ "git_checkout",
1222
+ "git_checkout_cmd",
1223
+ "git_clone",
1163
1224
  "git_clone_cmd",
1164
1225
  "git_hard_reset_cmd",
1165
1226
  "maybe_parent",
@@ -1183,7 +1244,10 @@ __all__ = [
1183
1244
  "symlink",
1184
1245
  "symlink_cmd",
1185
1246
  "tee_cmd",
1247
+ "touch",
1186
1248
  "touch_cmd",
1249
+ "uv_run",
1187
1250
  "uv_run_cmd",
1251
+ "yield_git_repo",
1188
1252
  "yield_ssh_temp_dir",
1189
1253
  ]