dycw-utilities 0.129.9__py3-none-any.whl → 0.129.10__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.4
2
2
  Name: dycw-utilities
3
- Version: 0.129.9
3
+ Version: 0.129.10
4
4
  Author-email: Derek Wan <d.wan@icloud.com>
5
5
  License-File: LICENSE
6
6
  Requires-Python: >=3.12
@@ -1,4 +1,4 @@
1
- utilities/__init__.py,sha256=uFYFepkZNArEi_sHiw7tlOn88WgLGjxnMihyD4GzfOQ,60
1
+ utilities/__init__.py,sha256=Ea2sLI04_oNAg8JArocs5IF0T0dgZO_dvaFh04klnq8,61
2
2
  utilities/altair.py,sha256=Gpja-flOo-Db0PIPJLJsgzAlXWoKUjPU1qY-DQ829ek,9156
3
3
  utilities/asyncio.py,sha256=3n5EIcSq2xtEF1i4oR0oY2JmBq3NyugeHKFK39Mt22s,37987
4
4
  utilities/atomicwrites.py,sha256=geFjn9Pwn-tTrtoGjDDxWli9NqbYfy3gGL6ZBctiqSo,5393
@@ -20,6 +20,7 @@ utilities/fpdf2.py,sha256=y1NGXR5chWqLXWpewGV3hlRGMr_5yV1lVRkPBhPEgJI,1843
20
20
  utilities/functions.py,sha256=jgt592voaHNtX56qX0SRvFveVCRmSIxCZmqvpLZCnY8,27305
21
21
  utilities/functools.py,sha256=WrpHt7NLNWSUn9A1Q_ZIWlNaYZOEI4IFKyBG9HO3BC4,1643
22
22
  utilities/getpass.py,sha256=DfN5UgMAtFCqS3dSfFHUfqIMZX2shXvwphOz_6J6f6A,103
23
+ utilities/git.py,sha256=oi7-_l5e9haSANSCvQw25ufYGoNahuUPHAZ6114s3JQ,1191
23
24
  utilities/hashlib.py,sha256=SVTgtguur0P4elppvzOBbLEjVM3Pea0eWB61yg2ilxo,309
24
25
  utilities/http.py,sha256=WcahTcKYRtZ04WXQoWt5EGCgFPcyHD3EJdlMfxvDt-0,946
25
26
  utilities/hypothesis.py,sha256=UnUMJmeqwJuK7uyUqw_i3opUYzVKud4RMG0RMOSRBQY,44463
@@ -89,7 +90,7 @@ utilities/warnings.py,sha256=un1LvHv70PU-LLv8RxPVmugTzDJkkGXRMZTE2-fTQHw,1771
89
90
  utilities/whenever.py,sha256=QbXgFAPuUL7PCp2hajmIP-FFIfIR1J6Y0TxJbeoj60I,18434
90
91
  utilities/zipfile.py,sha256=24lQc9ATcJxHXBPc_tBDiJk48pWyRrlxO2fIsFxU0A8,699
91
92
  utilities/zoneinfo.py,sha256=-5j7IQ9nb7gR43rdgA7ms05im-XuqhAk9EJnQBXxCoQ,1874
92
- dycw_utilities-0.129.9.dist-info/METADATA,sha256=c0KdCG0ORHKUnqbJ4eaGnDoZNUDbRtkjupd_8Oqg22c,12723
93
- dycw_utilities-0.129.9.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
94
- dycw_utilities-0.129.9.dist-info/licenses/LICENSE,sha256=gppZp16M6nSVpBbUBrNL6JuYfvKwZiKgV7XoKKsHzqo,1066
95
- dycw_utilities-0.129.9.dist-info/RECORD,,
93
+ dycw_utilities-0.129.10.dist-info/METADATA,sha256=w9VpvO8zhmLUxyrwfut-D_8nzKJc4mlol7xp_Li98G4,12724
94
+ dycw_utilities-0.129.10.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
95
+ dycw_utilities-0.129.10.dist-info/licenses/LICENSE,sha256=gppZp16M6nSVpBbUBrNL6JuYfvKwZiKgV7XoKKsHzqo,1066
96
+ dycw_utilities-0.129.10.dist-info/RECORD,,
utilities/__init__.py CHANGED
@@ -1,3 +1,3 @@
1
1
  from __future__ import annotations
2
2
 
3
- __version__ = "0.129.9"
3
+ __version__ = "0.129.10"
utilities/git.py ADDED
@@ -0,0 +1,40 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass
4
+ from pathlib import Path
5
+ from re import IGNORECASE, search
6
+ from subprocess import PIPE, CalledProcessError, check_output
7
+ from typing import TYPE_CHECKING, override
8
+
9
+ from utilities.pathlib import PWD
10
+
11
+ if TYPE_CHECKING:
12
+ from utilities.types import PathLike
13
+
14
+
15
+ def get_repo_root(*, path: PathLike = PWD) -> Path:
16
+ """Get the repo root."""
17
+ try:
18
+ output = check_output(
19
+ ["git", "rev-parse", "--show-toplevel"], stderr=PIPE, cwd=path, text=True
20
+ )
21
+ except CalledProcessError as error:
22
+ # newer versions of git report "Not a git repository", whilst older
23
+ # versions report "not a git repository"
24
+ if search("fatal: not a git repository", error.stderr, flags=IGNORECASE):
25
+ raise GetRepoRootError(cwd=path) from error
26
+ raise # pragma: no cover
27
+ else:
28
+ return Path(output.strip("\n"))
29
+
30
+
31
+ @dataclass(kw_only=True, slots=True)
32
+ class GetRepoRootError(Exception):
33
+ cwd: PathLike
34
+
35
+ @override
36
+ def __str__(self) -> str:
37
+ return f"Path is not part of a `git` repository: {self.cwd}"
38
+
39
+
40
+ __all__ = ["GetRepoRootError", "get_repo_root"]