checkpointer 2.6.2__py3-none-any.whl → 2.7.0__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.
@@ -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: str | None
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
- store_format = self.checkpointer.format
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 = self.checkpointer.fn_hash or str(ObjectHash().write_text(self.fn_hash_raw, *deep_hashes))
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
- hash_params = [self.checkpointer.hash_by(*args, **kw)] if self.checkpointer.hash_by else (args, kw)
95
- call_hash = ObjectHash(self.fn_hash, *hash_params, digest_size=16)
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 = self.checkpointer.root_path / checkpoint_id
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 (self.checkpointer.should_expire and self.checkpointer.should_expire(self.storage.checkpoint_date(checkpoint_path)))
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):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: checkpointer
3
- Version: 2.6.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
@@ -1,5 +1,5 @@
1
1
  checkpointer/__init__.py,sha256=ZJ6frUNgkklUi85b5uXTyTfRzMvZgQOJY-ZOnu7jh78,777
2
- checkpointer/checkpoint.py,sha256=3ohNeAqzZLCT9IHJ7nsDbtZ8rjI0rdApbqp8KowDRtc,6332
2
+ checkpointer/checkpoint.py,sha256=NmspwYKHbhaTMElENXR3TREzvhaXYfmuz_rQJsLUtpA,6280
3
3
  checkpointer/fn_ident.py,sha256=SWaksNCTlskMom0ztqjECSRjZYPWXUA1p1ZCb-9tWo0,4297
4
4
  checkpointer/object_hash.py,sha256=rcHzVYZAeygLyqeKv1NODIDp0M_knLuDZefcBV_7ln4,7371
5
5
  checkpointer/print_checkpoint.py,sha256=aJCeWMRJiIR3KpyPk_UOKTaD906kArGrmLGQ3LqcVgo,1369
@@ -10,7 +10,7 @@ checkpointer/storages/bcolz_storage.py,sha256=3QkSUSeG5s2kFuVV_LZpzMn1A5E7kqC7jk
10
10
  checkpointer/storages/memory_storage.py,sha256=S5ayOZE_CyaFQJ-vSgObTanldPzG3gh3NksjNAc7vsk,1282
11
11
  checkpointer/storages/pickle_storage.py,sha256=idh9sBMdWuyvS220oa_7bAUpc9Xo9v6Ud9aYKGWasUs,1593
12
12
  checkpointer/storages/storage.py,sha256=_m18Z8TKrdAbi6YYYQmuNOnhna4RB2sJDn1v3liaU3U,721
13
- checkpointer-2.6.2.dist-info/METADATA,sha256=fpt1kQbTghSeSIbDranjL0-iGYaA3LbWFlyAfSTgJB0,10606
14
- checkpointer-2.6.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
15
- checkpointer-2.6.2.dist-info/licenses/LICENSE,sha256=9xVsdtv_-uSyY9Xl9yujwAPm4-mjcCLeVy-ljwXEWbo,1059
16
- checkpointer-2.6.2.dist-info/RECORD,,
13
+ checkpointer-2.7.0.dist-info/METADATA,sha256=ANOUJpdq3OXaF_d9jMBP0rWlpIOq0c4Z2uVKjXf_YnE,10606
14
+ checkpointer-2.7.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
15
+ checkpointer-2.7.0.dist-info/licenses/LICENSE,sha256=9xVsdtv_-uSyY9Xl9yujwAPm4-mjcCLeVy-ljwXEWbo,1059
16
+ checkpointer-2.7.0.dist-info/RECORD,,