checkpointer 2.14.1__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.1 → checkpointer-2.14.2}/PKG-INFO +1 -1
  2. {checkpointer-2.14.1 → checkpointer-2.14.2}/checkpointer/checkpoint.py +10 -0
  3. {checkpointer-2.14.1 → checkpointer-2.14.2}/checkpointer/storages/pickle_storage.py +2 -16
  4. {checkpointer-2.14.1 → checkpointer-2.14.2}/checkpointer/utils.py +18 -0
  5. {checkpointer-2.14.1 → checkpointer-2.14.2}/pyproject.toml +1 -1
  6. {checkpointer-2.14.1 → checkpointer-2.14.2}/uv.lock +1 -1
  7. {checkpointer-2.14.1 → checkpointer-2.14.2}/.gitignore +0 -0
  8. {checkpointer-2.14.1 → checkpointer-2.14.2}/.python-version +0 -0
  9. {checkpointer-2.14.1 → checkpointer-2.14.2}/ATTRIBUTION.md +0 -0
  10. {checkpointer-2.14.1 → checkpointer-2.14.2}/LICENSE +0 -0
  11. {checkpointer-2.14.1 → checkpointer-2.14.2}/README.md +0 -0
  12. {checkpointer-2.14.1 → checkpointer-2.14.2}/checkpointer/__init__.py +0 -0
  13. {checkpointer-2.14.1 → checkpointer-2.14.2}/checkpointer/fn_ident.py +0 -0
  14. {checkpointer-2.14.1 → checkpointer-2.14.2}/checkpointer/fn_string.py +0 -0
  15. {checkpointer-2.14.1 → checkpointer-2.14.2}/checkpointer/import_mappings.py +0 -0
  16. {checkpointer-2.14.1 → checkpointer-2.14.2}/checkpointer/object_hash.py +0 -0
  17. {checkpointer-2.14.1 → checkpointer-2.14.2}/checkpointer/print_checkpoint.py +0 -0
  18. {checkpointer-2.14.1 → checkpointer-2.14.2}/checkpointer/storages/__init__.py +0 -0
  19. {checkpointer-2.14.1 → checkpointer-2.14.2}/checkpointer/storages/memory_storage.py +0 -0
  20. {checkpointer-2.14.1 → checkpointer-2.14.2}/checkpointer/storages/storage.py +0 -0
  21. {checkpointer-2.14.1 → 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.1
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
@@ -2,22 +2,12 @@ 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:
8
9
  return datetime.fromtimestamp(path.stat().st_mtime)
9
10
 
10
- def empty_dirs(path: Path):
11
- nonempty_count = 0
12
- for child in path.iterdir():
13
- nonempty_count += 1
14
- if child.is_dir():
15
- for grand_child in empty_dirs(child):
16
- yield grand_child
17
- nonempty_count -= child == grand_child
18
- if nonempty_count == 0:
19
- yield path
20
-
21
11
  class PickleStorage(Storage):
22
12
  def get_path(self, call_hash: str):
23
13
  return self.fn_dir() / f"{call_hash[:2]}/{call_hash[2:]}.pkl"
@@ -58,11 +48,7 @@ class PickleStorage(Storage):
58
48
  count += 1
59
49
  pkl_path.unlink(missing_ok=True)
60
50
  print(f"Removed {count} expired checkpoints for {self.cached_fn.__qualname__}")
61
- if fn_path.exists():
62
- for file in fn_path.glob("**/.DS_Store"):
63
- file.unlink()
64
- for directory in empty_dirs(fn_path):
65
- directory.rmdir()
51
+ clear_directory(fn_path)
66
52
 
67
53
  def clear(self):
68
54
  fn_path = self.fn_dir().parent
@@ -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.1"
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.1"
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