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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: relib
3
- Version: 1.3.3
3
+ Version: 1.3.4
4
4
  Project-URL: Repository, https://github.com/Reddan/relib.git
5
5
  Author: Hampus Hallman
6
6
  License: Copyright 2018-2025 Hampus Hallman
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "relib"
3
- version = "1.3.3"
3
+ version = "1.3.4"
4
4
  requires-python = ">=3.12"
5
5
  dependencies = []
6
6
  authors = [
@@ -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
- raise
28
+ raise
29
29
 
30
30
  def clear_console() -> None:
31
31
  os.system("cls" if os.name == "nt" else "clear")
@@ -118,7 +118,7 @@ wheels = [
118
118
 
119
119
  [[package]]
120
120
  name = "relib"
121
- version = "1.3.3"
121
+ version = "1.3.4"
122
122
  source = { editable = "." }
123
123
 
124
124
  [package.dev-dependencies]
@@ -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