persistent-function-cache 0.3.0__tar.gz → 0.3.1__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.
Files changed (31) hide show
  1. {persistent_function_cache-0.3.0 → persistent_function_cache-0.3.1}/PKG-INFO +4 -4
  2. {persistent_function_cache-0.3.0 → persistent_function_cache-0.3.1}/pyproject.toml +4 -5
  3. {persistent_function_cache-0.3.0 → persistent_function_cache-0.3.1}/src/persistent_cache/cli/clear_cache.py +1 -3
  4. {persistent_function_cache-0.3.0 → persistent_function_cache-0.3.1}/src/persistent_cache/main/cache_slot.py +2 -2
  5. {persistent_function_cache-0.3.0 → persistent_function_cache-0.3.1}/src/persistent_cache/main/decorator.py +2 -1
  6. {persistent_function_cache-0.3.0 → persistent_function_cache-0.3.1}/src/persistent_cache/main/hashing.py +2 -1
  7. {persistent_function_cache-0.3.0 → persistent_function_cache-0.3.1}/src/persistent_cache/models/path.py +1 -3
  8. {persistent_function_cache-0.3.0 → persistent_function_cache-0.3.1}/src/persistent_cache/reducers/base.py +8 -10
  9. {persistent_function_cache-0.3.0 → persistent_function_cache-0.3.1}/src/persistent_cache/reducers/deep_learning.py +5 -7
  10. {persistent_function_cache-0.3.0 → persistent_function_cache-0.3.1}/src/persistent_function_cache.egg-info/PKG-INFO +4 -4
  11. {persistent_function_cache-0.3.0 → persistent_function_cache-0.3.1}/src/persistent_function_cache.egg-info/requires.txt +3 -3
  12. {persistent_function_cache-0.3.0 → persistent_function_cache-0.3.1}/LICENSE +0 -0
  13. {persistent_function_cache-0.3.0 → persistent_function_cache-0.3.1}/README.md +0 -0
  14. {persistent_function_cache-0.3.0 → persistent_function_cache-0.3.1}/setup.cfg +0 -0
  15. {persistent_function_cache-0.3.0 → persistent_function_cache-0.3.1}/src/persistent_cache/__init__.py +0 -0
  16. {persistent_function_cache-0.3.0 → persistent_function_cache-0.3.1}/src/persistent_cache/caches/__init__.py +0 -0
  17. {persistent_function_cache-0.3.0 → persistent_function_cache-0.3.1}/src/persistent_cache/caches/deep_learning.py +0 -0
  18. {persistent_function_cache-0.3.0 → persistent_function_cache-0.3.1}/src/persistent_cache/caches/speedup_deep_learning.py +0 -0
  19. {persistent_function_cache-0.3.0 → persistent_function_cache-0.3.1}/src/persistent_cache/cli/__init__.py +0 -0
  20. {persistent_function_cache-0.3.0 → persistent_function_cache-0.3.1}/src/persistent_cache/main/__init__.py +0 -0
  21. {persistent_function_cache-0.3.0 → persistent_function_cache-0.3.1}/src/persistent_cache/models/__init__.py +0 -0
  22. {persistent_function_cache-0.3.0 → persistent_function_cache-0.3.1}/src/persistent_cache/py.typed +0 -0
  23. {persistent_function_cache-0.3.0 → persistent_function_cache-0.3.1}/src/persistent_cache/reducers/__init__.py +0 -0
  24. {persistent_function_cache-0.3.0 → persistent_function_cache-0.3.1}/src/persistent_cache/reducers/speedup_deep_learning.py +0 -0
  25. {persistent_function_cache-0.3.0 → persistent_function_cache-0.3.1}/src/persistent_function_cache.egg-info/SOURCES.txt +0 -0
  26. {persistent_function_cache-0.3.0 → persistent_function_cache-0.3.1}/src/persistent_function_cache.egg-info/dependency_links.txt +0 -0
  27. {persistent_function_cache-0.3.0 → persistent_function_cache-0.3.1}/src/persistent_function_cache.egg-info/entry_points.txt +0 -0
  28. {persistent_function_cache-0.3.0 → persistent_function_cache-0.3.1}/src/persistent_function_cache.egg-info/top_level.txt +0 -0
  29. {persistent_function_cache-0.3.0 → persistent_function_cache-0.3.1}/tests/test_cache.py +0 -0
  30. {persistent_function_cache-0.3.0 → persistent_function_cache-0.3.1}/tests/test_clear_cache.py +0 -0
  31. {persistent_function_cache-0.3.0 → persistent_function_cache-0.3.1}/tests/test_deep_learning_cache.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: persistent-function-cache
3
- Version: 0.3.0
3
+ Version: 0.3.1
4
4
  Summary: Persistent cache for expensive functions
5
5
  Author-email: Quinten Roets <qdr2104@columbia.edu>
6
6
  License-Expression: MIT
@@ -8,11 +8,11 @@ Project-URL: Source Code, https://github.com/quintenroets/persistent-cache
8
8
  Requires-Python: >=3.11
9
9
  Description-Content-Type: text/markdown
10
10
  License-File: LICENSE
11
- Requires-Dist: package-utils<1,>=0.8.5
11
+ Requires-Dist: package-utils<1,>=0.9.1
12
12
  Requires-Dist: powercli<1,>=0.4.0
13
- Requires-Dist: superpathlib<3,>=2.0.13
13
+ Requires-Dist: superpathlib<3,>=2.1.0
14
14
  Provides-Extra: dev
15
- Requires-Dist: package-dev-tools<1,>=0.8.1; extra == "dev"
15
+ Requires-Dist: package-dev-tools<1,>=0.8.7; extra == "dev"
16
16
  Requires-Dist: package-dev-utils<1,>=0.1.6; extra == "dev"
17
17
  Requires-Dist: numpy<3,>=1.26.0; extra == "dev"
18
18
  Requires-Dist: torch<3,>=1.26.0; extra == "dev"
@@ -1,20 +1,20 @@
1
1
  [project]
2
2
  name = "persistent-function-cache"
3
- version = "0.3.0"
3
+ version = "0.3.1"
4
4
  description = "Persistent cache for expensive functions"
5
5
  authors = [{name = "Quinten Roets", email = "qdr2104@columbia.edu"}]
6
6
  license = "MIT"
7
7
  readme = "README.md"
8
8
  requires-python = ">=3.11"
9
9
  dependencies = [
10
- "package-utils >=0.8.5, <1",
10
+ "package-utils >=0.9.1, <1",
11
11
  "powercli >=0.4.0, <1",
12
- "superpathlib >=2.0.13, <3",
12
+ "superpathlib >=2.1.0, <3",
13
13
  ]
14
14
 
15
15
  [project.optional-dependencies]
16
16
  dev = [
17
- "package-dev-tools >=0.8.1, <1",
17
+ "package-dev-tools >=0.8.7, <1",
18
18
  "package-dev-utils >=0.1.6, <1",
19
19
  "numpy >=1.26.0, <3",
20
20
  "torch >=1.26.0, <3",
@@ -54,7 +54,6 @@ select = ["ALL"]
54
54
  ignore = [
55
55
  "ANN401", # annotated with Any
56
56
  "CPY001", # missing copyright notice
57
- "D", # docstrings
58
57
  "D1", # missing docstrings
59
58
  "D200", # one-line docstring
60
59
  "D203", # conflicts with D211
@@ -42,9 +42,7 @@ def main(options: Options) -> None:
42
42
  for path in Options.cache_path.find(should_remove, recurse_on_match=True):
43
43
  if options.verbose:
44
44
  relative_path = path.relative_to(Options.cache_path)
45
- timestamp = datetime.fromtimestamp(path.mtime).astimezone(
46
- tz=UTC,
47
- )
45
+ timestamp = datetime.fromtimestamp(path.mtime).astimezone(tz=UTC)
48
46
  message = f"{relative_path} ({timestamp})"
49
47
  cli.console.print(message)
50
48
  path.unlink()
@@ -30,8 +30,8 @@ class CacheSlot:
30
30
  try:
31
31
  with self.path.open("rb") as fp:
32
32
  return pickle.Unpickler(fp).load() # noqa: S301
33
- except (pickle.UnpicklingError, EOFError):
34
- # discard values of corrupted or empty slots
33
+ except (FileNotFoundError, pickle.UnpicklingError, EOFError):
34
+ # discard values of missing, corrupted or empty slots
35
35
  raise KeyError from None
36
36
 
37
37
  @value.setter
@@ -49,7 +49,8 @@ def cache( # noqa: PLR0913
49
49
  deep_learning: bool = False,
50
50
  speedup_deep_learning: bool = False,
51
51
  ) -> F | Callable[[F], F]:
52
- """A decorator to cache function results. Decorated functions are only executed if
52
+ """
53
+ A decorator to cache function results. Decorated functions are only executed if
53
54
  result is not present in cache. The arguments of the function can be any nested
54
55
  complex object.
55
56
 
@@ -30,7 +30,8 @@ class HashPickler(pickle.Pickler):
30
30
  self.reducers = load_reducers(reducer) # type: ignore[arg-type]
31
31
 
32
32
  def reducer_override(self, obj: Any) -> Any:
33
- """The goal of this pickler is to create hashes of complex objects, not to
33
+ """
34
+ The goal of this pickler is to create hashes of complex objects, not to
34
35
  reconstruct complex objects.
35
36
 
36
37
  So mapping does not need to be reversible.
@@ -1,10 +1,8 @@
1
- from typing import Self, TypeVar, cast
1
+ from typing import Self, cast
2
2
 
3
3
  import superpathlib
4
4
  from simple_classproperty import classproperty
5
5
 
6
- T = TypeVar("T", bound="Path")
7
-
8
6
 
9
7
  class Path(superpathlib.Path):
10
8
  @classmethod
@@ -4,7 +4,8 @@ from types import FunctionType, ModuleType
4
4
 
5
5
 
6
6
  class Reducer:
7
- """Inherit from this class to implement own custom pickler.
7
+ """
8
+ Inherit from this class to implement own custom pickler.
8
9
 
9
10
  The result of each function are pickled further with their custom
10
11
  pickling function, so make sure to reduce each object to a new
@@ -14,15 +15,12 @@ class Reducer:
14
15
 
15
16
  @classmethod
16
17
  def reduce_code(cls, code_object: FunctionType | ModuleType | type) -> str:
17
- """
18
- custom lambda reduction needed:
19
- https://www.pythonpool.com/cant-pickle-local-object/
20
- custom module reduction needed:
21
- https://stackoverflow.com/questions/2790828/python-cant-pickle-module-objects-error
22
- name reduction for function/module/class is not enough because we assume
23
- cache result can change when function/module/class implementation changes
24
- """
25
-
18
+ # name reduction for function/module/class is not enough because we assume
19
+ # cache result can change when function/module/class implementation changes
20
+ # custom lambda reduction needed:
21
+ # https://www.pythonpool.com/cant-pickle-local-object/
22
+ # custom module reduction needed:
23
+ # https://stackoverflow.com/questions/2790828/python-cant-pickle-module-objects-error
26
24
  try:
27
25
  reduction = inspect.getsource(code_object)
28
26
  except (TypeError, OSError):
@@ -9,13 +9,11 @@ from . import base
9
9
  class Reducer(base.Reducer):
10
10
  @classmethod
11
11
  def reduce_model(cls, model: torch.nn.Module) -> tuple[dict[str, Any], Any]:
12
- """
13
- Avoid pickling _forward_hooks of model:
14
- implemented as OrderedDict with nondeterministic keys
15
- Model outputs determined by:
16
- - model weights
17
- - class implementation (forward method)
18
- """
12
+ # avoid pickling _forward_hooks of model:
13
+ # implemented as OrderedDict with nondeterministic keys
14
+ # model outputs determined by:
15
+ # - model weights
16
+ # - class implementation (forward method)
19
17
  return model.state_dict(), model.__class__
20
18
 
21
19
  @classmethod
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: persistent-function-cache
3
- Version: 0.3.0
3
+ Version: 0.3.1
4
4
  Summary: Persistent cache for expensive functions
5
5
  Author-email: Quinten Roets <qdr2104@columbia.edu>
6
6
  License-Expression: MIT
@@ -8,11 +8,11 @@ Project-URL: Source Code, https://github.com/quintenroets/persistent-cache
8
8
  Requires-Python: >=3.11
9
9
  Description-Content-Type: text/markdown
10
10
  License-File: LICENSE
11
- Requires-Dist: package-utils<1,>=0.8.5
11
+ Requires-Dist: package-utils<1,>=0.9.1
12
12
  Requires-Dist: powercli<1,>=0.4.0
13
- Requires-Dist: superpathlib<3,>=2.0.13
13
+ Requires-Dist: superpathlib<3,>=2.1.0
14
14
  Provides-Extra: dev
15
- Requires-Dist: package-dev-tools<1,>=0.8.1; extra == "dev"
15
+ Requires-Dist: package-dev-tools<1,>=0.8.7; extra == "dev"
16
16
  Requires-Dist: package-dev-utils<1,>=0.1.6; extra == "dev"
17
17
  Requires-Dist: numpy<3,>=1.26.0; extra == "dev"
18
18
  Requires-Dist: torch<3,>=1.26.0; extra == "dev"
@@ -1,9 +1,9 @@
1
- package-utils<1,>=0.8.5
1
+ package-utils<1,>=0.9.1
2
2
  powercli<1,>=0.4.0
3
- superpathlib<3,>=2.0.13
3
+ superpathlib<3,>=2.1.0
4
4
 
5
5
  [dev]
6
- package-dev-tools<1,>=0.8.1
6
+ package-dev-tools<1,>=0.8.7
7
7
  package-dev-utils<1,>=0.1.6
8
8
  numpy<3,>=1.26.0
9
9
  torch<3,>=1.26.0