aletk 0.1.5__py3-none-any.whl → 0.1.7__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 CHANGED
@@ -1,6 +1,6 @@
1
1
  from dataclasses import dataclass
2
2
  from logging import Logger
3
- from typing import Any, Callable, NamedTuple
3
+ from typing import Callable
4
4
  from functools import wraps
5
5
 
6
6
 
@@ -29,10 +29,16 @@ class Err:
29
29
  A message describing the error.
30
30
  code : int
31
31
  A code that can be used to handle different error cases.
32
+ error_type : str, optional
33
+ A string describing the type of error that occurred.
34
+ error_trace : str, optional
35
+ A string describing the trace of the error that occurred.
32
36
  """
33
37
 
34
38
  message: str
35
39
  code: int
40
+ error_type: str | None = None
41
+ error_trace: str | None = None
36
42
 
37
43
 
38
44
  type TResult[T] = Ok[T] | Err
@@ -141,15 +147,15 @@ def runwrap_or[T](result: TResult[T], default: T) -> T:
141
147
  return default
142
148
 
143
149
 
144
- def try_except_wrapper[T](logger: Logger) -> Callable[[Callable[..., T]], Callable[..., TResult[T]]]:
150
+ def try_except_wrapper[T, **P](logger: Logger) -> Callable[[Callable[P, T]], Callable[P, TResult[T]]]:
145
151
  """
146
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.
147
153
 
148
154
  """
149
155
 
150
- def decorator(func: Callable[..., T]) -> Callable[..., TResult[T]]:
156
+ def decorator(func: Callable[P, T]) -> Callable[P, TResult[T]]:
151
157
  @wraps(func)
152
- def wrapper(*args: Any, **kwargs: Any) -> TResult[T]:
158
+ def wrapper(*args: P.args, **kwargs: P.kwargs) -> TResult[T]:
153
159
  try:
154
160
  # logger.debug(f"Calling function '{func.__name__}' with args: {args} and kwargs: {kwargs}")
155
161
  result = func(*args, **kwargs)
@@ -207,12 +213,12 @@ def runwrap_soft[T](result: TResult[T]) -> T | Err:
207
213
  return Err(message=msg, code=code)
208
214
 
209
215
 
210
- def funwrap[T](func: Callable[..., TResult[T]]) -> Callable[..., T | Err]:
216
+ def funwrap[T, **P](func: Callable[P, TResult[T]]) -> Callable[P, T | Err]:
211
217
  """
212
218
  Wrap a function that returns a Result in a function that returns the data inside the Result.
213
219
  """
214
220
 
215
- def wrapper(*args: Any, **kwargs: Any) -> T | Err:
221
+ def wrapper(*args: P.args, **kwargs: P.kwargs) -> T | Err:
216
222
  result = func(*args, **kwargs)
217
223
  match result:
218
224
  case Ok(out=data):
@@ -225,14 +231,14 @@ def funwrap[T](func: Callable[..., TResult[T]]) -> Callable[..., T | Err]:
225
231
  return wrapper
226
232
 
227
233
 
228
- def main_try_except_wrapper[T](logger: Logger) -> Callable[[Callable[..., T]], Callable[..., TResult[T]]]:
234
+ def main_try_except_wrapper[T, **P](logger: Logger) -> Callable[[Callable[P, T]], Callable[P, TResult[T]]]:
229
235
  """
230
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.
231
237
  """
232
238
 
233
- def decorator(func: Callable[..., T]) -> Callable[..., TResult[T]]:
239
+ def decorator(func: Callable[P, T]) -> Callable[P, TResult[T]]:
234
240
  @wraps(func)
235
- def wrapper(*args: Any, **kwargs: Any) -> TResult[T]:
241
+ def wrapper(*args: P.args, **kwargs: P.kwargs) -> TResult[T]:
236
242
  try:
237
243
  result = func(*args, **kwargs)
238
244
 
@@ -256,14 +262,14 @@ def main_try_except_wrapper[T](logger: Logger) -> Callable[[Callable[..., T]], C
256
262
  return decorator
257
263
 
258
264
 
259
- def light_error_handler[T](debug: bool = False) -> Callable[[Callable[..., T]], Callable[..., T]]:
265
+ def light_error_handler[T, **P](debug: bool = False) -> Callable[[Callable[P, T]], Callable[P, T]]:
260
266
  """
261
267
  Decorator that wraps a function in a try-except block, and returns a better error message if an exception is raised.
262
268
  """
263
269
 
264
- def decorator(func: Callable[..., T]) -> Callable[..., T]:
270
+ def decorator(func: Callable[P, T]) -> Callable[P, T]:
265
271
  @wraps(func)
266
- def wrapper(*args: Any, **kwargs: Any) -> T:
272
+ def wrapper(*args: P.args, **kwargs: P.kwargs) -> T:
267
273
  try:
268
274
  return func(*args, **kwargs)
269
275
 
aletk/_version.py CHANGED
@@ -1,16 +1,34 @@
1
- # file generated by setuptools_scm
1
+ # file generated by setuptools-scm
2
2
  # don't change, don't track in version control
3
+
4
+ __all__ = [
5
+ "__version__",
6
+ "__version_tuple__",
7
+ "version",
8
+ "version_tuple",
9
+ "__commit_id__",
10
+ "commit_id",
11
+ ]
12
+
3
13
  TYPE_CHECKING = False
4
14
  if TYPE_CHECKING:
5
- from typing import Tuple, Union
15
+ from typing import Tuple
16
+ from typing import Union
17
+
6
18
  VERSION_TUPLE = Tuple[Union[int, str], ...]
19
+ COMMIT_ID = Union[str, None]
7
20
  else:
8
21
  VERSION_TUPLE = object
22
+ COMMIT_ID = object
9
23
 
10
24
  version: str
11
25
  __version__: str
12
26
  __version_tuple__: VERSION_TUPLE
13
27
  version_tuple: VERSION_TUPLE
28
+ commit_id: COMMIT_ID
29
+ __commit_id__: COMMIT_ID
30
+
31
+ __version__ = version = '0.1.7'
32
+ __version_tuple__ = version_tuple = (0, 1, 7)
14
33
 
15
- __version__ = version = '0.1.5'
16
- __version_tuple__ = version_tuple = (0, 1, 5)
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 name is None or not isinstance(name, str):
18
- raise ValueError("Utils::GetLogger::Argument 'name' has to be a non None string.")
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
 
@@ -42,8 +42,8 @@ def remove_extra_whitespace(string: str) -> str:
42
42
 
43
43
  If the input is None or not a string, a ValueError is raised.
44
44
  """
45
- if string is None or not isinstance(string, str):
46
- raise ValueError("Utils::RemoveExtraWhiteSpace::Argument string has to be a (non None) string.")
45
+ if not string:
46
+ raise ValueError("Utils::RemoveExtraWhiteSpace::Argument string has to be a non-empty string.")
47
47
 
48
48
  cleaned_string = " ".join(string.split()).strip()
49
49
 
@@ -69,8 +69,8 @@ def fuzzy_match_score(
69
69
  If any of the inputs is None or not a string, a ValueError is raised.
70
70
  """
71
71
 
72
- if str1 is None or str2 is None or not isinstance(str1, str) or not isinstance(str2, str):
73
- raise ValueError(f"Utils::FuzzyMatchScore::Arguments have to be non None strings. Got:\n'{str1}'\n'{str2}'")
72
+ if not str1 or not str2:
73
+ raise ValueError(f"Utils::FuzzyMatchScore::Arguments have to be non-empty strings. Got:\n'{str1}'\n'{str2}'")
74
74
 
75
75
  score = fuzz.token_sort_ratio(str1, str2)
76
76
 
@@ -111,7 +111,7 @@ def pretty_format_frozenset(fs: FrozenSet[object]) -> str:
111
111
  """
112
112
  Pretty format a FrozenSet object, to be used in logging or printing.
113
113
  """
114
- if fs is None or fs == frozenset():
114
+ if fs == frozenset():
115
115
  return ""
116
116
  return ", ".join(sorted([f"{item}" for item in fs]))
117
117
 
@@ -120,6 +120,6 @@ def dump_frozenset(fs: FrozenSet[object]) -> list[str]:
120
120
  """
121
121
  Dump a FrozenSet object to a list of strings.
122
122
  """
123
- if fs is None or fs == frozenset():
123
+ if fs == frozenset():
124
124
  return []
125
125
  return sorted([f"{item}" for item in fs])
@@ -0,0 +1,70 @@
1
+ Metadata-Version: 2.4
2
+ Name: aletk
3
+ Version: 0.1.7
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
+ Dynamic: license-file
25
+
26
+ # Ale's Python Toolkit
27
+
28
+ 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!
29
+
30
+ ## Development Setup
31
+
32
+ ```bash
33
+ git clone git@gitlab.com:alebg/aletk.git
34
+ cd aletk
35
+ python -m venv .venv
36
+ source .venv/bin/activate
37
+ pip install -e ".[dev]"
38
+ ```
39
+
40
+ ## Code Quality
41
+
42
+ This project uses strict mypy type checking:
43
+
44
+ ```bash
45
+ mypy src/aletk/
46
+ ```
47
+
48
+ ## Making a Release
49
+
50
+ 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.
51
+
52
+ 1. Commit your changes and merge to `main`
53
+ 2. Tag the commit with a semver tag:
54
+ ```bash
55
+ git tag v0.X.Y
56
+ git push origin v0.X.Y
57
+ ```
58
+ 3. The CI pipeline will automatically: build the package, publish to PyPI, and create a GitLab release
59
+
60
+ ## Updating Client Projects
61
+
62
+ After a new release is published to PyPI, update the dependency in client projects:
63
+
64
+ ```bash
65
+ # If using poetry
66
+ poetry update aletk
67
+
68
+ # If using pip
69
+ pip install --upgrade aletk
70
+ ```
@@ -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=szvPIs2C82UunpzuvVg3MbF4QhzbBYTsVJ8DmPfq6_E,704
4
+ aletk/adapters.py,sha256=9IYfIg1UYC0FbzWonMWdrUDgtVaV-q5NZKrRQubhBPw,659
5
+ aletk/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ aletk/utils.py,sha256=6d9jzephqICNKqlbbVAQqzrTgggbbU37QQRq-M2EWHY,3639
7
+ aletk-0.1.7.dist-info/licenses/LICENSE,sha256=hZFMbARrXo4zfuo80-Sg3-FT5_ceiSDf0QpjgJoUdGc,1085
8
+ aletk-0.1.7.dist-info/METADATA,sha256=fWFGPhLV9TyQfPzvOtNhuOJD5Yfv6fCyRKGjnNzUFLk,1896
9
+ aletk-0.1.7.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
10
+ aletk-0.1.7.dist-info/top_level.txt,sha256=LYDb8QWbh4W4hIkF0TVg5ITKEsaj-pb_xcYQRGzLqUU,6
11
+ aletk-0.1.7.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.6.0)
2
+ Generator: setuptools (80.10.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,27 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: aletk
3
- Version: 0.1.5
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!
@@ -1,11 +0,0 @@
1
- aletk/ResultMonad.py,sha256=v6BSIl7AHDfSqHypfLb5mBAQXAJQhXDLudbN8n2pK2s,7813
2
- aletk/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- aletk/_version.py,sha256=zBVX2byWL6NrFlwjvahpnvSqDsdtebZW0K9WM_cj20U,411
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.5.dist-info/LICENSE,sha256=hZFMbARrXo4zfuo80-Sg3-FT5_ceiSDf0QpjgJoUdGc,1085
8
- aletk-0.1.5.dist-info/METADATA,sha256=ZPHdVQ33SnLYUG98hiXaUPU_HCgrblO1HcbL8iScyDs,980
9
- aletk-0.1.5.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
10
- aletk-0.1.5.dist-info/top_level.txt,sha256=LYDb8QWbh4W4hIkF0TVg5ITKEsaj-pb_xcYQRGzLqUU,6
11
- aletk-0.1.5.dist-info/RECORD,,