relib 1.3.1__tar.gz → 1.3.3__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.1 → relib-1.3.3}/PKG-INFO +1 -1
- {relib-1.3.1 → relib-1.3.3}/pyproject.toml +2 -1
- {relib-1.3.1 → relib-1.3.3}/relib/iter_utils.py +78 -17
- {relib-1.3.1 → relib-1.3.3}/relib/runtime_tools.py +14 -8
- {relib-1.3.1 → relib-1.3.3}/uv.lock +39 -1
- {relib-1.3.1 → relib-1.3.3}/.gitignore +0 -0
- {relib-1.3.1 → relib-1.3.3}/.python-version +0 -0
- {relib-1.3.1 → relib-1.3.3}/LICENSE +0 -0
- {relib-1.3.1 → relib-1.3.3}/README.md +0 -0
- {relib-1.3.1 → relib-1.3.3}/relib/__init__.py +0 -0
- {relib-1.3.1 → relib-1.3.3}/relib/dict_utils.py +0 -0
- {relib-1.3.1 → relib-1.3.3}/relib/io_utils.py +0 -0
- {relib-1.3.1 → relib-1.3.3}/relib/processing_utils.py +0 -0
- {relib-1.3.1 → relib-1.3.3}/relib/type_utils.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
[project]
|
2
2
|
name = "relib"
|
3
|
-
version = "1.3.
|
3
|
+
version = "1.3.3"
|
4
4
|
requires-python = ">=3.12"
|
5
5
|
dependencies = []
|
6
6
|
authors = [
|
@@ -16,6 +16,7 @@ Repository = "https://github.com/Reddan/relib.git"
|
|
16
16
|
[dependency-groups]
|
17
17
|
dev = [
|
18
18
|
"numpy>=2.1.3",
|
19
|
+
"omg>=1.3.6",
|
19
20
|
"pandas>=2.2.3",
|
20
21
|
"tqdm>=4.67.1",
|
21
22
|
]
|
@@ -1,16 +1,18 @@
|
|
1
|
-
from
|
2
|
-
from
|
1
|
+
from contextlib import contextmanager
|
2
|
+
from itertools import chain, islice
|
3
|
+
from typing import Any, Iterable, Literal, Self, overload
|
3
4
|
from .dict_utils import dict_firsts
|
4
5
|
|
5
6
|
__all__ = [
|
7
|
+
"chunked",
|
6
8
|
"distinct_by", "distinct", "drop_none",
|
7
9
|
"first", "flatten",
|
8
10
|
"interleave", "intersect",
|
9
11
|
"list_split",
|
10
12
|
"move_value",
|
11
|
-
"
|
13
|
+
"partition",
|
12
14
|
"reversed_enumerate",
|
13
|
-
"
|
15
|
+
"seekable", "sort_by",
|
14
16
|
"transpose",
|
15
17
|
]
|
16
18
|
|
@@ -36,7 +38,7 @@ def move_value[T](iterable: Iterable[T], from_i: int, to_i: int) -> list[T]:
|
|
36
38
|
return values
|
37
39
|
|
38
40
|
def reversed_enumerate[T](values: list[T] | tuple[T, ...]) -> Iterable[tuple[int, T]]:
|
39
|
-
return zip(range(len(values))[
|
41
|
+
return zip(range(len(values))[::-1], reversed(values))
|
40
42
|
|
41
43
|
def intersect[T](*iterables: Iterable[T]) -> list[T]:
|
42
44
|
return list(set.intersection(*map(set, iterables)))
|
@@ -50,18 +52,77 @@ def list_split[T](iterable: Iterable[T], sep: T) -> list[list[T]]:
|
|
50
52
|
ranges = list(zip(split_at[0:-1], split_at[1:]))
|
51
53
|
return [values[start + 1:end] for start, end in ranges]
|
52
54
|
|
53
|
-
def
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
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
|
+
|
64
|
+
class seekable[T]:
|
65
|
+
def __init__(self, iterable: Iterable[T]):
|
66
|
+
self.index = 0
|
67
|
+
self.source = iter(iterable)
|
68
|
+
self.sink: list[T] = []
|
69
|
+
|
70
|
+
def __iter__(self):
|
71
|
+
return self
|
72
|
+
|
73
|
+
def __next__(self) -> T:
|
74
|
+
if len(self.sink) > self.index:
|
75
|
+
item = self.sink[self.index]
|
76
|
+
else:
|
77
|
+
item = next(self.source)
|
78
|
+
self.sink.append(item)
|
79
|
+
self.index += 1
|
80
|
+
return item
|
81
|
+
|
82
|
+
def __bool__(self):
|
83
|
+
return bool(self.lookahead(1))
|
84
|
+
|
85
|
+
def clear(self):
|
86
|
+
self.sink[:self.index] = []
|
87
|
+
self.index = 0
|
88
|
+
|
89
|
+
def seek(self, index: int) -> Self:
|
90
|
+
remainder = index - len(self.sink)
|
91
|
+
if remainder > 0:
|
92
|
+
next(islice(self, remainder, remainder), None)
|
93
|
+
self.index = max(0, min(index, len(self.sink)))
|
94
|
+
return self
|
95
|
+
|
96
|
+
def step(self, count: int) -> Self:
|
97
|
+
return self.seek(self.index + count)
|
98
|
+
|
99
|
+
@contextmanager
|
100
|
+
def freeze(self):
|
101
|
+
def commit(offset: int = 0):
|
102
|
+
nonlocal initial_index
|
103
|
+
initial_index = self.index + offset
|
104
|
+
initial_index = self.index
|
105
|
+
try:
|
106
|
+
yield commit
|
107
|
+
finally:
|
108
|
+
self.seek(initial_index)
|
109
|
+
|
110
|
+
def lookahead(self, count: int) -> list[T]:
|
111
|
+
with self.freeze():
|
112
|
+
return list(islice(self, count))
|
113
|
+
|
114
|
+
@overload
|
115
|
+
def chunked[T](values: Iterable[T], *, num_chunks: int, chunk_size=None) -> list[list[T]]: ...
|
116
|
+
@overload
|
117
|
+
def chunked[T](values: Iterable[T], *, num_chunks=None, chunk_size: int) -> list[list[T]]: ...
|
118
|
+
def chunked(values, *, num_chunks=None, chunk_size=None):
|
119
|
+
values = values if isinstance(values, list) else list(values)
|
120
|
+
if isinstance(num_chunks, int):
|
121
|
+
chunk_size = (len(values) / num_chunks).__ceil__()
|
122
|
+
elif isinstance(chunk_size, int):
|
123
|
+
num_chunks = (len(values) / chunk_size).__ceil__()
|
124
|
+
assert isinstance(num_chunks, int) and isinstance(chunk_size, int)
|
125
|
+
return [values[i * chunk_size:(i + 1) * chunk_size] for i in range(num_chunks)]
|
65
126
|
|
66
127
|
@overload
|
67
128
|
def flatten[T](iterable: Iterable[T], depth: Literal[0]) -> list[T]: ...
|
@@ -1,39 +1,45 @@
|
|
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
|
7
|
-
from typing import
|
8
|
+
from typing import Callable, Coroutine, Iterable, ParamSpec, TypeVar
|
8
9
|
from .processing_utils import noop
|
9
10
|
|
10
11
|
__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
|
|
18
19
|
P = ParamSpec("P")
|
19
20
|
R = TypeVar("R")
|
21
|
+
Coro = Coroutine[object, object, R]
|
20
22
|
|
21
23
|
default_workers = min(32, (os.cpu_count() or 1) + 4)
|
22
24
|
default_executor = ThreadPoolExecutor(max_workers=default_workers)
|
23
25
|
|
26
|
+
def raise_if_interrupt():
|
27
|
+
if sys.exc_info()[0] in (KeyboardInterrupt, SystemExit):
|
28
|
+
raise
|
29
|
+
|
24
30
|
def clear_console() -> None:
|
25
31
|
os.system("cls" if os.name == "nt" else "clear")
|
26
32
|
|
27
33
|
def console_link(text: str, url: str) -> str:
|
28
34
|
return f"\033]8;;{url}\033\\{text}\033]8;;\033\\"
|
29
35
|
|
30
|
-
async def worker[T](task:
|
36
|
+
async def worker[T](task: Coro[T], semaphore: asyncio.Semaphore, update=noop) -> T:
|
31
37
|
async with semaphore:
|
32
38
|
result = await task
|
33
39
|
update()
|
34
40
|
return result
|
35
41
|
|
36
|
-
async def roll_tasks[T](tasks: Iterable[
|
42
|
+
async def roll_tasks[T](tasks: Iterable[Coro[T]], workers=default_workers, progress=False) -> list[T]:
|
37
43
|
semaphore = asyncio.Semaphore(workers)
|
38
44
|
if not progress:
|
39
45
|
return await asyncio.gather(*[worker(task, semaphore) for task in tasks])
|
@@ -44,10 +50,10 @@ async def roll_tasks[T](tasks: Iterable[Awaitable[T]], workers=default_workers,
|
|
44
50
|
update = partial(pbar.update, 1)
|
45
51
|
return await asyncio.gather(*[worker(task, semaphore, update) for task in tasks])
|
46
52
|
|
47
|
-
def as_async(workers: int | ThreadPoolExecutor = default_executor) -> Callable[[Callable[P, R]], Callable[P,
|
53
|
+
def as_async(workers: int | ThreadPoolExecutor = default_executor) -> Callable[[Callable[P, R]], Callable[P, Coro[R]]]:
|
48
54
|
executor = ThreadPoolExecutor(max_workers=workers) if isinstance(workers, int) else workers
|
49
55
|
|
50
|
-
def on_fn(func: Callable[P, R]) -> Callable[P,
|
56
|
+
def on_fn(func: Callable[P, R]) -> Callable[P, Coro[R]]:
|
51
57
|
@wraps(func)
|
52
58
|
async def wrapper(*args: P.args, **kwargs: P.kwargs) -> R:
|
53
59
|
loop = asyncio.get_running_loop()
|
@@ -57,10 +63,10 @@ def as_async(workers: int | ThreadPoolExecutor = default_executor) -> Callable[[
|
|
57
63
|
return wrapper
|
58
64
|
return on_fn
|
59
65
|
|
60
|
-
def async_limit(workers=default_workers) -> Callable[[Callable[P,
|
66
|
+
def async_limit(workers=default_workers) -> Callable[[Callable[P, Coro[R]]], Callable[P, Coro[R]]]:
|
61
67
|
semaphore = asyncio.Semaphore(workers)
|
62
68
|
|
63
|
-
def on_fn(func: Callable[P,
|
69
|
+
def on_fn(func: Callable[P, Coro[R]]) -> Callable[P, Coro[R]]:
|
64
70
|
@wraps(func)
|
65
71
|
async def wrapper(*args: P.args, **kwargs: P.kwargs) -> R:
|
66
72
|
async with semaphore:
|
@@ -49,6 +49,18 @@ wheels = [
|
|
49
49
|
{ url = "https://files.pythonhosted.org/packages/86/09/a5ab407bd7f5f5599e6a9261f964ace03a73e7c6928de906981c31c38082/numpy-2.1.3-cp313-cp313t-win_amd64.whl", hash = "sha256:2564fbdf2b99b3f815f2107c1bbc93e2de8ee655a69c261363a1172a79a257d4", size = 12644098 },
|
50
50
|
]
|
51
51
|
|
52
|
+
[[package]]
|
53
|
+
name = "omg"
|
54
|
+
version = "1.3.6"
|
55
|
+
source = { registry = "https://pypi.org/simple" }
|
56
|
+
dependencies = [
|
57
|
+
{ name = "watchdog" },
|
58
|
+
]
|
59
|
+
sdist = { url = "https://files.pythonhosted.org/packages/65/06/da0a3778b7ff8f1333ed7ddc0931ffff3c86ab5cb8bc4a96a1d0edb8671b/omg-1.3.6.tar.gz", hash = "sha256:465a51b7576fa31ef313e2b9a77d57f5d4816fb0a14dca0fc5c09ff471074fe6", size = 14268 }
|
60
|
+
wheels = [
|
61
|
+
{ url = "https://files.pythonhosted.org/packages/dd/d2/87346e94dbecd3a65a09e2156c1adf30c162f31e69d0936343c3eff53e7a/omg-1.3.6-py3-none-any.whl", hash = "sha256:8e3ac99a18d5284ceef2ed98492d288d5f22ee2bb417591654a7d2433e196607", size = 7988 },
|
62
|
+
]
|
63
|
+
|
52
64
|
[[package]]
|
53
65
|
name = "pandas"
|
54
66
|
version = "2.2.3"
|
@@ -106,12 +118,13 @@ wheels = [
|
|
106
118
|
|
107
119
|
[[package]]
|
108
120
|
name = "relib"
|
109
|
-
version = "1.3.
|
121
|
+
version = "1.3.3"
|
110
122
|
source = { editable = "." }
|
111
123
|
|
112
124
|
[package.dev-dependencies]
|
113
125
|
dev = [
|
114
126
|
{ name = "numpy" },
|
127
|
+
{ name = "omg" },
|
115
128
|
{ name = "pandas" },
|
116
129
|
{ name = "tqdm" },
|
117
130
|
]
|
@@ -121,6 +134,7 @@ dev = [
|
|
121
134
|
[package.metadata.requires-dev]
|
122
135
|
dev = [
|
123
136
|
{ name = "numpy", specifier = ">=2.1.3" },
|
137
|
+
{ name = "omg", specifier = ">=1.3.6" },
|
124
138
|
{ name = "pandas", specifier = ">=2.2.3" },
|
125
139
|
{ name = "tqdm", specifier = ">=4.67.1" },
|
126
140
|
]
|
@@ -154,3 +168,27 @@ sdist = { url = "https://files.pythonhosted.org/packages/e1/34/943888654477a574a
|
|
154
168
|
wheels = [
|
155
169
|
{ url = "https://files.pythonhosted.org/packages/a6/ab/7e5f53c3b9d14972843a647d8d7a853969a58aecc7559cb3267302c94774/tzdata-2024.2-py2.py3-none-any.whl", hash = "sha256:a48093786cdcde33cad18c2555e8532f34422074448fbc874186f0abd79565cd", size = 346586 },
|
156
170
|
]
|
171
|
+
|
172
|
+
[[package]]
|
173
|
+
name = "watchdog"
|
174
|
+
version = "6.0.0"
|
175
|
+
source = { registry = "https://pypi.org/simple" }
|
176
|
+
sdist = { url = "https://files.pythonhosted.org/packages/db/7d/7f3d619e951c88ed75c6037b246ddcf2d322812ee8ea189be89511721d54/watchdog-6.0.0.tar.gz", hash = "sha256:9ddf7c82fda3ae8e24decda1338ede66e1c99883db93711d8fb941eaa2d8c282", size = 131220 }
|
177
|
+
wheels = [
|
178
|
+
{ url = "https://files.pythonhosted.org/packages/39/ea/3930d07dafc9e286ed356a679aa02d777c06e9bfd1164fa7c19c288a5483/watchdog-6.0.0-cp312-cp312-macosx_10_13_universal2.whl", hash = "sha256:bdd4e6f14b8b18c334febb9c4425a878a2ac20efd1e0b231978e7b150f92a948", size = 96471 },
|
179
|
+
{ url = "https://files.pythonhosted.org/packages/12/87/48361531f70b1f87928b045df868a9fd4e253d9ae087fa4cf3f7113be363/watchdog-6.0.0-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:c7c15dda13c4eb00d6fb6fc508b3c0ed88b9d5d374056b239c4ad1611125c860", size = 88449 },
|
180
|
+
{ url = "https://files.pythonhosted.org/packages/5b/7e/8f322f5e600812e6f9a31b75d242631068ca8f4ef0582dd3ae6e72daecc8/watchdog-6.0.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:6f10cb2d5902447c7d0da897e2c6768bca89174d0c6e1e30abec5421af97a5b0", size = 89054 },
|
181
|
+
{ url = "https://files.pythonhosted.org/packages/68/98/b0345cabdce2041a01293ba483333582891a3bd5769b08eceb0d406056ef/watchdog-6.0.0-cp313-cp313-macosx_10_13_universal2.whl", hash = "sha256:490ab2ef84f11129844c23fb14ecf30ef3d8a6abafd3754a6f75ca1e6654136c", size = 96480 },
|
182
|
+
{ url = "https://files.pythonhosted.org/packages/85/83/cdf13902c626b28eedef7ec4f10745c52aad8a8fe7eb04ed7b1f111ca20e/watchdog-6.0.0-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:76aae96b00ae814b181bb25b1b98076d5fc84e8a53cd8885a318b42b6d3a5134", size = 88451 },
|
183
|
+
{ url = "https://files.pythonhosted.org/packages/fe/c4/225c87bae08c8b9ec99030cd48ae9c4eca050a59bf5c2255853e18c87b50/watchdog-6.0.0-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:a175f755fc2279e0b7312c0035d52e27211a5bc39719dd529625b1930917345b", size = 89057 },
|
184
|
+
{ url = "https://files.pythonhosted.org/packages/a9/c7/ca4bf3e518cb57a686b2feb4f55a1892fd9a3dd13f470fca14e00f80ea36/watchdog-6.0.0-py3-none-manylinux2014_aarch64.whl", hash = "sha256:7607498efa04a3542ae3e05e64da8202e58159aa1fa4acddf7678d34a35d4f13", size = 79079 },
|
185
|
+
{ url = "https://files.pythonhosted.org/packages/5c/51/d46dc9332f9a647593c947b4b88e2381c8dfc0942d15b8edc0310fa4abb1/watchdog-6.0.0-py3-none-manylinux2014_armv7l.whl", hash = "sha256:9041567ee8953024c83343288ccc458fd0a2d811d6a0fd68c4c22609e3490379", size = 79078 },
|
186
|
+
{ url = "https://files.pythonhosted.org/packages/d4/57/04edbf5e169cd318d5f07b4766fee38e825d64b6913ca157ca32d1a42267/watchdog-6.0.0-py3-none-manylinux2014_i686.whl", hash = "sha256:82dc3e3143c7e38ec49d61af98d6558288c415eac98486a5c581726e0737c00e", size = 79076 },
|
187
|
+
{ url = "https://files.pythonhosted.org/packages/ab/cc/da8422b300e13cb187d2203f20b9253e91058aaf7db65b74142013478e66/watchdog-6.0.0-py3-none-manylinux2014_ppc64.whl", hash = "sha256:212ac9b8bf1161dc91bd09c048048a95ca3a4c4f5e5d4a7d1b1a7d5752a7f96f", size = 79077 },
|
188
|
+
{ url = "https://files.pythonhosted.org/packages/2c/3b/b8964e04ae1a025c44ba8e4291f86e97fac443bca31de8bd98d3263d2fcf/watchdog-6.0.0-py3-none-manylinux2014_ppc64le.whl", hash = "sha256:e3df4cbb9a450c6d49318f6d14f4bbc80d763fa587ba46ec86f99f9e6876bb26", size = 79078 },
|
189
|
+
{ url = "https://files.pythonhosted.org/packages/62/ae/a696eb424bedff7407801c257d4b1afda455fe40821a2be430e173660e81/watchdog-6.0.0-py3-none-manylinux2014_s390x.whl", hash = "sha256:2cce7cfc2008eb51feb6aab51251fd79b85d9894e98ba847408f662b3395ca3c", size = 79077 },
|
190
|
+
{ url = "https://files.pythonhosted.org/packages/b5/e8/dbf020b4d98251a9860752a094d09a65e1b436ad181faf929983f697048f/watchdog-6.0.0-py3-none-manylinux2014_x86_64.whl", hash = "sha256:20ffe5b202af80ab4266dcd3e91aae72bf2da48c0d33bdb15c66658e685e94e2", size = 79078 },
|
191
|
+
{ url = "https://files.pythonhosted.org/packages/07/f6/d0e5b343768e8bcb4cda79f0f2f55051bf26177ecd5651f84c07567461cf/watchdog-6.0.0-py3-none-win32.whl", hash = "sha256:07df1fdd701c5d4c8e55ef6cf55b8f0120fe1aef7ef39a1c6fc6bc2e606d517a", size = 79065 },
|
192
|
+
{ url = "https://files.pythonhosted.org/packages/db/d9/c495884c6e548fce18a8f40568ff120bc3a4b7b99813081c8ac0c936fa64/watchdog-6.0.0-py3-none-win_amd64.whl", hash = "sha256:cbafb470cf848d93b5d013e2ecb245d4aa1c8fd0504e863ccefa32445359d680", size = 79070 },
|
193
|
+
{ url = "https://files.pythonhosted.org/packages/33/e8/e40370e6d74ddba47f002a32919d91310d6074130fe4e17dabcafc15cbf1/watchdog-6.0.0-py3-none-win_ia64.whl", hash = "sha256:a1914259fa9e1454315171103c6a30961236f508b9b623eae470268bbcc6a22f", size = 79067 },
|
194
|
+
]
|
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
|