checkpointer 2.6.2__tar.gz → 2.7.0__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.
- {checkpointer-2.6.2 → checkpointer-2.7.0}/PKG-INFO +1 -1
- {checkpointer-2.6.2 → checkpointer-2.7.0}/checkpointer/checkpoint.py +13 -12
- {checkpointer-2.6.2 → checkpointer-2.7.0}/pyproject.toml +1 -1
- {checkpointer-2.6.2 → checkpointer-2.7.0}/uv.lock +1 -1
- {checkpointer-2.6.2 → checkpointer-2.7.0}/.gitignore +0 -0
- {checkpointer-2.6.2 → checkpointer-2.7.0}/.python-version +0 -0
- {checkpointer-2.6.2 → checkpointer-2.7.0}/LICENSE +0 -0
- {checkpointer-2.6.2 → checkpointer-2.7.0}/README.md +0 -0
- {checkpointer-2.6.2 → checkpointer-2.7.0}/checkpointer/__init__.py +0 -0
- {checkpointer-2.6.2 → checkpointer-2.7.0}/checkpointer/fn_ident.py +0 -0
- {checkpointer-2.6.2 → checkpointer-2.7.0}/checkpointer/object_hash.py +0 -0
- {checkpointer-2.6.2 → checkpointer-2.7.0}/checkpointer/print_checkpoint.py +0 -0
- {checkpointer-2.6.2 → checkpointer-2.7.0}/checkpointer/storages/__init__.py +0 -0
- {checkpointer-2.6.2 → checkpointer-2.7.0}/checkpointer/storages/bcolz_storage.py +0 -0
- {checkpointer-2.6.2 → checkpointer-2.7.0}/checkpointer/storages/memory_storage.py +0 -0
- {checkpointer-2.6.2 → checkpointer-2.7.0}/checkpointer/storages/pickle_storage.py +0 -0
- {checkpointer-2.6.2 → checkpointer-2.7.0}/checkpointer/storages/storage.py +0 -0
- {checkpointer-2.6.2 → checkpointer-2.7.0}/checkpointer/test_checkpointer.py +0 -0
- {checkpointer-2.6.2 → checkpointer-2.7.0}/checkpointer/utils.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: checkpointer
|
3
|
-
Version: 2.
|
3
|
+
Version: 2.7.0
|
4
4
|
Summary: A Python library for memoizing function results with support for multiple storage backends, async runtimes, and automatic cache invalidation
|
5
5
|
Project-URL: Repository, https://github.com/Reddan/checkpointer.git
|
6
6
|
Author: Hampus Hallman
|
@@ -26,7 +26,7 @@ class CheckpointerOpts(TypedDict, total=False):
|
|
26
26
|
hash_by: Callable | None
|
27
27
|
should_expire: Callable[[datetime], bool] | None
|
28
28
|
capture: bool
|
29
|
-
fn_hash:
|
29
|
+
fn_hash: ObjectHash | None
|
30
30
|
|
31
31
|
class Checkpointer:
|
32
32
|
def __init__(self, **opts: Unpack[CheckpointerOpts]):
|
@@ -61,14 +61,14 @@ class CheckpointFn(Generic[Fn]):
|
|
61
61
|
return self
|
62
62
|
|
63
63
|
def _lazyinit(self):
|
64
|
+
params = self.checkpointer
|
64
65
|
wrapped = unwrap_fn(self.fn)
|
65
66
|
fn_file = Path(wrapped.__code__.co_filename).name
|
66
67
|
fn_name = re.sub(r"[^\w.]", "", wrapped.__qualname__)
|
67
68
|
update_wrapper(cast(Callable, self), wrapped)
|
68
|
-
|
69
|
-
Storage = STORAGE_MAP[store_format] if isinstance(store_format, str) else store_format
|
69
|
+
Storage = STORAGE_MAP[params.format] if isinstance(params.format, str) else params.format
|
70
70
|
deep_hashes = [child._set_ident().fn_hash_raw for child in iterate_checkpoint_fns(self)]
|
71
|
-
self.fn_hash =
|
71
|
+
self.fn_hash = str(params.fn_hash or ObjectHash().write_text(self.fn_hash_raw, *deep_hashes))
|
72
72
|
self.fn_subdir = f"{fn_file}/{fn_name}/{self.fn_hash[:16]}"
|
73
73
|
self.is_async: bool = self.fn.is_async if isinstance(self.fn, CheckpointFn) else inspect.iscoroutinefunction(self.fn)
|
74
74
|
self.storage = Storage(self)
|
@@ -91,20 +91,21 @@ class CheckpointFn(Generic[Fn]):
|
|
91
91
|
return self
|
92
92
|
|
93
93
|
def get_checkpoint_id(self, args: tuple, kw: dict) -> str:
|
94
|
-
|
95
|
-
|
94
|
+
hash_by = self.checkpointer.hash_by
|
95
|
+
hash_params = hash_by(*args, **kw) if hash_by else (args, kw)
|
96
|
+
call_hash = ObjectHash(hash_params, digest_size=16)
|
96
97
|
return f"{self.fn_subdir}/{call_hash}"
|
97
98
|
|
98
99
|
async def _store_on_demand(self, args: tuple, kw: dict, rerun: bool):
|
100
|
+
params = self.checkpointer
|
99
101
|
checkpoint_id = self.get_checkpoint_id(args, kw)
|
100
|
-
checkpoint_path =
|
101
|
-
verbosity = self.checkpointer.verbosity
|
102
|
+
checkpoint_path = params.root_path / checkpoint_id
|
102
103
|
refresh = rerun \
|
103
104
|
or not self.storage.exists(checkpoint_path) \
|
104
|
-
or (
|
105
|
+
or (params.should_expire and params.should_expire(self.storage.checkpoint_date(checkpoint_path)))
|
105
106
|
|
106
107
|
if refresh:
|
107
|
-
print_checkpoint(verbosity >= 1, "MEMORIZING", checkpoint_id, "blue")
|
108
|
+
print_checkpoint(params.verbosity >= 1, "MEMORIZING", checkpoint_id, "blue")
|
108
109
|
data = self.fn(*args, **kw)
|
109
110
|
if inspect.iscoroutine(data):
|
110
111
|
data = await data
|
@@ -113,11 +114,11 @@ class CheckpointFn(Generic[Fn]):
|
|
113
114
|
|
114
115
|
try:
|
115
116
|
data = self.storage.load(checkpoint_path)
|
116
|
-
print_checkpoint(verbosity >= 2, "REMEMBERED", checkpoint_id, "green")
|
117
|
+
print_checkpoint(params.verbosity >= 2, "REMEMBERED", checkpoint_id, "green")
|
117
118
|
return data
|
118
119
|
except (EOFError, FileNotFoundError):
|
119
120
|
pass
|
120
|
-
print_checkpoint(verbosity >= 1, "CORRUPTED", checkpoint_id, "yellow")
|
121
|
+
print_checkpoint(params.verbosity >= 1, "CORRUPTED", checkpoint_id, "yellow")
|
121
122
|
return await self._store_on_demand(args, kw, True)
|
122
123
|
|
123
124
|
def _call(self, args: tuple, kw: dict, rerun=False):
|
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
|