aletk 0.1.6__py3-none-any.whl → 0.1.8__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.
- aletk/ResultMonad.py +12 -12
- aletk/_version.py +16 -3
- aletk/utils.py +6 -10
- aletk-0.1.8.dist-info/METADATA +71 -0
- aletk-0.1.8.dist-info/RECORD +11 -0
- {aletk-0.1.6.dist-info → aletk-0.1.8.dist-info}/WHEEL +1 -1
- aletk-0.1.6.dist-info/METADATA +0 -27
- aletk-0.1.6.dist-info/RECORD +0 -11
- {aletk-0.1.6.dist-info → aletk-0.1.8.dist-info/licenses}/LICENSE +0 -0
- {aletk-0.1.6.dist-info → aletk-0.1.8.dist-info}/top_level.txt +0 -0
aletk/ResultMonad.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from dataclasses import dataclass
|
|
2
2
|
from logging import Logger
|
|
3
|
-
from typing import
|
|
3
|
+
from typing import Callable
|
|
4
4
|
from functools import wraps
|
|
5
5
|
|
|
6
6
|
|
|
@@ -147,15 +147,15 @@ def runwrap_or[T](result: TResult[T], default: T) -> T:
|
|
|
147
147
|
return default
|
|
148
148
|
|
|
149
149
|
|
|
150
|
-
def try_except_wrapper[T](logger: Logger) -> Callable[[Callable[
|
|
150
|
+
def try_except_wrapper[T, **P](logger: Logger) -> Callable[[Callable[P, T]], Callable[P, TResult[T]]]:
|
|
151
151
|
"""
|
|
152
152
|
Decorator that wraps a function in a try-except block, logging any errors that occur. The wrapped function will then always return a Ok[T] or Err as output.
|
|
153
153
|
|
|
154
154
|
"""
|
|
155
155
|
|
|
156
|
-
def decorator(func: Callable[
|
|
156
|
+
def decorator(func: Callable[P, T]) -> Callable[P, TResult[T]]:
|
|
157
157
|
@wraps(func)
|
|
158
|
-
def wrapper(*args:
|
|
158
|
+
def wrapper(*args: P.args, **kwargs: P.kwargs) -> TResult[T]:
|
|
159
159
|
try:
|
|
160
160
|
# logger.debug(f"Calling function '{func.__name__}' with args: {args} and kwargs: {kwargs}")
|
|
161
161
|
result = func(*args, **kwargs)
|
|
@@ -213,12 +213,12 @@ def runwrap_soft[T](result: TResult[T]) -> T | Err:
|
|
|
213
213
|
return Err(message=msg, code=code)
|
|
214
214
|
|
|
215
215
|
|
|
216
|
-
def funwrap[T](func: Callable[
|
|
216
|
+
def funwrap[T, **P](func: Callable[P, TResult[T]]) -> Callable[P, T | Err]:
|
|
217
217
|
"""
|
|
218
218
|
Wrap a function that returns a Result in a function that returns the data inside the Result.
|
|
219
219
|
"""
|
|
220
220
|
|
|
221
|
-
def wrapper(*args:
|
|
221
|
+
def wrapper(*args: P.args, **kwargs: P.kwargs) -> T | Err:
|
|
222
222
|
result = func(*args, **kwargs)
|
|
223
223
|
match result:
|
|
224
224
|
case Ok(out=data):
|
|
@@ -231,14 +231,14 @@ def funwrap[T](func: Callable[..., TResult[T]]) -> Callable[..., T | Err]:
|
|
|
231
231
|
return wrapper
|
|
232
232
|
|
|
233
233
|
|
|
234
|
-
def main_try_except_wrapper[T](logger: Logger) -> Callable[[Callable[
|
|
234
|
+
def main_try_except_wrapper[T, **P](logger: Logger) -> Callable[[Callable[P, T]], Callable[P, TResult[T]]]:
|
|
235
235
|
"""
|
|
236
236
|
Decorator that wraps a function in a try-except block, logging any errors that occur. The wrapped function will then always return a Ok[T] or Err as output.
|
|
237
237
|
"""
|
|
238
238
|
|
|
239
|
-
def decorator(func: Callable[
|
|
239
|
+
def decorator(func: Callable[P, T]) -> Callable[P, TResult[T]]:
|
|
240
240
|
@wraps(func)
|
|
241
|
-
def wrapper(*args:
|
|
241
|
+
def wrapper(*args: P.args, **kwargs: P.kwargs) -> TResult[T]:
|
|
242
242
|
try:
|
|
243
243
|
result = func(*args, **kwargs)
|
|
244
244
|
|
|
@@ -262,14 +262,14 @@ def main_try_except_wrapper[T](logger: Logger) -> Callable[[Callable[..., T]], C
|
|
|
262
262
|
return decorator
|
|
263
263
|
|
|
264
264
|
|
|
265
|
-
def light_error_handler[T](debug: bool = False) -> Callable[[Callable[
|
|
265
|
+
def light_error_handler[T, **P](debug: bool = False) -> Callable[[Callable[P, T]], Callable[P, T]]:
|
|
266
266
|
"""
|
|
267
267
|
Decorator that wraps a function in a try-except block, and returns a better error message if an exception is raised.
|
|
268
268
|
"""
|
|
269
269
|
|
|
270
|
-
def decorator(func: Callable[
|
|
270
|
+
def decorator(func: Callable[P, T]) -> Callable[P, T]:
|
|
271
271
|
@wraps(func)
|
|
272
|
-
def wrapper(*args:
|
|
272
|
+
def wrapper(*args: P.args, **kwargs: P.kwargs) -> T:
|
|
273
273
|
try:
|
|
274
274
|
return func(*args, **kwargs)
|
|
275
275
|
|
aletk/_version.py
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
# file generated by setuptools-scm
|
|
2
2
|
# don't change, don't track in version control
|
|
3
3
|
|
|
4
|
-
__all__ = [
|
|
4
|
+
__all__ = [
|
|
5
|
+
"__version__",
|
|
6
|
+
"__version_tuple__",
|
|
7
|
+
"version",
|
|
8
|
+
"version_tuple",
|
|
9
|
+
"__commit_id__",
|
|
10
|
+
"commit_id",
|
|
11
|
+
]
|
|
5
12
|
|
|
6
13
|
TYPE_CHECKING = False
|
|
7
14
|
if TYPE_CHECKING:
|
|
@@ -9,13 +16,19 @@ if TYPE_CHECKING:
|
|
|
9
16
|
from typing import Union
|
|
10
17
|
|
|
11
18
|
VERSION_TUPLE = Tuple[Union[int, str], ...]
|
|
19
|
+
COMMIT_ID = Union[str, None]
|
|
12
20
|
else:
|
|
13
21
|
VERSION_TUPLE = object
|
|
22
|
+
COMMIT_ID = object
|
|
14
23
|
|
|
15
24
|
version: str
|
|
16
25
|
__version__: str
|
|
17
26
|
__version_tuple__: VERSION_TUPLE
|
|
18
27
|
version_tuple: VERSION_TUPLE
|
|
28
|
+
commit_id: COMMIT_ID
|
|
29
|
+
__commit_id__: COMMIT_ID
|
|
19
30
|
|
|
20
|
-
__version__ = version = '0.1.
|
|
21
|
-
__version_tuple__ = version_tuple = (0, 1,
|
|
31
|
+
__version__ = version = '0.1.8'
|
|
32
|
+
__version_tuple__ = version_tuple = (0, 1, 8)
|
|
33
|
+
|
|
34
|
+
__commit_id__ = commit_id = None
|
aletk/utils.py
CHANGED
|
@@ -14,8 +14,8 @@ def get_logger(name: str) -> logging.Logger:
|
|
|
14
14
|
You can also pass the environment variables 'LOGGING_LEVEL' or 'LOG_LEVEL' to set the logging level. If none is passed, the default is 'INFO'.
|
|
15
15
|
"""
|
|
16
16
|
|
|
17
|
-
if
|
|
18
|
-
raise ValueError("Utils::GetLogger::Argument 'name' has to be a non
|
|
17
|
+
if not name:
|
|
18
|
+
raise ValueError("Utils::GetLogger::Argument 'name' has to be a non-empty string.")
|
|
19
19
|
|
|
20
20
|
logging_level = getenv("LOGGING_LEVEL", "")
|
|
21
21
|
|
|
@@ -39,11 +39,7 @@ def get_logger(name: str) -> logging.Logger:
|
|
|
39
39
|
def remove_extra_whitespace(string: str) -> str:
|
|
40
40
|
"""
|
|
41
41
|
Remove extra whitespace from a string. This version removes all newlines, tabs, carriage returns, trailing and leading whitespace, and multiple spaces in a row.
|
|
42
|
-
|
|
43
|
-
If the input is None or not a string, a ValueError is raised.
|
|
44
42
|
"""
|
|
45
|
-
if string is None or not isinstance(string, str):
|
|
46
|
-
raise ValueError("Utils::RemoveExtraWhiteSpace::Argument string has to be a (non None) string.")
|
|
47
43
|
|
|
48
44
|
cleaned_string = " ".join(string.split()).strip()
|
|
49
45
|
|
|
@@ -69,8 +65,8 @@ def fuzzy_match_score(
|
|
|
69
65
|
If any of the inputs is None or not a string, a ValueError is raised.
|
|
70
66
|
"""
|
|
71
67
|
|
|
72
|
-
if
|
|
73
|
-
raise ValueError(f"Utils::FuzzyMatchScore::Arguments have to be non
|
|
68
|
+
if not str1 or not str2:
|
|
69
|
+
raise ValueError(f"Utils::FuzzyMatchScore::Arguments have to be non-empty strings. Got:\n'{str1}'\n'{str2}'")
|
|
74
70
|
|
|
75
71
|
score = fuzz.token_sort_ratio(str1, str2)
|
|
76
72
|
|
|
@@ -111,7 +107,7 @@ def pretty_format_frozenset(fs: FrozenSet[object]) -> str:
|
|
|
111
107
|
"""
|
|
112
108
|
Pretty format a FrozenSet object, to be used in logging or printing.
|
|
113
109
|
"""
|
|
114
|
-
if fs
|
|
110
|
+
if fs == frozenset():
|
|
115
111
|
return ""
|
|
116
112
|
return ", ".join(sorted([f"{item}" for item in fs]))
|
|
117
113
|
|
|
@@ -120,6 +116,6 @@ def dump_frozenset(fs: FrozenSet[object]) -> list[str]:
|
|
|
120
116
|
"""
|
|
121
117
|
Dump a FrozenSet object to a list of strings.
|
|
122
118
|
"""
|
|
123
|
-
if fs
|
|
119
|
+
if fs == frozenset():
|
|
124
120
|
return []
|
|
125
121
|
return sorted([f"{item}" for item in fs])
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: aletk
|
|
3
|
+
Version: 0.1.8
|
|
4
|
+
Summary: Collection of general purpose tools to work with Python
|
|
5
|
+
Author-email: Luis Alejandro Bordo García <bgluiszz@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Repository, https://gitlab.com/alebg/aletk
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Typing :: Typed
|
|
14
|
+
Requires-Python: >=3.13
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Requires-Dist: fuzzywuzzy
|
|
18
|
+
Requires-Dist: python-Levenshtein
|
|
19
|
+
Provides-Extra: dev
|
|
20
|
+
Requires-Dist: mypy; extra == "dev"
|
|
21
|
+
Requires-Dist: black; extra == "dev"
|
|
22
|
+
Requires-Dist: pytest; extra == "dev"
|
|
23
|
+
Requires-Dist: autoflake; extra == "dev"
|
|
24
|
+
Requires-Dist: jupyter; extra == "dev"
|
|
25
|
+
Dynamic: license-file
|
|
26
|
+
|
|
27
|
+
# Ale's Python Toolkit
|
|
28
|
+
|
|
29
|
+
This is a collection of tools that I use to make my life easier when working with Python. I hope you find them useful too!
|
|
30
|
+
|
|
31
|
+
## Development Setup
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
git clone git@gitlab.com:alebg/aletk.git
|
|
35
|
+
cd aletk
|
|
36
|
+
python -m venv .venv
|
|
37
|
+
source .venv/bin/activate
|
|
38
|
+
pip install -e ".[dev]"
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Code Quality
|
|
42
|
+
|
|
43
|
+
This project uses strict mypy type checking:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
mypy src/aletk/
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Making a Release
|
|
50
|
+
|
|
51
|
+
Versioning is handled automatically by `setuptools_scm` — the version is derived from git tags. The CI/CD pipeline (GitLab CI) triggers only on semantic version tags.
|
|
52
|
+
|
|
53
|
+
1. Commit your changes and merge to `main`
|
|
54
|
+
2. Tag the commit with a semver tag:
|
|
55
|
+
```bash
|
|
56
|
+
git tag v0.X.Y
|
|
57
|
+
git push origin v0.X.Y
|
|
58
|
+
```
|
|
59
|
+
3. The CI pipeline will automatically: build the package, publish to PyPI, and create a GitLab release
|
|
60
|
+
|
|
61
|
+
## Updating Client Projects
|
|
62
|
+
|
|
63
|
+
After a new release is published to PyPI, update the dependency in client projects:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
# If using poetry
|
|
67
|
+
poetry update aletk
|
|
68
|
+
|
|
69
|
+
# If using pip
|
|
70
|
+
pip install --upgrade aletk
|
|
71
|
+
```
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
aletk/ResultMonad.py,sha256=YGsCAPQ7yCmZhrUj7rKFJj3SImN66iOFKxGm9qo5TVk,8079
|
|
2
|
+
aletk/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
+
aletk/_version.py,sha256=Zaz3s9gl_rzsS46-ymJOALojMxviW77EJq_agE8knLk,704
|
|
4
|
+
aletk/adapters.py,sha256=9IYfIg1UYC0FbzWonMWdrUDgtVaV-q5NZKrRQubhBPw,659
|
|
5
|
+
aletk/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
+
aletk/utils.py,sha256=52OarfFAzEGXVnZBr0iF3pOaHizqApkemH3OGbv56J8,3449
|
|
7
|
+
aletk-0.1.8.dist-info/licenses/LICENSE,sha256=hZFMbARrXo4zfuo80-Sg3-FT5_ceiSDf0QpjgJoUdGc,1085
|
|
8
|
+
aletk-0.1.8.dist-info/METADATA,sha256=Nl0t0Rme1QwT6gkKiXog6jN9poezdLiMtWcazh_uCnw,1937
|
|
9
|
+
aletk-0.1.8.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
10
|
+
aletk-0.1.8.dist-info/top_level.txt,sha256=LYDb8QWbh4W4hIkF0TVg5ITKEsaj-pb_xcYQRGzLqUU,6
|
|
11
|
+
aletk-0.1.8.dist-info/RECORD,,
|
aletk-0.1.6.dist-info/METADATA
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.2
|
|
2
|
-
Name: aletk
|
|
3
|
-
Version: 0.1.6
|
|
4
|
-
Summary: Collection of general purpose tools to work with Python
|
|
5
|
-
Author-email: Luis Alejandro Bordo García <bgluiszz@gmail.com>
|
|
6
|
-
License: MIT
|
|
7
|
-
Project-URL: Repository, https://gitlab.com/alebg/aletk
|
|
8
|
-
Classifier: Programming Language :: Python :: 3
|
|
9
|
-
Classifier: Programming Language :: Python :: 3.13
|
|
10
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
-
Classifier: Operating System :: OS Independent
|
|
12
|
-
Classifier: Intended Audience :: Developers
|
|
13
|
-
Classifier: Typing :: Typed
|
|
14
|
-
Requires-Python: >=3.13
|
|
15
|
-
Description-Content-Type: text/markdown
|
|
16
|
-
License-File: LICENSE
|
|
17
|
-
Requires-Dist: fuzzywuzzy
|
|
18
|
-
Requires-Dist: python-Levenshtein
|
|
19
|
-
Provides-Extra: dev
|
|
20
|
-
Requires-Dist: mypy; extra == "dev"
|
|
21
|
-
Requires-Dist: black; extra == "dev"
|
|
22
|
-
Requires-Dist: pytest; extra == "dev"
|
|
23
|
-
Requires-Dist: jupyter; extra == "dev"
|
|
24
|
-
|
|
25
|
-
# Ale's Python Toolkit
|
|
26
|
-
|
|
27
|
-
This is a collection of tools that I use to make my life easier when working with Python. I hope you find them useful too!
|
aletk-0.1.6.dist-info/RECORD
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
aletk/ResultMonad.py,sha256=PcEyLm5r1OFtbPuD_53_syEeK5wXEXA9kAGabb7IDt4,8060
|
|
2
|
-
aletk/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
-
aletk/_version.py,sha256=ESbJO0YD7TYfOUv_WDIJJgWELGepEWsoyhqVifEcXPA,511
|
|
4
|
-
aletk/adapters.py,sha256=9IYfIg1UYC0FbzWonMWdrUDgtVaV-q5NZKrRQubhBPw,659
|
|
5
|
-
aletk/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
-
aletk/utils.py,sha256=nvG-fRt4qIr-hBOFcpLN27mC0EEp877k3sf72O1rBE0,3800
|
|
7
|
-
aletk-0.1.6.dist-info/LICENSE,sha256=hZFMbARrXo4zfuo80-Sg3-FT5_ceiSDf0QpjgJoUdGc,1085
|
|
8
|
-
aletk-0.1.6.dist-info/METADATA,sha256=mrIbglrstdqk4f5azxBh5HqSVpbdbTvpQgWhiKh_CAA,980
|
|
9
|
-
aletk-0.1.6.dist-info/WHEEL,sha256=52BFRY2Up02UkjOa29eZOS2VxUrpPORXg1pkohGGUS8,91
|
|
10
|
-
aletk-0.1.6.dist-info/top_level.txt,sha256=LYDb8QWbh4W4hIkF0TVg5ITKEsaj-pb_xcYQRGzLqUU,6
|
|
11
|
-
aletk-0.1.6.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|