dycw-utilities 0.138.8__py3-none-any.whl → 0.138.9__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.
- {dycw_utilities-0.138.8.dist-info → dycw_utilities-0.138.9.dist-info}/METADATA +1 -1
- {dycw_utilities-0.138.8.dist-info → dycw_utilities-0.138.9.dist-info}/RECORD +7 -7
- utilities/__init__.py +1 -1
- utilities/pathlib.py +71 -24
- {dycw_utilities-0.138.8.dist-info → dycw_utilities-0.138.9.dist-info}/WHEEL +0 -0
- {dycw_utilities-0.138.8.dist-info → dycw_utilities-0.138.9.dist-info}/entry_points.txt +0 -0
- {dycw_utilities-0.138.8.dist-info → dycw_utilities-0.138.9.dist-info}/licenses/LICENSE +0 -0
@@ -1,4 +1,4 @@
|
|
1
|
-
utilities/__init__.py,sha256=
|
1
|
+
utilities/__init__.py,sha256=ANddrXgdSTBQjO5buynEzt5zVNH6F2WJFjL8c1YlyV8,60
|
2
2
|
utilities/aiolimiter.py,sha256=mD0wEiqMgwpty4XTbawFpnkkmJS6R4JRsVXFUaoitSU,628
|
3
3
|
utilities/altair.py,sha256=HeZBVUocjkrTNwwKrClppsIqgNFF-ykv05HfZSoHYno,9104
|
4
4
|
utilities/asyncio.py,sha256=dcGeKQzjLBXxKzZkVIk5oZsFXEcynVbRB9iNB5XEDZk,38526
|
@@ -42,7 +42,7 @@ utilities/optuna.py,sha256=C-fhWYiXHVPo1l8QctYkFJ4DyhbSrGorzP1dJb_qvd8,1933
|
|
42
42
|
utilities/orjson.py,sha256=WWV2QukCIuwT8OAOtmKhLhxezXPVbeA_fQCucmGmbRA,37106
|
43
43
|
utilities/os.py,sha256=yMNAKMyY8oFgQ1yN3TQYnwa5-A_FXz4tCDbhIctQHSs,3736
|
44
44
|
utilities/parse.py,sha256=JcJn5yXKhIWXBCwgBdPsyu7Hvcuw6kyEdqvaebCaI9k,17951
|
45
|
-
utilities/pathlib.py,sha256=
|
45
|
+
utilities/pathlib.py,sha256=5p9MI8m7iUFksNVGiLavN4MZ3cj1CpBiLBlgaCR0LCs,8334
|
46
46
|
utilities/period.py,sha256=6jEff_qAiE7xdFaQ1DnKgNf10D2wHhzt7hQXCBoKlgc,6842
|
47
47
|
utilities/pickle.py,sha256=MBT2xZCsv0pH868IXLGKnlcqNx2IRVKYNpRcqiQQqxw,653
|
48
48
|
utilities/platform.py,sha256=5uCKRf_ij7ukJDcbnNfhY2ay9fbrpiNLRO1t2QvcwqQ,2825
|
@@ -88,8 +88,8 @@ utilities/warnings.py,sha256=un1LvHv70PU-LLv8RxPVmugTzDJkkGXRMZTE2-fTQHw,1771
|
|
88
88
|
utilities/whenever.py,sha256=R5d9UCNCdAOyjwLUmfH2Vn8Ykee8OHQi2skRTFfbZMM,20492
|
89
89
|
utilities/zipfile.py,sha256=24lQc9ATcJxHXBPc_tBDiJk48pWyRrlxO2fIsFxU0A8,699
|
90
90
|
utilities/zoneinfo.py,sha256=oEH-nL3t4h9uawyZqWDtNtDAl6M-CLpLYGI_nI6DulM,1971
|
91
|
-
dycw_utilities-0.138.
|
92
|
-
dycw_utilities-0.138.
|
93
|
-
dycw_utilities-0.138.
|
94
|
-
dycw_utilities-0.138.
|
95
|
-
dycw_utilities-0.138.
|
91
|
+
dycw_utilities-0.138.9.dist-info/METADATA,sha256=og-7pWHDQmHofzZTBE5WqHkkBAcqtjf6rxaKb8gKz-c,1638
|
92
|
+
dycw_utilities-0.138.9.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
93
|
+
dycw_utilities-0.138.9.dist-info/entry_points.txt,sha256=uLj5QWWVXv8tnMaRX3ZGYpt7w1xzLWU6LxbFhELEpkc,68
|
94
|
+
dycw_utilities-0.138.9.dist-info/licenses/LICENSE,sha256=gppZp16M6nSVpBbUBrNL6JuYfvKwZiKgV7XoKKsHzqo,1066
|
95
|
+
dycw_utilities-0.138.9.dist-info/RECORD,,
|
utilities/__init__.py
CHANGED
utilities/pathlib.py
CHANGED
@@ -71,8 +71,35 @@ def get_path(
|
|
71
71
|
##
|
72
72
|
|
73
73
|
|
74
|
-
def
|
75
|
-
"""Get the root
|
74
|
+
def get_package_root(*, path: MaybeCallablePathLike | None = None) -> Path:
|
75
|
+
"""Get the package root."""
|
76
|
+
path = get_path(path=path)
|
77
|
+
path_dir = path.parent if path.is_file() else path
|
78
|
+
all_paths = list(chain([path_dir], path_dir.parents))
|
79
|
+
try:
|
80
|
+
return next(
|
81
|
+
p.resolve()
|
82
|
+
for p in all_paths
|
83
|
+
if any(p_i.name == "pyproject.toml" for p_i in p.iterdir())
|
84
|
+
)
|
85
|
+
except StopIteration:
|
86
|
+
raise GetPackageRootError(path=path) from None
|
87
|
+
|
88
|
+
|
89
|
+
@dataclass(kw_only=True, slots=True)
|
90
|
+
class GetPackageRootError(Exception):
|
91
|
+
path: PathLike
|
92
|
+
|
93
|
+
@override
|
94
|
+
def __str__(self) -> str:
|
95
|
+
return f"Path is not part of a package: {self.path}"
|
96
|
+
|
97
|
+
|
98
|
+
##
|
99
|
+
|
100
|
+
|
101
|
+
def get_repo_root(*, path: MaybeCallablePathLike | None = None) -> Path:
|
102
|
+
"""Get the repo root."""
|
76
103
|
path = get_path(path=path)
|
77
104
|
path_dir = path.parent if path.is_file() else path
|
78
105
|
try:
|
@@ -85,36 +112,52 @@ def get_root(*, path: MaybeCallablePathLike | None = None) -> Path:
|
|
85
112
|
except CalledProcessError as error:
|
86
113
|
# newer versions of git report "Not a git repository", whilst older
|
87
114
|
# versions report "not a git repository"
|
88
|
-
if
|
89
|
-
raise
|
90
|
-
|
115
|
+
if search("fatal: not a git repository", error.stderr, flags=IGNORECASE):
|
116
|
+
raise GetRepoRootError(path=path) from None
|
117
|
+
raise # pragma: no cover
|
91
118
|
else:
|
92
|
-
|
93
|
-
|
119
|
+
return Path(output.strip("\n"))
|
120
|
+
|
121
|
+
|
122
|
+
@dataclass(kw_only=True, slots=True)
|
123
|
+
class GetRepoRootError(Exception):
|
124
|
+
path: PathLike
|
125
|
+
|
126
|
+
@override
|
127
|
+
def __str__(self) -> str:
|
128
|
+
return f"Path is not part of a `git` repository: {self.path}"
|
129
|
+
|
130
|
+
|
131
|
+
##
|
132
|
+
|
133
|
+
|
134
|
+
def get_root(*, path: MaybeCallablePathLike | None = None) -> Path:
|
135
|
+
"""Get the root of a path."""
|
136
|
+
path = get_path(path=path)
|
94
137
|
try:
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
)
|
100
|
-
except
|
101
|
-
|
102
|
-
match
|
138
|
+
repo = get_repo_root(path=path)
|
139
|
+
except GetRepoRootError:
|
140
|
+
repo = None
|
141
|
+
try:
|
142
|
+
package = get_package_root(path=path)
|
143
|
+
except GetPackageRootError:
|
144
|
+
package = None
|
145
|
+
match repo, package:
|
103
146
|
case None, None:
|
104
147
|
raise GetRootError(path=path)
|
105
148
|
case Path(), None:
|
106
|
-
return
|
149
|
+
return repo
|
107
150
|
case None, Path():
|
108
|
-
return
|
151
|
+
return package
|
109
152
|
case Path(), Path():
|
110
|
-
if
|
111
|
-
return
|
112
|
-
if is_sub_path(
|
113
|
-
return
|
114
|
-
if is_sub_path(
|
115
|
-
return
|
153
|
+
if repo == package:
|
154
|
+
return repo
|
155
|
+
if is_sub_path(repo, package, strict=True):
|
156
|
+
return repo
|
157
|
+
if is_sub_path(package, repo, strict=True):
|
158
|
+
return package
|
116
159
|
raise ImpossibleCaseError( # pragma: no cover
|
117
|
-
case=[f"{
|
160
|
+
case=[f"{repo=}", f"{package=}"]
|
118
161
|
)
|
119
162
|
case _ as never:
|
120
163
|
assert_never(never)
|
@@ -259,10 +302,14 @@ def temp_cwd(path: PathLike, /) -> Iterator[None]:
|
|
259
302
|
|
260
303
|
__all__ = [
|
261
304
|
"PWD",
|
305
|
+
"GetPackageRootError",
|
306
|
+
"GetRepoRootError",
|
262
307
|
"GetTailError",
|
263
308
|
"ensure_suffix",
|
264
309
|
"expand_path",
|
310
|
+
"get_package_root",
|
265
311
|
"get_path",
|
312
|
+
"get_repo_root",
|
266
313
|
"get_tail",
|
267
314
|
"is_sub_path",
|
268
315
|
"list_dir",
|
File without changes
|
File without changes
|
File without changes
|