relib 1.2.1__py3-none-any.whl → 1.2.3__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/__init__.py +2 -2
- relib/system.py +18 -0
- relib/utils.py +12 -15
- {relib-1.2.1.dist-info → relib-1.2.3.dist-info}/METADATA +2 -2
- relib-1.2.3.dist-info/RECORD +9 -0
- {relib-1.2.1.dist-info → relib-1.2.3.dist-info}/licenses/LICENSE +1 -1
- relib-1.2.1.dist-info/RECORD +0 -8
- {relib-1.2.1.dist-info → relib-1.2.3.dist-info}/WHEEL +0 -0
relib/__init__.py
CHANGED
@@ -1,6 +1,4 @@
|
|
1
1
|
from .utils import (
|
2
|
-
clear_console,
|
3
|
-
console_link,
|
4
2
|
non_none,
|
5
3
|
as_any,
|
6
4
|
list_split,
|
@@ -27,11 +25,13 @@ from .utils import (
|
|
27
25
|
group,
|
28
26
|
reversed_enumerate,
|
29
27
|
get_at,
|
28
|
+
for_each,
|
30
29
|
sized_partitions,
|
31
30
|
num_partitions,
|
32
31
|
df_from_array,
|
33
32
|
StrFilter,
|
34
33
|
str_filterer,
|
35
34
|
)
|
35
|
+
from .system import read_json, write_json, clear_console, console_link
|
36
36
|
from .hashing import hash, hash_obj
|
37
37
|
from .measure_duration import measure_duration
|
relib/system.py
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
import json
|
2
|
+
import os
|
3
|
+
from pathlib import Path
|
4
|
+
from typing import Any
|
5
|
+
|
6
|
+
def read_json(path: Path) -> Any:
|
7
|
+
with path.open("r") as f:
|
8
|
+
return json.load(f)
|
9
|
+
|
10
|
+
def write_json(path: Path, obj: Any) -> None:
|
11
|
+
with path.open("w") as f:
|
12
|
+
return json.dump(obj, f)
|
13
|
+
|
14
|
+
def clear_console() -> None:
|
15
|
+
os.system("cls" if os.name == "nt" else "clear")
|
16
|
+
|
17
|
+
def console_link(text, url) -> str:
|
18
|
+
return f"\033]8;;{url}\033\\{text}\033]8;;\033\\"
|
relib/utils.py
CHANGED
@@ -1,14 +1,7 @@
|
|
1
|
-
import os
|
2
1
|
import re
|
3
2
|
from typing import Iterable, Callable, Any, overload
|
4
3
|
from itertools import chain
|
5
4
|
|
6
|
-
def clear_console():
|
7
|
-
os.system("cls" if os.name == "nt" else "clear")
|
8
|
-
|
9
|
-
def console_link(text, url):
|
10
|
-
return f"\033]8;;{url}\033\\{text}\033]8;;\033\\"
|
11
|
-
|
12
5
|
def non_none[T](obj: T | None) -> T:
|
13
6
|
assert obj is not None
|
14
7
|
return obj
|
@@ -25,8 +18,8 @@ def list_split[T](l: list[T], sep: T) -> list[list[T]]:
|
|
25
18
|
for start, end in ranges
|
26
19
|
]
|
27
20
|
|
28
|
-
def drop_none[T](
|
29
|
-
return [x for x in
|
21
|
+
def drop_none[T](iterable: Iterable[T | None]) -> list[T]:
|
22
|
+
return [x for x in iterable if x is not None]
|
30
23
|
|
31
24
|
def distinct[T](items: Iterable[T]) -> list[T]:
|
32
25
|
return list(dict.fromkeys(items))
|
@@ -34,8 +27,8 @@ def distinct[T](items: Iterable[T]) -> list[T]:
|
|
34
27
|
def first[T](iterable: Iterable[T]) -> T | None:
|
35
28
|
return next(iter(iterable), None)
|
36
29
|
|
37
|
-
def move_value[T](
|
38
|
-
l = list(
|
30
|
+
def move_value[T](iterable: Iterable[T], from_i: int, to_i: int) -> list[T]:
|
31
|
+
l = list(iterable)
|
39
32
|
l.insert(to_i, l.pop(from_i))
|
40
33
|
return l
|
41
34
|
|
@@ -76,8 +69,8 @@ def merge_dicts[T, K](*dicts: dict[K, T]) -> dict[K, T]:
|
|
76
69
|
result.update(d)
|
77
70
|
return result
|
78
71
|
|
79
|
-
def intersect[T](*
|
80
|
-
return list(set.intersection(*map(set,
|
72
|
+
def intersect[T](*iterables: Iterable[T]) -> list[T]:
|
73
|
+
return list(set.intersection(*map(set, iterables)))
|
81
74
|
|
82
75
|
def ensure_tuple[T](value: T | tuple[T, ...]) -> tuple[T, ...]:
|
83
76
|
return value if isinstance(value, tuple) else (value,)
|
@@ -101,8 +94,8 @@ def dict_by[T, K](keys: Iterable[K], values: Iterable[T]) -> dict[K, T]:
|
|
101
94
|
def tuple_by[T, K](d: dict[K, T], keys: Iterable[K]) -> tuple[T, ...]:
|
102
95
|
return tuple(d[key] for key in keys)
|
103
96
|
|
104
|
-
def flatten[T](
|
105
|
-
return list(chain.from_iterable(
|
97
|
+
def flatten[T](iterable: Iterable[Iterable[T]]) -> list[T]:
|
98
|
+
return list(chain.from_iterable(iterable))
|
106
99
|
|
107
100
|
def transpose(tuples, default_num_returns=0):
|
108
101
|
output = tuple(zip(*tuples))
|
@@ -163,6 +156,10 @@ def get_at[T](d: dict, keys: Iterable[Any], default: T) -> T:
|
|
163
156
|
return default
|
164
157
|
return as_any(d)
|
165
158
|
|
159
|
+
def for_each[T](func: Callable[[T], Any], iterable: Iterable[T]) -> None:
|
160
|
+
for item in iterable:
|
161
|
+
func(item)
|
162
|
+
|
166
163
|
def sized_partitions[T](values: Iterable[T], part_size: int) -> list[list[T]]:
|
167
164
|
# "chunk"
|
168
165
|
if not isinstance(values, list):
|
@@ -1,9 +1,9 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: relib
|
3
|
-
Version: 1.2.
|
3
|
+
Version: 1.2.3
|
4
4
|
Project-URL: Repository, https://github.com/Reddan/relib.git
|
5
5
|
Author: Hampus Hallman
|
6
|
-
License: Copyright
|
6
|
+
License: Copyright 2018-2025 Hampus Hallman
|
7
7
|
|
8
8
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
9
9
|
|
@@ -0,0 +1,9 @@
|
|
1
|
+
relib/__init__.py,sha256=dLFft8umAfLeZfTiecZ2Cx_-C-nKoBepUk-aWivI5ZE,627
|
2
|
+
relib/hashing.py,sha256=DB_fnkj0ls01FgZbf4nPFHl4EBU8X_0OrmDvty4HlRE,6020
|
3
|
+
relib/measure_duration.py,sha256=LCTo_D_qReNprD3fhtJ0daeWycS6xQE_cwxeg2_h0xo,456
|
4
|
+
relib/system.py,sha256=H-SJccCVLNTDhWTT5jo1NFUiQJzHv2Z1xvq0OVrnJcM,431
|
5
|
+
relib/utils.py,sha256=6Y_77KeejooPa54Z57EwPbNVvnFncmGay-VBbv4gAQQ,6905
|
6
|
+
relib-1.2.3.dist-info/METADATA,sha256=SrcjKfhYBKtDMGjdZqmwLsgm5I3hln8Q4ZW2FtFHz80,1295
|
7
|
+
relib-1.2.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
8
|
+
relib-1.2.3.dist-info/licenses/LICENSE,sha256=9xVsdtv_-uSyY9Xl9yujwAPm4-mjcCLeVy-ljwXEWbo,1059
|
9
|
+
relib-1.2.3.dist-info/RECORD,,
|
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright
|
1
|
+
Copyright 2018-2025 Hampus Hallman
|
2
2
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
4
|
|
relib-1.2.1.dist-info/RECORD
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
relib/__init__.py,sha256=TPvX5ey_D4bjzIqp5HqAUX4V7IXreJhY7T2-GuATHLg,577
|
2
|
-
relib/hashing.py,sha256=DB_fnkj0ls01FgZbf4nPFHl4EBU8X_0OrmDvty4HlRE,6020
|
3
|
-
relib/measure_duration.py,sha256=LCTo_D_qReNprD3fhtJ0daeWycS6xQE_cwxeg2_h0xo,456
|
4
|
-
relib/utils.py,sha256=tFO2FnisciRCrcTO45sm8SnzxGXzHd6u6r4efOtOQ7k,6906
|
5
|
-
relib-1.2.1.dist-info/METADATA,sha256=3izGnxrJlKPmUX-ezjdM6rUyCflyVyBToMfXb4pnCBs,1290
|
6
|
-
relib-1.2.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
7
|
-
relib-1.2.1.dist-info/licenses/LICENSE,sha256=t9LfkVbmcvZjP0x3Sq-jR38UfTNbNtRQvc0Q8HWmLak,1054
|
8
|
-
relib-1.2.1.dist-info/RECORD,,
|
File without changes
|