dycw-utilities 0.174.18__py3-none-any.whl → 0.174.20__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.18
3
+ Version: 0.174.20
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=2xupJL_-0RN3mhQDSD7NIAJegYc_Pr3NKdbT8LPHrvI,61
1
+ utilities/__init__.py,sha256=SXnJCLALsdKuftonx3Xk6nl9lsUbY1lII9DJii26lms,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
@@ -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=q0k-Fl8iRKX9UvqtNgshUcrv-tAEzJbeyoQWiWEdql8,34298
84
+ utilities/subprocess.py,sha256=f8amdrbh48Y_3ETcIU_vthKMqAi7ehq3xmwMbAcldc8,34875
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.18.dist-info/WHEEL,sha256=RRVLqVugUmFOqBedBFAmA4bsgFcROUBiSUKlERi0Hcg,79
102
- dycw_utilities-0.174.18.dist-info/entry_points.txt,sha256=ykGI1ArwOPHqm2g5Cqh3ENdMxEej_a_FcOUov5EM5Oc,155
103
- dycw_utilities-0.174.18.dist-info/METADATA,sha256=lsjOEHDTftfTew-cUGjw81uggqGrWLEXHVN3snWSV80,1710
104
- dycw_utilities-0.174.18.dist-info/RECORD,,
101
+ dycw_utilities-0.174.20.dist-info/WHEEL,sha256=RRVLqVugUmFOqBedBFAmA4bsgFcROUBiSUKlERi0Hcg,79
102
+ dycw_utilities-0.174.20.dist-info/entry_points.txt,sha256=ykGI1ArwOPHqm2g5Cqh3ENdMxEej_a_FcOUov5EM5Oc,155
103
+ dycw_utilities-0.174.20.dist-info/METADATA,sha256=j2YRKAirmAe5WDN_hR-Nm9lV3oHLNWg_42bMAAPUTqE,1710
104
+ dycw_utilities-0.174.20.dist-info/RECORD,,
utilities/__init__.py CHANGED
@@ -1,3 +1,3 @@
1
1
  from __future__ import annotations
2
2
 
3
- __version__ = "0.174.18"
3
+ __version__ = "0.174.20"
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"
@@ -48,6 +49,13 @@ UPDATE_CA_CERTIFICATES: str = "update-ca-certificates"
48
49
  ##
49
50
 
50
51
 
52
+ def apt_install(package: str, /, *, update: bool = False, sudo: bool = False) -> None:
53
+ """Install a package."""
54
+ if update: # pragma: no cover
55
+ run(*maybe_sudo_cmd(*APT_UPDATE, sudo=sudo))
56
+ run(*maybe_sudo_cmd(*apt_install_cmd(package), sudo=sudo))
57
+
58
+
51
59
  def apt_install_cmd(package: str, /) -> list[str]:
52
60
  """Command to use 'apt' to install a package."""
53
61
  return ["apt", "install", "-y", package]
@@ -221,6 +229,27 @@ def expand_path(
221
229
  ##
222
230
 
223
231
 
232
+ def git_branch_current(path: PathLike, /) -> str:
233
+ """Show the current a branch."""
234
+ return run(*GIT_BRANCH_SHOW_CURRENT, cwd=path, return_=True)
235
+
236
+
237
+ ##
238
+
239
+
240
+ def git_checkout(branch: str, path: PathLike, /) -> None:
241
+ """Switch a branch."""
242
+ run(*git_checkout_cmd(branch), cwd=path)
243
+
244
+
245
+ def git_checkout_cmd(branch: str, /) -> list[str]:
246
+ """Command to use 'git checkout' to switch a branch."""
247
+ return ["git", "checkout", branch]
248
+
249
+
250
+ ##
251
+
252
+
224
253
  def git_clone(
225
254
  url: str, path: PathLike, /, *, sudo: bool = False, branch: str | None = None
226
255
  ) -> None:
@@ -228,7 +257,7 @@ def git_clone(
228
257
  rm(path, sudo=sudo)
229
258
  run(*maybe_sudo_cmd(*git_clone_cmd(url, path), sudo=sudo))
230
259
  if branch is not None:
231
- run(*maybe_sudo_cmd(*git_hard_reset_cmd(branch=branch), sudo=sudo), cwd=path)
260
+ git_checkout(branch, path)
232
261
 
233
262
 
234
263
  def git_clone_cmd(url: str, path: PathLike, /) -> list[str]:
@@ -239,15 +268,6 @@ def git_clone_cmd(url: str, path: PathLike, /) -> list[str]:
239
268
  ##
240
269
 
241
270
 
242
- def git_hard_reset_cmd(*, branch: str | None = None) -> list[str]:
243
- """Command to use 'git hard-reset' to hard reset a repository."""
244
- branch_use = "master" if branch is None else branch
245
- return ["git", "hard-reset", branch_use]
246
-
247
-
248
- ##
249
-
250
-
251
271
  def maybe_parent(path: PathLike, /, *, parent: bool = False) -> Path:
252
272
  """Get the parent of a path, if required."""
253
273
  path = Path(path)
@@ -1175,6 +1195,7 @@ __all__ = [
1175
1195
  "APT_UPDATE",
1176
1196
  "BASH_LC",
1177
1197
  "BASH_LS",
1198
+ "GIT_BRANCH_SHOW_CURRENT",
1178
1199
  "MKTEMP_DIR_CMD",
1179
1200
  "RESTART_SSHD",
1180
1201
  "UPDATE_CA_CERTIFICATES",
@@ -1184,6 +1205,7 @@ __all__ = [
1184
1205
  "RsyncCmdError",
1185
1206
  "RsyncCmdNoSourcesError",
1186
1207
  "RsyncCmdSourcesNotFoundError",
1208
+ "apt_install",
1187
1209
  "apt_install_cmd",
1188
1210
  "cd_cmd",
1189
1211
  "chmod",
@@ -1194,9 +1216,11 @@ __all__ = [
1194
1216
  "cp_cmd",
1195
1217
  "echo_cmd",
1196
1218
  "expand_path",
1219
+ "git_branch_current",
1220
+ "git_checkout",
1221
+ "git_checkout_cmd",
1197
1222
  "git_clone",
1198
1223
  "git_clone_cmd",
1199
- "git_hard_reset_cmd",
1200
1224
  "maybe_parent",
1201
1225
  "maybe_sudo_cmd",
1202
1226
  "mkdir",