pelutils 3.8.1__tar.gz → 3.8.3__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.
Files changed (47) hide show
  1. {pelutils-3.8.1 → pelutils-3.8.3}/PKG-INFO +1 -1
  2. {pelutils-3.8.1 → pelutils-3.8.3}/pelutils/__version__.py +1 -1
  3. {pelutils-3.8.1 → pelutils-3.8.3}/pelutils/datastorage2/__init__.py +7 -4
  4. {pelutils-3.8.1 → pelutils-3.8.3}/pelutils/logging/__init__.py +14 -9
  5. {pelutils-3.8.1 → pelutils-3.8.3}/pelutils.egg-info/PKG-INFO +1 -1
  6. {pelutils-3.8.1 → pelutils-3.8.3}/MANIFEST.in +0 -0
  7. {pelutils-3.8.1 → pelutils-3.8.3}/README.md +0 -0
  8. {pelutils-3.8.1 → pelutils-3.8.3}/pelutils/__init__.py +0 -0
  9. {pelutils-3.8.1 → pelutils-3.8.3}/pelutils/_c/__init__.py +0 -0
  10. {pelutils-3.8.1 → pelutils-3.8.3}/pelutils/_c/ds.c +0 -0
  11. {pelutils-3.8.1 → pelutils-3.8.3}/pelutils/_c/hashmap.c/LICENSE +0 -0
  12. {pelutils-3.8.1 → pelutils-3.8.3}/pelutils/_c/hashmap.c/hashmap.c +0 -0
  13. {pelutils-3.8.1 → pelutils-3.8.3}/pelutils/_c/hashmap.c/hashmap.h +0 -0
  14. {pelutils-3.8.1 → pelutils-3.8.3}/pelutils/_entry_points/__init__.py +0 -0
  15. {pelutils-3.8.1 → pelutils-3.8.3}/pelutils/_entry_points/linecounter.py +0 -0
  16. {pelutils-3.8.1 → pelutils-3.8.3}/pelutils/datastorage.py +0 -0
  17. {pelutils-3.8.1 → pelutils-3.8.3}/pelutils/datastorage2/_pretty_json.py +0 -0
  18. {pelutils-3.8.1 → pelutils-3.8.3}/pelutils/ds/__init__.py +0 -0
  19. {pelutils-3.8.1 → pelutils-3.8.3}/pelutils/ds/distributions.py +0 -0
  20. {pelutils-3.8.1 → pelutils-3.8.3}/pelutils/ds/plots.py +0 -0
  21. {pelutils-3.8.1 → pelutils-3.8.3}/pelutils/ds/stats.py +0 -0
  22. {pelutils-3.8.1 → pelutils-3.8.3}/pelutils/format.py +0 -0
  23. {pelutils-3.8.1 → pelutils-3.8.3}/pelutils/jsonl.py +0 -0
  24. {pelutils-3.8.1 → pelutils-3.8.3}/pelutils/logging/_rotate.py +0 -0
  25. {pelutils-3.8.1 → pelutils-3.8.3}/pelutils/logging/_utils.py +0 -0
  26. {pelutils-3.8.1 → pelutils-3.8.3}/pelutils/parser.py +0 -0
  27. {pelutils-3.8.1 → pelutils-3.8.3}/pelutils/pretty_json.py +0 -0
  28. {pelutils-3.8.1 → pelutils-3.8.3}/pelutils/py.typed +0 -0
  29. {pelutils-3.8.1 → pelutils-3.8.3}/pelutils/tests.py +0 -0
  30. {pelutils-3.8.1 → pelutils-3.8.3}/pelutils/ticktock.py +0 -0
  31. {pelutils-3.8.1 → pelutils-3.8.3}/pelutils/types.py +0 -0
  32. {pelutils-3.8.1 → pelutils-3.8.3}/pelutils.egg-info/SOURCES.txt +0 -0
  33. {pelutils-3.8.1 → pelutils-3.8.3}/pelutils.egg-info/dependency_links.txt +0 -0
  34. {pelutils-3.8.1 → pelutils-3.8.3}/pelutils.egg-info/entry_points.txt +0 -0
  35. {pelutils-3.8.1 → pelutils-3.8.3}/pelutils.egg-info/requires.txt +0 -0
  36. {pelutils-3.8.1 → pelutils-3.8.3}/pelutils.egg-info/top_level.txt +0 -0
  37. {pelutils-3.8.1 → pelutils-3.8.3}/setup.cfg +0 -0
  38. {pelutils-3.8.1 → pelutils-3.8.3}/setup.py +0 -0
  39. {pelutils-3.8.1 → pelutils-3.8.3}/tests/test_datastorage.py +0 -0
  40. {pelutils-3.8.1 → pelutils-3.8.3}/tests/test_format.py +0 -0
  41. {pelutils-3.8.1 → pelutils-3.8.3}/tests/test_init.py +0 -0
  42. {pelutils-3.8.1 → pelutils-3.8.3}/tests/test_jsonl.py +0 -0
  43. {pelutils-3.8.1 → pelutils-3.8.3}/tests/test_parser.py +0 -0
  44. {pelutils-3.8.1 → pelutils-3.8.3}/tests/test_pretty_json.py +0 -0
  45. {pelutils-3.8.1 → pelutils-3.8.3}/tests/test_tests.py +0 -0
  46. {pelutils-3.8.1 → pelutils-3.8.3}/tests/test_ticktock.py +0 -0
  47. {pelutils-3.8.1 → pelutils-3.8.3}/tests/test_types.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pelutils
3
- Version: 3.8.1
3
+ Version: 3.8.3
4
4
  Summary: The Swiss army knife of Python projects.
5
5
  Home-page: https://github.com/peleiden/pelutils
6
6
  Download-URL: https://pypi.org/project/pelutils/
@@ -1,2 +1,2 @@
1
1
  # Do not put anything else in this file
2
- __version__ = "3.8.1"
2
+ __version__ = "3.8.3"
@@ -6,13 +6,13 @@ from typing import TypeVar
6
6
 
7
7
  from pydantic import BaseModel, ConfigDict
8
8
 
9
- from pelutils.datastorage2._pretty_json import _make_json_unsafe, _pretty_json # pyright: ignore[reportPrivateUsage]
9
+ from pelutils.datastorage2._pretty_json import _make_json_unsafe, _pickle_encode, _pretty_json # pyright: ignore[reportPrivateUsage]
10
10
 
11
11
  _T = TypeVar("_T", bound="DataStorage2")
12
12
 
13
13
 
14
14
  class DataStorage2(BaseModel):
15
- """Better version of DataStorage based on pydantic.
15
+ """Better version of DataStorage based on pydantic. It makes any class fully JSON serialisable.
16
16
 
17
17
  Usage is very similar to DataStorage, but it has a few key advantages:
18
18
  - Allows saving and loading of nested objects.
@@ -35,15 +35,18 @@ class DataStorage2(BaseModel):
35
35
  ) -> Path:
36
36
  """Save the instance to a json file in the directory. The path to the file is returned.
37
37
 
38
- If save_name is None, the path is <directory>/<class name>.json, otherwise it is <directory>/<save_name>.json.
38
+ If save_name is None, the path is <directory>/<class name>.json, otherwise it is <directory>/<filename>.json.
39
39
  """
40
40
  savepath = self._resolve_save_file(directory, filename)
41
- self_dict = self.model_dump()
41
+ savepath.parent.mkdir(parents=True, exist_ok=True)
42
+ self_dict = self.model_dump(mode="json", fallback=_pickle_encode)
42
43
  savepath.write_text(
43
44
  _pretty_json(
44
45
  self_dict,
45
46
  max_line_length=max_line_length,
46
47
  indent=indent,
48
+ # Safe should not be needed here, as the fallback function in model_dump should ensure no issues
49
+ # However, it is kept for good measure in case there unforeseen edge cases
47
50
  safe=True,
48
51
  ),
49
52
  encoding=encoding,
@@ -4,7 +4,7 @@ import os
4
4
  import traceback as tb
5
5
  from collections.abc import Generator, Iterable
6
6
  from pathlib import Path
7
- from typing import Optional
7
+ from typing import Any, Optional
8
8
 
9
9
  from pelutils import OS, UnsupportedOS, get_repo, get_timestamp
10
10
  from pelutils.format import RichString
@@ -135,7 +135,7 @@ class Logger:
135
135
 
136
136
  def _log(
137
137
  self,
138
- *tolog: str,
138
+ *tolog: Any, # pyright: ignore[reportExplicitAny]
139
139
  level: LogLevels = LogLevels.INFO,
140
140
  with_info: bool = True,
141
141
  sep: str | None = None,
@@ -276,34 +276,39 @@ class Logger:
276
276
  raise UnsupportedOS("Log collecting is not supported on windows")
277
277
  return _CollectLogs(self)
278
278
 
279
- def section(self, *tolog: str, with_info: bool = True, sep: str | None = None, with_print: bool | None = None, newline: bool = True):
279
+ def section(self, *tolog: Any, with_info: bool = True, sep: str | None = None, with_print: bool | None = None, newline: bool = True): # pyright: ignore[reportExplicitAny]
280
280
  """Log at SECTION level. See .log method for argument descriptions."""
281
281
  if newline:
282
282
  self._log("")
283
283
  self._log(*tolog, with_info=with_info, sep=sep, with_print=with_print, level=LogLevels.SECTION)
284
284
 
285
- def critical(self, *tolog: str, with_info: bool = True, sep: str | None = None, with_print: bool | None = None):
285
+ def critical(self, *tolog: Any, with_info: bool = True, sep: str | None = None, with_print: bool | None = None): # pyright: ignore[reportExplicitAny]
286
286
  """Log at CRITICAL level. See .log method for argument descriptions."""
287
287
  self._log(*tolog, with_info=with_info, sep=sep, with_print=with_print, level=LogLevels.CRITICAL)
288
288
 
289
- def error(self, *tolog: str, with_info: bool = True, sep: str | None = None, with_print: bool | None = None):
289
+ def error(self, *tolog: Any, with_info: bool = True, sep: str | None = None, with_print: bool | None = None): # pyright: ignore[reportExplicitAny]
290
290
  """Log at ERROR level. See .log method for argument descriptions."""
291
291
  self._log(*tolog, with_info=with_info, sep=sep, with_print=with_print, level=LogLevels.ERROR)
292
292
 
293
- def warning(self, *tolog: str, with_info: bool = True, sep: str | None = None, with_print: bool | None = None):
293
+ def warning(self, *tolog: Any, with_info: bool = True, sep: str | None = None, with_print: bool | None = None): # pyright: ignore[reportExplicitAny]
294
294
  """Log at WARNING level. See .log method for argument descriptions."""
295
295
  self._log(*tolog, with_info=with_info, sep=sep, with_print=with_print, level=LogLevels.WARNING)
296
296
 
297
- def info(self, *tolog: str, with_info: bool = True, sep: str | None = None, with_print: bool | None = None):
297
+ def info(self, *tolog: Any, with_info: bool = True, sep: str | None = None, with_print: bool | None = None): # pyright: ignore[reportExplicitAny]
298
298
  """Log at INFO level. See .log method for argument descriptions."""
299
299
  self._log(*tolog, with_info=with_info, sep=sep, with_print=with_print, level=LogLevels.INFO)
300
300
 
301
- def debug(self, *tolog: str, with_info: bool = True, sep: str | None = None, with_print: bool | None = None):
301
+ def debug(self, *tolog: Any, with_info: bool = True, sep: str | None = None, with_print: bool | None = None): # pyright: ignore[reportExplicitAny]
302
302
  """Log at DEBUG level. See .log method for argument descriptions."""
303
303
  self._log(*tolog, with_info=with_info, sep=sep, with_print=with_print, level=LogLevels.DEBUG)
304
304
 
305
305
  def __call__(
306
- self, *tolog: str, level: LogLevels = LogLevels.INFO, with_info: bool = True, sep: str | None = None, with_print: bool | None = None
306
+ self,
307
+ *tolog: Any, # pyright: ignore[reportExplicitAny]
308
+ level: LogLevels = LogLevels.INFO,
309
+ with_info: bool = True,
310
+ sep: str | None = None,
311
+ with_print: bool | None = None,
307
312
  ):
308
313
  """Shorthand for specific logging methods where level is specified as an argument."""
309
314
  self._log(*tolog, level=level, with_info=with_info, sep=sep, with_print=with_print)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pelutils
3
- Version: 3.8.1
3
+ Version: 3.8.3
4
4
  Summary: The Swiss army knife of Python projects.
5
5
  Home-page: https://github.com/peleiden/pelutils
6
6
  Download-URL: https://pypi.org/project/pelutils/
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes