dycw-utilities 0.175.27__py3-none-any.whl → 0.175.29__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.175.27
3
+ Version: 0.175.29
4
4
  Summary: Miscellaneous Python utilities
5
5
  Author: Derek Wan
6
6
  Author-email: Derek Wan <d.wan@icloud.com>
@@ -1,4 +1,4 @@
1
- utilities/__init__.py,sha256=IhEmMfmycJdR031fNLaK1iuiv3mg9N-cQcLonJln-q4,61
1
+ utilities/__init__.py,sha256=4Vn2mZMxPdI4pPiLLbxz37PzGsyw0oipRMmAdN102Fw,61
2
2
  utilities/altair.py,sha256=TLfRFbG9HwG7SLXoJ-v0r-t49ZaGgTQZD82cpjVi4vs,9085
3
3
  utilities/asyncio.py,sha256=aJySVxBY0gqsIYnoNmH7-1r8djKuf4vSsU69VCD08t8,16772
4
4
  utilities/atomicwrites.py,sha256=tPo6r-Rypd9u99u66B9z86YBPpnLrlHtwox_8Z7T34Y,5790
@@ -80,7 +80,7 @@ utilities/sqlalchemy.py,sha256=HQYpd7LFxdTF5WYVWYtCJeEBI71EJm7ytvCGyAH9B-U,37163
80
80
  utilities/sqlalchemy_polars.py,sha256=JCGhB37raSR7fqeWV5dTsciRTMVzIdVT9YSqKT0piT0,13370
81
81
  utilities/statsmodels.py,sha256=koyiBHvpMcSiBfh99wFUfSggLNx7cuAw3rwyfAhoKpQ,3410
82
82
  utilities/string.py,sha256=shmBK87zZwzGyixuNuXCiUbqzfeZ9xlrFwz6JTaRvDk,582
83
- utilities/subprocess.py,sha256=RRDh212OgVj07cidE8SgyOvyaRfR9BFKyw48X_sIqhU,51182
83
+ utilities/subprocess.py,sha256=InHiFN318S46vHtqgSPbC0zL2UACjxm4Y9oCLiTXTQo,52937
84
84
  utilities/tempfile.py,sha256=a3_M1QyxGZql_VcGkBOQBeWbbkItjgkfIpVyzU1UAic,3843
85
85
  utilities/testbook.py,sha256=j1KmaVbrX9VrbeMgtPh5gk55myAsn3dyRUn7jGbPbRk,1294
86
86
  utilities/text.py,sha256=7SvwcSR2l_5cOrm1samGnR4C-ZI6qyFLHLzSpO1zeHQ,13958
@@ -97,7 +97,7 @@ utilities/warnings.py,sha256=un1LvHv70PU-LLv8RxPVmugTzDJkkGXRMZTE2-fTQHw,1771
97
97
  utilities/whenever.py,sha256=F4ek0-OBWxHYrZdmoZt76N2RnNyKY5KrEHt7rqO4AQE,60183
98
98
  utilities/zipfile.py,sha256=24lQc9ATcJxHXBPc_tBDiJk48pWyRrlxO2fIsFxU0A8,699
99
99
  utilities/zoneinfo.py,sha256=tdIScrTB2-B-LH0ukb1HUXKooLknOfJNwHk10MuMYvA,3619
100
- dycw_utilities-0.175.27.dist-info/WHEEL,sha256=RRVLqVugUmFOqBedBFAmA4bsgFcROUBiSUKlERi0Hcg,79
101
- dycw_utilities-0.175.27.dist-info/entry_points.txt,sha256=cOGtKeJI0KXLSV7MJ8Dhc2G8jPgDcBDm53MVNJU4ycI,136
102
- dycw_utilities-0.175.27.dist-info/METADATA,sha256=_bP-SZHDjfjAq8A7eJxwN3gt0WHcfNSeifg3u5JWqUU,1443
103
- dycw_utilities-0.175.27.dist-info/RECORD,,
100
+ dycw_utilities-0.175.29.dist-info/WHEEL,sha256=RRVLqVugUmFOqBedBFAmA4bsgFcROUBiSUKlERi0Hcg,79
101
+ dycw_utilities-0.175.29.dist-info/entry_points.txt,sha256=cOGtKeJI0KXLSV7MJ8Dhc2G8jPgDcBDm53MVNJU4ycI,136
102
+ dycw_utilities-0.175.29.dist-info/METADATA,sha256=JKE9YzvVLkTKQHdvaHCMrMs2NO1_pRPSxtqh8c5mizY,1443
103
+ dycw_utilities-0.175.29.dist-info/RECORD,,
utilities/__init__.py CHANGED
@@ -1,3 +1,3 @@
1
1
  from __future__ import annotations
2
2
 
3
- __version__ = "0.175.27"
3
+ __version__ = "0.175.29"
utilities/subprocess.py CHANGED
@@ -146,6 +146,29 @@ def cd_cmd(path: PathLike, /) -> list[str]:
146
146
  ##
147
147
 
148
148
 
149
+ def chattr(
150
+ path: PathLike, /, *, immutable: bool | None = None, sudo: bool = False
151
+ ) -> None:
152
+ """Change file attributes."""
153
+ args = maybe_sudo_cmd( # pragma: no cover
154
+ *chattr_cmd(path, immutable=immutable), sudo=sudo
155
+ )
156
+ run(*args) # pragma: no cover
157
+
158
+
159
+ def chattr_cmd(path: PathLike, /, *, immutable: bool | None = None) -> list[str]:
160
+ """Command to use 'chattr' to change file attributes."""
161
+ args: list[str] = ["chattr"]
162
+ if immutable is True:
163
+ args.append("+i")
164
+ elif immutable is False:
165
+ args.append("-i")
166
+ return [*args, str(path)]
167
+
168
+
169
+ ##
170
+
171
+
149
172
  def chmod(path: PathLike, perms: PermissionsLike, /, *, sudo: bool = False) -> None:
150
173
  """Change file mode."""
151
174
  if sudo: # pragma: no cover
@@ -421,8 +444,8 @@ def curl(
421
444
  logger: LoggerLike | None = None,
422
445
  ) -> str | None:
423
446
  """Transfer a URL."""
424
- args = maybe_sudo_cmd(
425
- *curl_cmd( # skipif-ci
447
+ args = maybe_sudo_cmd( # skipif-ci
448
+ *curl_cmd(
426
449
  url,
427
450
  fail=fail,
428
451
  location=location,
@@ -542,6 +565,53 @@ def git_clone_cmd(url: str, path: PathLike, /) -> list[str]:
542
565
  ##
543
566
 
544
567
 
568
+ def install(
569
+ path: PathLike,
570
+ /,
571
+ *,
572
+ directory: bool = False,
573
+ mode: PermissionsLike | None = None,
574
+ owner: str | int | None = None,
575
+ group: str | int | None = None,
576
+ sudo: bool = False,
577
+ ) -> None:
578
+ """Install a binary."""
579
+ args = maybe_sudo_cmd(
580
+ *install_cmd(path, directory=directory, mode=mode, owner=owner, group=group),
581
+ sudo=sudo,
582
+ )
583
+ run(*args)
584
+
585
+
586
+ def install_cmd(
587
+ path: PathLike,
588
+ /,
589
+ *,
590
+ directory: bool = False,
591
+ mode: PermissionsLike | None = None,
592
+ owner: str | int | None = None,
593
+ group: str | int | None = None,
594
+ ) -> list[str]:
595
+ """Command to use 'install' to install a binary."""
596
+ args: list[str] = ["install"]
597
+ if directory:
598
+ args.append("-d")
599
+ if mode is not None:
600
+ args.extend(["-m", str(ensure_perms(mode))])
601
+ if owner is not None:
602
+ args.extend(["-o", str(owner)])
603
+ if group is not None:
604
+ args.extend(["-g", str(group)])
605
+ if directory:
606
+ args.append(str(path))
607
+ else:
608
+ args.extend(["/dev/null", str(path)])
609
+ return args
610
+
611
+
612
+ ##
613
+
614
+
545
615
  def maybe_parent(path: PathLike, /, *, parent: bool = False) -> Path:
546
616
  """Get the parent of a path, if required."""
547
617
  path = Path(path)
@@ -1813,6 +1883,8 @@ __all__ = [
1813
1883
  "apt_update",
1814
1884
  "cat",
1815
1885
  "cd_cmd",
1886
+ "chattr",
1887
+ "chattr_cmd",
1816
1888
  "chmod",
1817
1889
  "chmod_cmd",
1818
1890
  "chown",
@@ -1831,6 +1903,8 @@ __all__ = [
1831
1903
  "git_checkout_cmd",
1832
1904
  "git_clone",
1833
1905
  "git_clone_cmd",
1906
+ "install",
1907
+ "install_cmd",
1834
1908
  "maybe_parent",
1835
1909
  "maybe_sudo_cmd",
1836
1910
  "mkdir",