relib 1.3.3__tar.gz → 1.3.4__tar.gz
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.
- {relib-1.3.3 → relib-1.3.4}/PKG-INFO +1 -1
- {relib-1.3.3 → relib-1.3.4}/pyproject.toml +1 -1
- relib-1.3.4/relib/io_utils.py +41 -0
- {relib-1.3.3 → relib-1.3.4}/relib/runtime_tools.py +1 -1
- {relib-1.3.3 → relib-1.3.4}/uv.lock +1 -1
- relib-1.3.3/relib/io_utils.py +0 -21
- {relib-1.3.3 → relib-1.3.4}/.gitignore +0 -0
- {relib-1.3.3 → relib-1.3.4}/.python-version +0 -0
- {relib-1.3.3 → relib-1.3.4}/LICENSE +0 -0
- {relib-1.3.3 → relib-1.3.4}/README.md +0 -0
- {relib-1.3.3 → relib-1.3.4}/relib/__init__.py +0 -0
- {relib-1.3.3 → relib-1.3.4}/relib/dict_utils.py +0 -0
- {relib-1.3.3 → relib-1.3.4}/relib/iter_utils.py +0 -0
- {relib-1.3.3 → relib-1.3.4}/relib/processing_utils.py +0 -0
- {relib-1.3.3 → relib-1.3.4}/relib/type_utils.py +0 -0
@@ -0,0 +1,41 @@
|
|
1
|
+
import json
|
2
|
+
from pathlib import Path
|
3
|
+
from typing import Any, Iterable
|
4
|
+
|
5
|
+
__all__ = [
|
6
|
+
"clear_directory",
|
7
|
+
"empty_dirs",
|
8
|
+
"read_json",
|
9
|
+
"write_json",
|
10
|
+
]
|
11
|
+
|
12
|
+
default_sentinel = object()
|
13
|
+
|
14
|
+
def read_json(path: Path, default=default_sentinel) -> Any:
|
15
|
+
if default is not default_sentinel and not path.exists():
|
16
|
+
return default
|
17
|
+
with path.open("r") as f:
|
18
|
+
return json.load(f)
|
19
|
+
|
20
|
+
def write_json(path: Path, obj: object, indent: None | int = None) -> None:
|
21
|
+
with path.open("w") as f:
|
22
|
+
separators = (",", ":") if indent is None else None
|
23
|
+
return json.dump(obj, f, indent=indent, separators=separators)
|
24
|
+
|
25
|
+
def empty_dirs(path: Path) -> Iterable[Path]:
|
26
|
+
nonempty_count = 0
|
27
|
+
for child in path.iterdir():
|
28
|
+
nonempty_count += 1
|
29
|
+
if child.is_dir():
|
30
|
+
for grand_child in empty_dirs(child):
|
31
|
+
yield grand_child
|
32
|
+
nonempty_count -= child == grand_child
|
33
|
+
if nonempty_count == 0:
|
34
|
+
yield path
|
35
|
+
|
36
|
+
def clear_directory(path: Path):
|
37
|
+
if path.is_dir():
|
38
|
+
for file in path.glob("**/.DS_Store"):
|
39
|
+
file.unlink()
|
40
|
+
for directory in empty_dirs(path):
|
41
|
+
directory.rmdir()
|
@@ -25,7 +25,7 @@ default_executor = ThreadPoolExecutor(max_workers=default_workers)
|
|
25
25
|
|
26
26
|
def raise_if_interrupt():
|
27
27
|
if sys.exc_info()[0] in (KeyboardInterrupt, SystemExit):
|
28
|
-
|
28
|
+
raise
|
29
29
|
|
30
30
|
def clear_console() -> None:
|
31
31
|
os.system("cls" if os.name == "nt" else "clear")
|
relib-1.3.3/relib/io_utils.py
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
import json
|
2
|
-
from pathlib import Path
|
3
|
-
from typing import Any
|
4
|
-
|
5
|
-
__all__ = [
|
6
|
-
"read_json",
|
7
|
-
"write_json",
|
8
|
-
]
|
9
|
-
|
10
|
-
default_sentinel = object()
|
11
|
-
|
12
|
-
def read_json(path: Path, default=default_sentinel) -> Any:
|
13
|
-
if default is not default_sentinel and not path.exists():
|
14
|
-
return default
|
15
|
-
with path.open("r") as f:
|
16
|
-
return json.load(f)
|
17
|
-
|
18
|
-
def write_json(path: Path, obj: object, indent: None | int = None) -> None:
|
19
|
-
with path.open("w") as f:
|
20
|
-
separators = (",", ":") if indent is None else None
|
21
|
-
return json.dump(obj, f, indent=indent, separators=separators)
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|