relib 1.3.2__py3-none-any.whl → 1.3.4__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.
relib/io_utils.py CHANGED
@@ -1,8 +1,10 @@
1
1
  import json
2
2
  from pathlib import Path
3
- from typing import Any
3
+ from typing import Any, Iterable
4
4
 
5
5
  __all__ = [
6
+ "clear_directory",
7
+ "empty_dirs",
6
8
  "read_json",
7
9
  "write_json",
8
10
  ]
@@ -19,3 +21,21 @@ def write_json(path: Path, obj: object, indent: None | int = None) -> None:
19
21
  with path.open("w") as f:
20
22
  separators = (",", ":") if indent is None else None
21
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()
relib/iter_utils.py CHANGED
@@ -10,6 +10,7 @@ __all__ = [
10
10
  "interleave", "intersect",
11
11
  "list_split",
12
12
  "move_value",
13
+ "partition",
13
14
  "reversed_enumerate",
14
15
  "seekable", "sort_by",
15
16
  "transpose",
@@ -51,6 +52,15 @@ def list_split[T](iterable: Iterable[T], sep: T) -> list[list[T]]:
51
52
  ranges = list(zip(split_at[0:-1], split_at[1:]))
52
53
  return [values[start + 1:end] for start, end in ranges]
53
54
 
55
+ def partition[T](iterable: Iterable[tuple[bool, T]]) -> tuple[list[T], list[T]]:
56
+ true_values, false_values = [], []
57
+ for predicate, value in iterable:
58
+ if predicate:
59
+ true_values.append(value)
60
+ else:
61
+ false_values.append(value)
62
+ return true_values, false_values
63
+
54
64
  class seekable[T]:
55
65
  def __init__(self, iterable: Iterable[T]):
56
66
  self.index = 0
relib/runtime_tools.py CHANGED
@@ -1,6 +1,7 @@
1
1
  import asyncio
2
2
  import contextvars
3
3
  import os
4
+ import sys
4
5
  from concurrent.futures import ThreadPoolExecutor
5
6
  from functools import partial, wraps
6
7
  from time import time
@@ -11,7 +12,7 @@ __all__ = [
11
12
  "as_async", "async_limit",
12
13
  "clear_console", "console_link",
13
14
  "default_executor", "default_workers",
14
- "roll_tasks",
15
+ "raise_if_interrupt", "roll_tasks",
15
16
  "measure_duration",
16
17
  ]
17
18
 
@@ -22,6 +23,10 @@ Coro = Coroutine[object, object, R]
22
23
  default_workers = min(32, (os.cpu_count() or 1) + 4)
23
24
  default_executor = ThreadPoolExecutor(max_workers=default_workers)
24
25
 
26
+ def raise_if_interrupt():
27
+ if sys.exc_info()[0] in (KeyboardInterrupt, SystemExit):
28
+ raise
29
+
25
30
  def clear_console() -> None:
26
31
  os.system("cls" if os.name == "nt" else "clear")
27
32
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: relib
3
- Version: 1.3.2
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
@@ -0,0 +1,11 @@
1
+ relib/__init__.py,sha256=WerjUaM_sNvudjXFudLRtXB7viZWEW1RSinkDjrh4nE,163
2
+ relib/dict_utils.py,sha256=jqW6bYSaQMt2AC2KFzDJKyl88idyMttWxXDu3t-fA5I,2980
3
+ relib/io_utils.py,sha256=cUyUFhrMCUDfkINhYo32QPaVGz3chqDO3ElymSCoWEg,1086
4
+ relib/iter_utils.py,sha256=r9tus9F_obwXsHE8Jk8H9_ZPdOgtBI6WnpDxI6La-to,5477
5
+ relib/processing_utils.py,sha256=eMzjlxsEmfvtKafDITBWSp9D5RwegSWsUsvj1FpmBM0,1893
6
+ relib/runtime_tools.py,sha256=Bb0OLMNgG9sqJpMc06x_W5aJNfJ2Z0ryc8f4WEP7Pz4,2967
7
+ relib/type_utils.py,sha256=oY96cAAux1JwhXgWFFyqEv_f-wwyPc_Hm6I9Yeisu_M,323
8
+ relib-1.3.4.dist-info/METADATA,sha256=VSsdKCUxM9Q_qR9xFV1bzaGR8GPv3Unm9a05RzzHGzQ,1295
9
+ relib-1.3.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
10
+ relib-1.3.4.dist-info/licenses/LICENSE,sha256=9xVsdtv_-uSyY9Xl9yujwAPm4-mjcCLeVy-ljwXEWbo,1059
11
+ relib-1.3.4.dist-info/RECORD,,
@@ -1,11 +0,0 @@
1
- relib/__init__.py,sha256=WerjUaM_sNvudjXFudLRtXB7viZWEW1RSinkDjrh4nE,163
2
- relib/dict_utils.py,sha256=jqW6bYSaQMt2AC2KFzDJKyl88idyMttWxXDu3t-fA5I,2980
3
- relib/io_utils.py,sha256=EtnIGQmLXjoHUPFteB5yPXDD3wGLvH4O3CahlCebXDQ,555
4
- relib/iter_utils.py,sha256=O2sXQ7Old7b9mkRczi-R8Gio92hpzSQl30TXsDS7PD4,5179
5
- relib/processing_utils.py,sha256=eMzjlxsEmfvtKafDITBWSp9D5RwegSWsUsvj1FpmBM0,1893
6
- relib/runtime_tools.py,sha256=KNtthODV1DdijABX_VIVbStbgT7Dlubu8oAEGxQsIhQ,2838
7
- relib/type_utils.py,sha256=oY96cAAux1JwhXgWFFyqEv_f-wwyPc_Hm6I9Yeisu_M,323
8
- relib-1.3.2.dist-info/METADATA,sha256=X3NdxQpaT122Rd0CM709I-rJUgUlbTbw3F3b0SwZMhQ,1295
9
- relib-1.3.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
10
- relib-1.3.2.dist-info/licenses/LICENSE,sha256=9xVsdtv_-uSyY9Xl9yujwAPm4-mjcCLeVy-ljwXEWbo,1059
11
- relib-1.3.2.dist-info/RECORD,,
File without changes