checkpointer 2.14.0__tar.gz → 2.14.2__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 (21) hide show
  1. {checkpointer-2.14.0 → checkpointer-2.14.2}/PKG-INFO +1 -1
  2. {checkpointer-2.14.0 → checkpointer-2.14.2}/checkpointer/checkpoint.py +10 -0
  3. {checkpointer-2.14.0 → checkpointer-2.14.2}/checkpointer/storages/memory_storage.py +6 -0
  4. {checkpointer-2.14.0 → checkpointer-2.14.2}/checkpointer/storages/pickle_storage.py +8 -1
  5. {checkpointer-2.14.0 → checkpointer-2.14.2}/checkpointer/storages/storage.py +3 -1
  6. {checkpointer-2.14.0 → checkpointer-2.14.2}/checkpointer/utils.py +18 -0
  7. {checkpointer-2.14.0 → checkpointer-2.14.2}/pyproject.toml +1 -1
  8. {checkpointer-2.14.0 → checkpointer-2.14.2}/uv.lock +1 -1
  9. {checkpointer-2.14.0 → checkpointer-2.14.2}/.gitignore +0 -0
  10. {checkpointer-2.14.0 → checkpointer-2.14.2}/.python-version +0 -0
  11. {checkpointer-2.14.0 → checkpointer-2.14.2}/ATTRIBUTION.md +0 -0
  12. {checkpointer-2.14.0 → checkpointer-2.14.2}/LICENSE +0 -0
  13. {checkpointer-2.14.0 → checkpointer-2.14.2}/README.md +0 -0
  14. {checkpointer-2.14.0 → checkpointer-2.14.2}/checkpointer/__init__.py +0 -0
  15. {checkpointer-2.14.0 → checkpointer-2.14.2}/checkpointer/fn_ident.py +0 -0
  16. {checkpointer-2.14.0 → checkpointer-2.14.2}/checkpointer/fn_string.py +0 -0
  17. {checkpointer-2.14.0 → checkpointer-2.14.2}/checkpointer/import_mappings.py +0 -0
  18. {checkpointer-2.14.0 → checkpointer-2.14.2}/checkpointer/object_hash.py +0 -0
  19. {checkpointer-2.14.0 → checkpointer-2.14.2}/checkpointer/print_checkpoint.py +0 -0
  20. {checkpointer-2.14.0 → checkpointer-2.14.2}/checkpointer/storages/__init__.py +0 -0
  21. {checkpointer-2.14.0 → checkpointer-2.14.2}/checkpointer/types.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: checkpointer
3
- Version: 2.14.0
3
+ Version: 2.14.2
4
4
  Summary: checkpointer adds code-aware caching to Python functions, maintaining correctness and speeding up execution as your code changes.
5
5
  Project-URL: Repository, https://github.com/Reddan/checkpointer.git
6
6
  Author: Hampus Hallman
@@ -241,6 +241,16 @@ class CachedFunction(Generic[Fn]):
241
241
  except Exception as ex:
242
242
  raise CheckpointError("Could not load checkpoint") from ex
243
243
 
244
+ @overload
245
+ def get_or(self: Callable[P, Coro[R]], default: R, *args: P.args, **kw: P.kwargs) -> R: ...
246
+ @overload
247
+ def get_or(self: Callable[P, R], default: R, *args: P.args, **kw: P.kwargs) -> R: ...
248
+ def get_or(self, default, *args, **kw):
249
+ try:
250
+ return self.get(*args, **kw) # type: ignore
251
+ except CheckpointError:
252
+ return default
253
+
244
254
  @overload
245
255
  def set(self: Callable[P, Coro[R]], value: AwaitableValue[R], *args: P.args, **kw: P.kwargs): ...
246
256
  @overload
@@ -35,3 +35,9 @@ class MemoryStorage(Storage):
35
35
  for call_hash, (date, _) in list(calldict.items()):
36
36
  if self.expired_dt(date):
37
37
  del calldict[call_hash]
38
+
39
+ def clear(self):
40
+ fn_path = self.fn_dir().parent
41
+ for key in list(item_map.keys()):
42
+ if key.parent == fn_path:
43
+ del item_map[key]
@@ -2,6 +2,7 @@ import pickle
2
2
  import shutil
3
3
  from datetime import datetime
4
4
  from pathlib import Path
5
+ from ..utils import clear_directory
5
6
  from .storage import Storage
6
7
 
7
8
  def filedate(path: Path) -> datetime:
@@ -35,7 +36,7 @@ class PickleStorage(Storage):
35
36
  def cleanup(self, invalidated=True, expired=True):
36
37
  version_path = self.fn_dir()
37
38
  fn_path = version_path.parent
38
- if invalidated:
39
+ if invalidated and fn_path.exists():
39
40
  old_dirs = [path for path in fn_path.iterdir() if path.is_dir() and path != version_path]
40
41
  for path in old_dirs:
41
42
  shutil.rmtree(path)
@@ -47,3 +48,9 @@ class PickleStorage(Storage):
47
48
  count += 1
48
49
  pkl_path.unlink(missing_ok=True)
49
50
  print(f"Removed {count} expired checkpoints for {self.cached_fn.__qualname__}")
51
+ clear_directory(fn_path)
52
+
53
+ def clear(self):
54
+ fn_path = self.fn_dir().parent
55
+ if fn_path.exists():
56
+ shutil.rmtree(fn_path)
@@ -44,4 +44,6 @@ class Storage:
44
44
 
45
45
  def delete(self, call_hash: str) -> None: ...
46
46
 
47
- def cleanup(self, invalidated=True, expired=True): ...
47
+ def cleanup(self, invalidated=True, expired=True) -> None: ...
48
+
49
+ def clear(self) -> None: ...
@@ -112,3 +112,21 @@ class ContextVar(Generic[T]):
112
112
  yield
113
113
  finally:
114
114
  self.value = old
115
+
116
+ def empty_dirs(path: Path) -> Iterable[Path]:
117
+ nonempty_count = 0
118
+ for child in path.iterdir():
119
+ nonempty_count += 1
120
+ if child.is_dir():
121
+ for grand_child in empty_dirs(child):
122
+ yield grand_child
123
+ nonempty_count -= child == grand_child
124
+ if nonempty_count == 0:
125
+ yield path
126
+
127
+ def clear_directory(path: Path):
128
+ if path.is_dir():
129
+ for file in path.glob("**/.DS_Store"):
130
+ file.unlink()
131
+ for directory in empty_dirs(path):
132
+ directory.rmdir()
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "checkpointer"
3
- version = "2.14.0"
3
+ version = "2.14.2"
4
4
  requires-python = ">=3.11"
5
5
  dependencies = []
6
6
  authors = [
@@ -8,7 +8,7 @@ resolution-markers = [
8
8
 
9
9
  [[package]]
10
10
  name = "checkpointer"
11
- version = "2.14.0"
11
+ version = "2.14.2"
12
12
  source = { editable = "." }
13
13
 
14
14
  [package.dev-dependencies]
File without changes
File without changes
File without changes