checkpointer 2.14.0__py3-none-any.whl → 2.14.1__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.
@@ -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]
@@ -7,6 +7,17 @@ from .storage import Storage
7
7
  def filedate(path: Path) -> datetime:
8
8
  return datetime.fromtimestamp(path.stat().st_mtime)
9
9
 
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
+
10
21
  class PickleStorage(Storage):
11
22
  def get_path(self, call_hash: str):
12
23
  return self.fn_dir() / f"{call_hash[:2]}/{call_hash[2:]}.pkl"
@@ -35,7 +46,7 @@ class PickleStorage(Storage):
35
46
  def cleanup(self, invalidated=True, expired=True):
36
47
  version_path = self.fn_dir()
37
48
  fn_path = version_path.parent
38
- if invalidated:
49
+ if invalidated and fn_path.exists():
39
50
  old_dirs = [path for path in fn_path.iterdir() if path.is_dir() and path != version_path]
40
51
  for path in old_dirs:
41
52
  shutil.rmtree(path)
@@ -47,3 +58,13 @@ class PickleStorage(Storage):
47
58
  count += 1
48
59
  pkl_path.unlink(missing_ok=True)
49
60
  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()
66
+
67
+ def clear(self):
68
+ fn_path = self.fn_dir().parent
69
+ if fn_path.exists():
70
+ 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: ...
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: checkpointer
3
- Version: 2.14.0
3
+ Version: 2.14.1
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
@@ -8,11 +8,11 @@ checkpointer/print_checkpoint.py,sha256=uUQ493fJCaB4nhp4Ox60govSCiBTIPbBX15zt2Qi
8
8
  checkpointer/types.py,sha256=GFqbGACdDxzQX3bb2LmF9UxQVWOEisGvdtobnqCBAOA,1129
9
9
  checkpointer/utils.py,sha256=CF28pGytCWV4URhRDFaIDawX8qmCAAByQp0ZkEwrA6c,3014
10
10
  checkpointer/storages/__init__.py,sha256=p-r4YrPXn505_S3qLrSXHSlsEtb13w_DFnCt9IiUomk,296
11
- checkpointer/storages/memory_storage.py,sha256=f242kLEsB4TcqEkEBmJGIewJE9mvv9aCAZ0V9pPB2EQ,1110
12
- checkpointer/storages/pickle_storage.py,sha256=burbgX-ICPLNMAF9iU3HRZroxJibKfmgJLqTCm6YbbI,1649
13
- checkpointer/storages/storage.py,sha256=PgpwW_VLkiwD361Kjsz8aoq5FHZLBTqF43yD2mw9dTI,1326
14
- checkpointer-2.14.0.dist-info/METADATA,sha256=MSJ--2X9N_Ug8sd9VhffONSzhIPA_njmzJhCe3fa_l8,11215
15
- checkpointer-2.14.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
16
- checkpointer-2.14.0.dist-info/licenses/ATTRIBUTION.md,sha256=WF6L7-sD4s9t9ytVJOhjhpDoZ6TrWpqE3_bMdDIeJxI,1078
17
- checkpointer-2.14.0.dist-info/licenses/LICENSE,sha256=drXs6vIb7uW49r70UuMz2A1VtOCl626kiTbcmrar1Xo,1072
18
- checkpointer-2.14.0.dist-info/RECORD,,
11
+ checkpointer/storages/memory_storage.py,sha256=1YHZU-WSqvLA_0og53UZY141ziDgnaBub2mDjDaeAj8,1261
12
+ checkpointer/storages/pickle_storage.py,sha256=PwFbCqYHjR3jiWuTnwxCU9cui7CINvq0wXIOKtf8dOk,2230
13
+ checkpointer/storages/storage.py,sha256=JVxdq1DMhbq83bvflvIuW7okE1CQCa7poQPsj3x0ACg,1366
14
+ checkpointer-2.14.1.dist-info/METADATA,sha256=KupseJCcWRNym_Ckit_F-oGLPIgqUsyKJvjl6ekEDZU,11215
15
+ checkpointer-2.14.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
16
+ checkpointer-2.14.1.dist-info/licenses/ATTRIBUTION.md,sha256=WF6L7-sD4s9t9ytVJOhjhpDoZ6TrWpqE3_bMdDIeJxI,1078
17
+ checkpointer-2.14.1.dist-info/licenses/LICENSE,sha256=drXs6vIb7uW49r70UuMz2A1VtOCl626kiTbcmrar1Xo,1072
18
+ checkpointer-2.14.1.dist-info/RECORD,,