persistent-function-cache 0.2.1__py3-none-any.whl → 0.2.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.
@@ -3,6 +3,7 @@ import pickle
3
3
  from collections.abc import Callable, Iterable, Iterator
4
4
  from dataclasses import dataclass
5
5
  from functools import cached_property
6
+ from inspect import BoundArguments
6
7
  from typing import Any
7
8
 
8
9
  from persistent_cache.models import Path
@@ -18,6 +19,7 @@ class CacheSlot:
18
19
  kwargs: dict[str, Any]
19
20
  directory: Path
20
21
  key_arguments: Iterable[str] | str | None
22
+ argument_reducers: dict[str, Callable[[Any], Any]] | None
21
23
  extra_keys: Any
22
24
  key_reducer: type[Reducer] | None
23
25
  deep_learning: bool
@@ -60,17 +62,25 @@ class CacheSlot:
60
62
 
61
63
  @property
62
64
  def argument_values(self) -> Iterator[Any]:
63
- if self.key_arguments is None:
65
+ if self.key_arguments is None and self.argument_reducers is None:
64
66
  yield from self.args
65
67
  yield from self.kwargs.values()
66
68
  else:
67
69
  arguments = inspect.signature(self.function).bind(*self.args, **self.kwargs)
68
70
  arguments.apply_defaults()
71
+ yield from self.extract_argument_values(arguments)
72
+
73
+ def extract_argument_values(self, arguments: BoundArguments) -> Iterator[Any]:
74
+ if self.key_arguments is not None:
69
75
  if isinstance(self.key_arguments, str):
70
76
  yield arguments.arguments.get(self.key_arguments)
71
77
  else:
72
78
  for name in self.key_arguments:
73
79
  yield arguments.arguments.get(name)
80
+ if self.argument_reducers is not None:
81
+ for argument_name, reducer in self.argument_reducers.items():
82
+ argument = arguments.arguments.get(argument_name)
83
+ yield reducer(argument)
74
84
 
75
85
  @property
76
86
  def reducer(self) -> type[Reducer]:
@@ -16,6 +16,7 @@ def cache(
16
16
  *,
17
17
  cache_directory: Path = Path.cache,
18
18
  cache_key_arguments: Iterable[str] | str | None = None,
19
+ argument_reducers: dict[str, Callable[[Any], Any]] | None = None,
19
20
  extra_cache_keys: Iterable[Any] | None = None,
20
21
  key_reducer: type[Reducer] = Reducer,
21
22
  deep_learning: bool = False,
@@ -29,6 +30,7 @@ def cache(
29
30
  *,
30
31
  cache_directory: Path = Path.cache,
31
32
  cache_key_arguments: Iterable[str] | str | None = None,
33
+ argument_reducers: dict[str, Callable[[Any], Any]] | None = None,
32
34
  extra_cache_keys: Any = None,
33
35
  key_reducer: type[Reducer] = Reducer,
34
36
  deep_learning: bool = False,
@@ -41,6 +43,7 @@ def cache( # noqa: PLR0913
41
43
  *,
42
44
  cache_directory: Path = Path.cache,
43
45
  cache_key_arguments: Iterable[str] | str | None = None,
46
+ argument_reducers: dict[str, Callable[[Any], Any]] | None = None,
44
47
  extra_cache_keys: Any = None,
45
48
  key_reducer: type[Reducer] | None = None,
46
49
  deep_learning: bool = False,
@@ -68,6 +71,7 @@ def cache( # noqa: PLR0913
68
71
  kwargs,
69
72
  cache_directory,
70
73
  cache_key_arguments,
74
+ argument_reducers,
71
75
  extra_cache_keys,
72
76
  key_reducer,
73
77
  deep_learning,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: persistent-function-cache
3
- Version: 0.2.1
3
+ Version: 0.2.2
4
4
  Summary: Persistent cache for expensive functions
5
5
  Author-email: Quinten Roets <qdr2104@columbia.edu>
6
6
  License: MIT
@@ -6,8 +6,8 @@ persistent_cache/caches/speedup_deep_learning.py,sha256=bywNXeEZsg8Rs2A1_w-ZrJi9
6
6
  persistent_cache/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
7
  persistent_cache/cli/clear_cache.py,sha256=YbKfqzUB9IyEpU-2n0h5BrK9kZKjbayqiMTzjPbDl3s,1541
8
8
  persistent_cache/main/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
- persistent_cache/main/cache_slot.py,sha256=9zBrcTGJ-oEUryftiGqBks_mdrkX2s_c0b2Pisc5vvU,2716
10
- persistent_cache/main/decorator.py,sha256=tvrgv_lTxldgxfWnvzJKvDC00oE8eenPY5VdPZxiywM,2439
9
+ persistent_cache/main/cache_slot.py,sha256=MmWBcz798QA8N6CPXXNxYmlGb3HwbG21NbbFcavH6eU,3265
10
+ persistent_cache/main/decorator.py,sha256=lE_0q-KEavCe8IaK8hwuMUxH-tkN1_v-Jgy_dM_8Uxw,2684
11
11
  persistent_cache/main/hashing.py,sha256=6GYzUJcqjfjHPWMqPOCEY9FUSH2k2zUGrUza2fKaMTQ,2688
12
12
  persistent_cache/models/__init__.py,sha256=1OeLZ6FZ5gAjlerAjc69Vx0AqWLSx6OSqNCpuzkCZQg,23
13
13
  persistent_cache/models/path.py,sha256=-HRJ4yqqmBPlax4H0KS8guhndBXNwCnl7WZXhtaWmGQ,441
@@ -15,9 +15,9 @@ persistent_cache/reducers/__init__.py,sha256=hCozFuvrAb_gXLcqMMq92v4KdwBbQugwGwC
15
15
  persistent_cache/reducers/base.py,sha256=HsodcuE8Id5oV93_b_RN18I69UWsJ21yazXCwT1f6YU,1428
16
16
  persistent_cache/reducers/deep_learning.py,sha256=cyVolwmwm_ZN2gRxPtfJFqiNQlNuq_CrehO7ZSVWeVw,800
17
17
  persistent_cache/reducers/speedup_deep_learning.py,sha256=kMkr1467zUsQUPOi_N8tWKWAtKUcFgsk3rh94QhETg0,1970
18
- persistent_function_cache-0.2.1.dist-info/LICENSE,sha256=ENpNaBSvIV7ifD7iNz_-lBhImbiYowqPzBc5V5R8IhM,1070
19
- persistent_function_cache-0.2.1.dist-info/METADATA,sha256=E_GxkYLEh9vSXGpVYv9cKAMDTjqHRJDZc6d44WcqQXs,2164
20
- persistent_function_cache-0.2.1.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
21
- persistent_function_cache-0.2.1.dist-info/entry_points.txt,sha256=fSZfuL6Wn42mZldojgGyg7dzSPCRVAuZox3w6dLd2ZI,88
22
- persistent_function_cache-0.2.1.dist-info/top_level.txt,sha256=Jj-Z9wxHRlRyDUxrfC9GeaV5-8hAf8R4LclQFZesxi8,17
23
- persistent_function_cache-0.2.1.dist-info/RECORD,,
18
+ persistent_function_cache-0.2.2.dist-info/LICENSE,sha256=ENpNaBSvIV7ifD7iNz_-lBhImbiYowqPzBc5V5R8IhM,1070
19
+ persistent_function_cache-0.2.2.dist-info/METADATA,sha256=PoI9EMIFqiZ21RHpHKNctkbdhu7h0LdHWD7TS-8_Krc,2164
20
+ persistent_function_cache-0.2.2.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
21
+ persistent_function_cache-0.2.2.dist-info/entry_points.txt,sha256=fSZfuL6Wn42mZldojgGyg7dzSPCRVAuZox3w6dLd2ZI,88
22
+ persistent_function_cache-0.2.2.dist-info/top_level.txt,sha256=Jj-Z9wxHRlRyDUxrfC9GeaV5-8hAf8R4LclQFZesxi8,17
23
+ persistent_function_cache-0.2.2.dist-info/RECORD,,