relib 1.2.5__tar.gz → 1.2.7__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.2.5 → relib-1.2.7}/PKG-INFO +1 -1
- {relib-1.2.5 → relib-1.2.7}/pyproject.toml +1 -1
- {relib-1.2.5 → relib-1.2.7}/relib/system.py +18 -7
- {relib-1.2.5 → relib-1.2.7}/uv.lock +1 -1
- {relib-1.2.5 → relib-1.2.7}/.gitignore +0 -0
- {relib-1.2.5 → relib-1.2.7}/LICENSE +0 -0
- {relib-1.2.5 → relib-1.2.7}/README.md +0 -0
- {relib-1.2.5 → relib-1.2.7}/relib/__init__.py +0 -0
- {relib-1.2.5 → relib-1.2.7}/relib/hashing.py +0 -0
- {relib-1.2.5 → relib-1.2.7}/relib/measure_duration.py +0 -0
- {relib-1.2.5 → relib-1.2.7}/relib/utils.py +0 -0
@@ -16,9 +16,9 @@ def read_json(path: Path) -> Any:
|
|
16
16
|
with path.open("r") as f:
|
17
17
|
return json.load(f)
|
18
18
|
|
19
|
-
def write_json(path: Path, obj: Any) -> None:
|
19
|
+
def write_json(path: Path, obj: Any, indent: None | int = None) -> None:
|
20
20
|
with path.open("w") as f:
|
21
|
-
return json.dump(obj, f)
|
21
|
+
return json.dump(obj, f, indent=indent)
|
22
22
|
|
23
23
|
def clear_console() -> None:
|
24
24
|
os.system("cls" if os.name == "nt" else "clear")
|
@@ -32,18 +32,19 @@ async def worker[T](task: Awaitable[T], semaphore: asyncio.Semaphore, update=noo
|
|
32
32
|
update()
|
33
33
|
return result
|
34
34
|
|
35
|
-
async def roll_tasks[T](tasks: Iterable[Awaitable[T]], workers
|
35
|
+
async def roll_tasks[T](tasks: Iterable[Awaitable[T]], workers=default_num_workers, progress=False) -> list[T]:
|
36
36
|
semaphore = asyncio.Semaphore(workers)
|
37
37
|
if not progress:
|
38
38
|
return await asyncio.gather(*(worker(task, semaphore) for task in tasks))
|
39
|
+
|
39
40
|
from tqdm import tqdm
|
40
|
-
|
41
|
+
tasks = tasks if isinstance(tasks, list) else list(tasks)
|
41
42
|
with tqdm(total=len(tasks)) as pbar:
|
42
|
-
update =
|
43
|
+
update = functools.partial(pbar.update, 1)
|
43
44
|
return await asyncio.gather(*(worker(task, semaphore, update) for task in tasks))
|
44
45
|
|
45
|
-
def as_async(
|
46
|
-
executor = ThreadPoolExecutor(max_workers=
|
46
|
+
def as_async(workers=default_num_workers) -> Callable[[Callable[P, R]], Callable[P, Awaitable[R]]]:
|
47
|
+
executor = ThreadPoolExecutor(max_workers=workers)
|
47
48
|
|
48
49
|
def on_fn(func: Callable[P, R]) -> Callable[P, Awaitable[R]]:
|
49
50
|
@functools.wraps(func)
|
@@ -53,5 +54,15 @@ def as_async(num_workers=default_num_workers) -> Callable[[Callable[P, R]], Call
|
|
53
54
|
fn_call = functools.partial(ctx.run, func, *args, **kwargs)
|
54
55
|
return await loop.run_in_executor(executor, fn_call)
|
55
56
|
return wrapper
|
57
|
+
return on_fn
|
58
|
+
|
59
|
+
def async_limit(workers=default_num_workers) -> Callable[[Callable[P, Awaitable[R]]], Callable[P, Awaitable[R]]]:
|
60
|
+
semaphore = asyncio.Semaphore(workers)
|
56
61
|
|
62
|
+
def on_fn(func: Callable[P, Awaitable[R]]) -> Callable[P, Awaitable[R]]:
|
63
|
+
@functools.wraps(func)
|
64
|
+
async def wrapper(*args: P.args, **kwargs: P.kwargs) -> R:
|
65
|
+
async with semaphore:
|
66
|
+
return await func(*args, **kwargs)
|
67
|
+
return wrapper
|
57
68
|
return on_fn
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|