relib 0.2.4__py3-none-any.whl → 1.0.1__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 CHANGED
@@ -1,5 +1,26 @@
1
- from .utils import list_split, drop_none, distinct, find, transpose_dict, make_combinations_by_dict, \
2
- merge_dicts, intersect, ensure_tuple, omit, dict_by, tuple_by, flatten, transpose, deepen_dict, group
1
+ from .utils import (
2
+ list_split,
3
+ drop_none,
4
+ distinct,
5
+ find,
6
+ transpose_dict,
7
+ make_combinations_by_dict,
8
+ merge_dicts,
9
+ intersect,
10
+ ensure_tuple,
11
+ omit,
12
+ dict_by,
13
+ tuple_by,
14
+ flatten,
15
+ transpose,
16
+ map_dict,
17
+ deepen_dict,
18
+ group,
19
+ sized_partitions,
20
+ num_partitions,
21
+ StrFilter,
22
+ str_filterer,
23
+ )
3
24
  from .raypipe import raypipe
4
25
  from .hashing import hash
5
26
  from .measure_duration import measure_duration
relib/utils.py CHANGED
@@ -1,17 +1,18 @@
1
- from typing import TypeVar, Union, Iterable, Any
1
+ from typing import TypeVar, Union, Iterable, Callable
2
+ import re
2
3
 
3
4
  T = TypeVar('T')
4
5
  U = TypeVar('U')
6
+ K = TypeVar('K')
5
7
 
6
8
  def list_split(l: list[T], sep: T) -> list[list[T]]:
7
9
  l = [sep, *l, sep]
8
10
  split_at = [i for i, x in enumerate(l) if x is sep]
9
11
  ranges = list(zip(split_at[0:-1], split_at[1:]))
10
- result: Any = [
12
+ return [
11
13
  l[start + 1:end]
12
14
  for start, end in ranges
13
15
  ]
14
- return result
15
16
 
16
17
  def drop_none(l: Iterable[Union[T, None]]) -> list[T]:
17
18
  return [x for x in l if x is not None]
@@ -87,6 +88,9 @@ def transpose(tuples, default_num_returns=0):
87
88
  return ([],) * default_num_returns
88
89
  return tuple(map(list, result))
89
90
 
91
+ def map_dict(fn: Callable[[T], U], d: dict[K, T]) -> dict[K, U]:
92
+ return {key: fn(value) for key, value in d.items()}
93
+
90
94
  def deepen_dict(d):
91
95
  result = {}
92
96
  for (*tail, head), value in d.items():
@@ -113,3 +117,30 @@ def get_at(d, keys, default):
113
117
  except KeyError:
114
118
  return default
115
119
  return d
120
+
121
+ def sized_partitions(values: Iterable[T], part_size: int) -> list[list[T]]:
122
+ if not isinstance(values, list):
123
+ values = list(values)
124
+ num_parts = (len(values) / part_size).__ceil__()
125
+ return [values[i * part_size : (i + 1) * part_size] for i in range(num_parts)]
126
+
127
+ def num_partitions(values: Iterable[T], num_parts: int) -> list[list[T]]:
128
+ if not isinstance(values, list):
129
+ values = list(values)
130
+ part_size = (len(values) / num_parts).__ceil__()
131
+ return [values[i * part_size : (i + 1) * part_size] for i in range(num_parts)]
132
+
133
+ StrFilter = Callable[[str], bool]
134
+
135
+ def str_filterer(
136
+ include_patterns: list[re.Pattern[str]] = [],
137
+ exclude_patterns: list[re.Pattern[str]] = [],
138
+ ) -> StrFilter:
139
+ def str_filter(string: str) -> bool:
140
+ if any(pattern.search(string) for pattern in exclude_patterns):
141
+ return False
142
+ if not include_patterns:
143
+ return True
144
+ return any(pattern.search(string) for pattern in include_patterns)
145
+
146
+ return str_filter
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: relib
3
- Version: 0.2.4
3
+ Version: 1.0.1
4
4
  Home-page: https://github.com/Reddan/relib
5
5
  Author: Hampus Hallman
6
6
  Author-email: me@hampushallman.com
@@ -0,0 +1,10 @@
1
+ relib/__init__.py,sha256=Mcy5O19R8A7zfdGeXFhrnLfqNlCWs-8LnnHtV0E7GnA,421
2
+ relib/hashing.py,sha256=6iAPRiJI_4jaSooZRFJnqK2limXqTmErzcwpd050LAA,8943
3
+ relib/measure_duration.py,sha256=jJa5Kh5FxaBysS__nkwqcnTt8Uc2niLucXfTzFE0j-E,555
4
+ relib/raypipe.py,sha256=ynEoXs1dnD-360_uQC8v89xjiilt3knpocXpFaQ3plA,1905
5
+ relib/utils.py,sha256=n2b5ntvgOIEwiwbX75hcD_-QEJii8Tn301-Afl7Z-RI,4100
6
+ relib-1.0.1.dist-info/LICENSE.txt,sha256=t9LfkVbmcvZjP0x3Sq-jR38UfTNbNtRQvc0Q8HWmLak,1054
7
+ relib-1.0.1.dist-info/METADATA,sha256=pXhcA9hlsGXnJrbTrceC1hM25-MdlFDUUOjq5T99khc,260
8
+ relib-1.0.1.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
9
+ relib-1.0.1.dist-info/top_level.txt,sha256=Yc96FwkbRYj4AQVatga8uK4hH9ATKI9XIyEH_1ba6KQ,6
10
+ relib-1.0.1.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.38.4)
2
+ Generator: bdist_wheel (0.40.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,10 +0,0 @@
1
- relib/__init__.py,sha256=OmN7DRgA2rYN0XMamE4P3rJPGJIFpnkFQoDXn-GK6sU,309
2
- relib/hashing.py,sha256=6iAPRiJI_4jaSooZRFJnqK2limXqTmErzcwpd050LAA,8943
3
- relib/measure_duration.py,sha256=jJa5Kh5FxaBysS__nkwqcnTt8Uc2niLucXfTzFE0j-E,555
4
- relib/raypipe.py,sha256=ynEoXs1dnD-360_uQC8v89xjiilt3knpocXpFaQ3plA,1905
5
- relib/utils.py,sha256=t2QqpqtM9MxiW1CVCy6yN1Mr1BmvBcIWMBm0b52uKp0,3002
6
- relib-0.2.4.dist-info/LICENSE.txt,sha256=t9LfkVbmcvZjP0x3Sq-jR38UfTNbNtRQvc0Q8HWmLak,1054
7
- relib-0.2.4.dist-info/METADATA,sha256=I4zwI2bACPcmUXcKt6Tct_HhyZC4beXnqDGG1wX4F-s,260
8
- relib-0.2.4.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
9
- relib-0.2.4.dist-info/top_level.txt,sha256=Yc96FwkbRYj4AQVatga8uK4hH9ATKI9XIyEH_1ba6KQ,6
10
- relib-0.2.4.dist-info/RECORD,,