checkpointer 2.6.1__py3-none-any.whl → 2.6.2__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.
- checkpointer/object_hash.py +11 -2
- checkpointer/print_checkpoint.py +1 -1
- checkpointer/utils.py +12 -9
- {checkpointer-2.6.1.dist-info → checkpointer-2.6.2.dist-info}/METADATA +3 -2
- {checkpointer-2.6.1.dist-info → checkpointer-2.6.2.dist-info}/RECORD +7 -7
- {checkpointer-2.6.1.dist-info → checkpointer-2.6.2.dist-info}/WHEEL +0 -0
- {checkpointer-2.6.1.dist-info → checkpointer-2.6.2.dist-info}/licenses/LICENSE +0 -0
checkpointer/object_hash.py
CHANGED
@@ -2,23 +2,32 @@ import ctypes
|
|
2
2
|
import hashlib
|
3
3
|
import io
|
4
4
|
import re
|
5
|
+
import sys
|
5
6
|
from collections.abc import Iterable
|
6
7
|
from contextlib import nullcontext, suppress
|
7
8
|
from decimal import Decimal
|
8
9
|
from itertools import chain
|
9
10
|
from pickle import HIGHEST_PROTOCOL as PROTOCOL
|
10
11
|
from types import BuiltinFunctionType, FunctionType, GeneratorType, MethodType, ModuleType, UnionType
|
11
|
-
from typing import Any,
|
12
|
+
from typing import Any, TypeVar
|
12
13
|
from .utils import ContextVar, get_fn_body
|
13
14
|
|
14
15
|
np, torch = None, None
|
15
16
|
|
16
17
|
with suppress(Exception):
|
17
18
|
import numpy as np
|
18
|
-
|
19
19
|
with suppress(Exception):
|
20
20
|
import torch
|
21
21
|
|
22
|
+
class _Never:
|
23
|
+
def __getattribute__(self, _: str):
|
24
|
+
pass
|
25
|
+
|
26
|
+
if sys.version_info >= (3, 12):
|
27
|
+
from typing import TypeAliasType
|
28
|
+
else:
|
29
|
+
TypeAliasType = _Never
|
30
|
+
|
22
31
|
def encode_type(t: type | FunctionType) -> str:
|
23
32
|
return f"{t.__module__}:{t.__qualname__}"
|
24
33
|
|
checkpointer/print_checkpoint.py
CHANGED
@@ -49,4 +49,4 @@ colored = colored_ if allow_color() else noop
|
|
49
49
|
|
50
50
|
def print_checkpoint(should_log: bool, title: str, text: str, color: Color):
|
51
51
|
if should_log:
|
52
|
-
print(f
|
52
|
+
print(f'{colored(f" {title} ", "grey", color)} {colored(text, color)}')
|
checkpointer/utils.py
CHANGED
@@ -3,9 +3,12 @@ import tokenize
|
|
3
3
|
from contextlib import contextmanager
|
4
4
|
from io import StringIO
|
5
5
|
from types import coroutine
|
6
|
-
from typing import Any, Callable, Coroutine, Generator, Iterable, cast
|
6
|
+
from typing import Any, Callable, Coroutine, Generator, Generic, Iterable, TypeVar, cast
|
7
7
|
|
8
|
-
|
8
|
+
T = TypeVar("T")
|
9
|
+
T_Callable = TypeVar("T_Callable", bound=Callable)
|
10
|
+
|
11
|
+
def distinct(seq: Iterable[T]) -> list[T]:
|
9
12
|
return list(dict.fromkeys(seq))
|
10
13
|
|
11
14
|
def transpose(tuples, default_num_returns=0):
|
@@ -30,22 +33,22 @@ def get_cell_contents(fn: Callable) -> Iterable[tuple[str, Any]]:
|
|
30
33
|
except ValueError:
|
31
34
|
pass
|
32
35
|
|
33
|
-
def unwrap_fn
|
36
|
+
def unwrap_fn(fn: T_Callable, checkpoint_fn=False) -> T_Callable:
|
34
37
|
from .checkpoint import CheckpointFn
|
35
38
|
while True:
|
36
39
|
if (checkpoint_fn and isinstance(fn, CheckpointFn)) or not hasattr(fn, "__wrapped__"):
|
37
|
-
return cast(
|
40
|
+
return cast(T_Callable, fn)
|
38
41
|
fn = getattr(fn, "__wrapped__")
|
39
42
|
|
40
|
-
async def resolved_awaitable
|
43
|
+
async def resolved_awaitable(value: T) -> T:
|
41
44
|
return value
|
42
45
|
|
43
46
|
@coroutine
|
44
|
-
def coroutine_as_generator
|
47
|
+
def coroutine_as_generator(coroutine: Coroutine[None, None, T]) -> Generator[None, None, T]:
|
45
48
|
val = yield from coroutine
|
46
49
|
return val
|
47
50
|
|
48
|
-
def sync_resolve_coroutine
|
51
|
+
def sync_resolve_coroutine(coroutine: Coroutine[None, None, T]) -> T:
|
49
52
|
gen = cast(Generator, coroutine_as_generator(coroutine))
|
50
53
|
try:
|
51
54
|
while True:
|
@@ -81,7 +84,7 @@ class AttrDict(dict):
|
|
81
84
|
d = getattr(d, attr, None)
|
82
85
|
return d
|
83
86
|
|
84
|
-
class ContextVar[T]:
|
87
|
+
class ContextVar(Generic[T]):
|
85
88
|
def __init__(self, value: T):
|
86
89
|
self.value = value
|
87
90
|
|
@@ -93,7 +96,7 @@ class ContextVar[T]:
|
|
93
96
|
finally:
|
94
97
|
self.value = old
|
95
98
|
|
96
|
-
class iterate_and_upcoming[T]:
|
99
|
+
class iterate_and_upcoming(Generic[T]):
|
97
100
|
def __init__(self, it: Iterable[T]) -> None:
|
98
101
|
self.it = iter(it)
|
99
102
|
self.previous: tuple[()] | tuple[T] = ()
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: checkpointer
|
3
|
-
Version: 2.6.
|
3
|
+
Version: 2.6.2
|
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
|
@@ -12,9 +12,10 @@ License: Copyright 2018-2025 Hampus Hallman
|
|
12
12
|
|
13
13
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
14
14
|
License-File: LICENSE
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
15
16
|
Classifier: Programming Language :: Python :: 3.12
|
16
17
|
Classifier: Programming Language :: Python :: 3.13
|
17
|
-
Requires-Python: >=3.
|
18
|
+
Requires-Python: >=3.11
|
18
19
|
Description-Content-Type: text/markdown
|
19
20
|
|
20
21
|
# checkpointer · [](https://github.com/Reddan/checkpointer/blob/master/LICENSE) [](https://pypi.org/project/checkpointer/) [](https://pypi.org/project/checkpointer/)
|
@@ -1,16 +1,16 @@
|
|
1
1
|
checkpointer/__init__.py,sha256=ZJ6frUNgkklUi85b5uXTyTfRzMvZgQOJY-ZOnu7jh78,777
|
2
2
|
checkpointer/checkpoint.py,sha256=3ohNeAqzZLCT9IHJ7nsDbtZ8rjI0rdApbqp8KowDRtc,6332
|
3
3
|
checkpointer/fn_ident.py,sha256=SWaksNCTlskMom0ztqjECSRjZYPWXUA1p1ZCb-9tWo0,4297
|
4
|
-
checkpointer/object_hash.py,sha256=
|
5
|
-
checkpointer/print_checkpoint.py,sha256=
|
4
|
+
checkpointer/object_hash.py,sha256=rcHzVYZAeygLyqeKv1NODIDp0M_knLuDZefcBV_7ln4,7371
|
5
|
+
checkpointer/print_checkpoint.py,sha256=aJCeWMRJiIR3KpyPk_UOKTaD906kArGrmLGQ3LqcVgo,1369
|
6
6
|
checkpointer/test_checkpointer.py,sha256=uJ2Pg9Miq1W0l28eNlRhMjuT_R8c-ygYwp3KP3VW8Os,3600
|
7
|
-
checkpointer/utils.py,sha256=
|
7
|
+
checkpointer/utils.py,sha256=E1AV96NTh3tuVmgPrr0JSKZaokw-Jely5Y6-NjlMCp8,3141
|
8
8
|
checkpointer/storages/__init__.py,sha256=Kl4Og5jhYxn6m3tB_kTMsabf4_eWVLmFVAoC-pikNQE,301
|
9
9
|
checkpointer/storages/bcolz_storage.py,sha256=3QkSUSeG5s2kFuVV_LZpzMn1A5E7kqC7jk7w35c0NyQ,2314
|
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.
|
14
|
-
checkpointer-2.6.
|
15
|
-
checkpointer-2.6.
|
16
|
-
checkpointer-2.6.
|
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,,
|
File without changes
|
File without changes
|