dependency-cache 0.2.1__tar.gz → 0.2.2__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 (30) hide show
  1. {dependency_cache-0.2.1 → dependency_cache-0.2.2}/.github/workflows/Test.yml +8 -0
  2. {dependency_cache-0.2.1 → dependency_cache-0.2.2}/PKG-INFO +2 -2
  3. {dependency_cache-0.2.1 → dependency_cache-0.2.2}/README.md +1 -1
  4. {dependency_cache-0.2.1 → dependency_cache-0.2.2}/pyproject.toml +1 -1
  5. {dependency_cache-0.2.1 → dependency_cache-0.2.2}/python/examples/automagic_dependency_example.py +1 -0
  6. {dependency_cache-0.2.1 → dependency_cache-0.2.2}/python/examples/example.py +1 -0
  7. {dependency_cache-0.2.1 → dependency_cache-0.2.2}/python/examples/inheritance_example.py +1 -1
  8. {dependency_cache-0.2.1 → dependency_cache-0.2.2}/python/examples/manual_dependency_example.py +1 -0
  9. {dependency_cache-0.2.1 → dependency_cache-0.2.2}/python/examples/runtime_dependencies_example.py +19 -4
  10. dependency_cache-0.2.2/python/examples/runtime_function_calls_example.py +34 -0
  11. dependency_cache-0.2.1/python/examples/function_calls_example.py → dependency_cache-0.2.2/python/examples/static_function_calls_example.py +1 -1
  12. dependency_cache-0.2.2/python/examples/use_cache_example.py +30 -0
  13. {dependency_cache-0.2.1 → dependency_cache-0.2.2}/uv.lock +1 -1
  14. dependency_cache-0.2.1/python/examples/use_cache_example.py +0 -30
  15. {dependency_cache-0.2.1 → dependency_cache-0.2.2}/.github/workflows/CI.yml +0 -0
  16. {dependency_cache-0.2.1 → dependency_cache-0.2.2}/.gitignore +0 -0
  17. {dependency_cache-0.2.1 → dependency_cache-0.2.2}/Cargo.lock +0 -0
  18. {dependency_cache-0.2.1 → dependency_cache-0.2.2}/Cargo.toml +0 -0
  19. {dependency_cache-0.2.1 → dependency_cache-0.2.2}/LICENSE +0 -0
  20. {dependency_cache-0.2.1 → dependency_cache-0.2.2}/python/dependency_cache/__init__.py +0 -0
  21. {dependency_cache-0.2.1 → dependency_cache-0.2.2}/python/dependency_cache/dependency_cache.pyi +0 -0
  22. {dependency_cache-0.2.1 → dependency_cache-0.2.2}/python/dependency_cache/plot_dependency_graph.py +0 -0
  23. {dependency_cache-0.2.1 → dependency_cache-0.2.2}/python/test_python.py +0 -0
  24. {dependency_cache-0.2.1 → dependency_cache-0.2.2}/python/test_python_automagic.py +0 -0
  25. {dependency_cache-0.2.1 → dependency_cache-0.2.2}/src/decorator.rs +0 -0
  26. {dependency_cache-0.2.1 → dependency_cache-0.2.2}/src/decorator_factory.rs +0 -0
  27. {dependency_cache-0.2.1 → dependency_cache-0.2.2}/src/dependency_cache_base.rs +0 -0
  28. {dependency_cache-0.2.1 → dependency_cache-0.2.2}/src/dependency_graph.rs +0 -0
  29. {dependency_cache-0.2.1 → dependency_cache-0.2.2}/src/lib.rs +0 -0
  30. {dependency_cache-0.2.1 → dependency_cache-0.2.2}/src/py_introspection_utils.rs +0 -0
@@ -34,3 +34,11 @@ jobs:
34
34
  pip install --upgrade pip pytest
35
35
  maturin develop --release
36
36
  pytest -v
37
+
38
+ - name: Ensure Python examples valid
39
+ run: |
40
+ source venv/bin/activate
41
+ for example in python/examples/*.py; do
42
+ echo "Running $example"
43
+ python "$example"
44
+ done
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dependency_cache
3
- Version: 0.2.1
3
+ Version: 0.2.2
4
4
  Classifier: Programming Language :: Rust
5
5
  Classifier: Programming Language :: Python :: Implementation :: CPython
6
6
  Classifier: Programming Language :: Python :: Implementation :: PyPy
@@ -108,7 +108,7 @@ c.update_cached_value("A", 0) # invalidates C (but not B)
108
108
  print(c.C()) # recalculates C -> 5
109
109
  ```
110
110
 
111
- This example can be found [here](/python/examples/example.py) with more runnable examples and use cases provided in the [python/examples](/python/examples) folder.
111
+ This example can be found [here](https://github.com/XtdWt/dependency_cache/blob/master/python/examples/example.py) with more runnable examples and use cases provided in the [python/examples](https://github.com/XtdWt/dependency_cache/tree/master/python/examples) folder.
112
112
 
113
113
  ```bash
114
114
  uv run ./python/examples/example.py
@@ -90,7 +90,7 @@ c.update_cached_value("A", 0) # invalidates C (but not B)
90
90
  print(c.C()) # recalculates C -> 5
91
91
  ```
92
92
 
93
- This example can be found [here](/python/examples/example.py) with more runnable examples and use cases provided in the [python/examples](/python/examples) folder.
93
+ This example can be found [here](https://github.com/XtdWt/dependency_cache/blob/master/python/examples/example.py) with more runnable examples and use cases provided in the [python/examples](https://github.com/XtdWt/dependency_cache/tree/master/python/examples) folder.
94
94
 
95
95
  ```bash
96
96
  uv run ./python/examples/example.py
@@ -11,7 +11,7 @@ classifiers = [
11
11
  "Programming Language :: Python :: Implementation :: PyPy",
12
12
  ]
13
13
  keywords = ["caching", "dependency-graph", "invalidation"]
14
- version = "0.2.1"
14
+ version = "0.2.2"
15
15
  description = "A caching library for Python object methods that utilises a dependency graph to track relationships and control invalidation, enabling efficient recomputation"
16
16
  readme = "README.md"
17
17
  license = { text = "MIT" }
@@ -42,6 +42,7 @@ class ExampleCalculationMagic(DependencyCacheBase):
42
42
 
43
43
 
44
44
  if __name__ == "__main__":
45
+ print("example of using the automagic parsing of dependencies")
45
46
  print(" E")
46
47
  print(" / \\")
47
48
  print(" D \\")
@@ -29,6 +29,7 @@ class ExampleCalculation(DependencyCacheBase):
29
29
 
30
30
 
31
31
  if __name__ == "__main__":
32
+ print("example of using dependency_cache for recomputation")
32
33
  print(" C")
33
34
  print(" / \\")
34
35
  print("A B")
@@ -32,7 +32,7 @@ class ParentClass(ChildClass):
32
32
 
33
33
 
34
34
  if __name__ == "__main__":
35
- print("dependency graph obeys MRO (standard inheritance method order)")
35
+ print("example that dependency graph obeys MRO (standard inheritance method order)")
36
36
  c = ParentClass()
37
37
 
38
38
  print(f"Result of A {c.A()}") # calculates parent A and does not calculates child
@@ -41,6 +41,7 @@ class ExampleCalculationManual(DependencyCacheBase):
41
41
 
42
42
 
43
43
  if __name__ == "__main__":
44
+ print("example of manually declaring dependencies")
44
45
  print("D E")
45
46
  print(" \\ /")
46
47
  print(" C")
@@ -32,14 +32,29 @@ class RuntimeGraphExample(DependencyCacheBase):
32
32
 
33
33
 
34
34
  if __name__ == "__main__":
35
+ print("example of using runtime dependencies")
36
+ print("graph only partially built!")
37
+ print(" A")
38
+ print(" / |")
39
+ print(" / |")
40
+ print("C B")
35
41
  c = RuntimeGraphExample()
36
42
  print(c.A()) # calculates A, prints 1000
37
- print("graph only partially built!")
38
43
 
39
- print("repeatedly updating D!")
44
+ print("updating D!")
45
+ print(c.D())
40
46
  c.update_cached_value("D", 1)
41
- c.update_cached_value("D", 2)
47
+ print(c.D())
42
48
  c.update_cached_value("D", 3)
43
-
49
+ print(c.D())
44
50
  print(c.A()) # no calculation, returns cached 1000
51
+
52
+ print("graph fully built!")
53
+ print(" A")
54
+ print(" / | \\")
55
+ print(" / | \\")
56
+ print("C B D")
57
+ c.update_cached_value("B", False)
58
+ print(c.A()) # calculates A, prints 3
59
+
45
60
  print(c.get_cached_values(), c.get_dependency_graph(), c.get_validation_state())
@@ -0,0 +1,34 @@
1
+ from dependency_cache import DependencyCacheBase, dependency_cached
2
+
3
+
4
+ class FibonacciExample(DependencyCacheBase):
5
+ def __init__(self):
6
+ super().__init__()
7
+
8
+ @dependency_cached(track_runtime_dependencies=True)
9
+ def Calculate(self, n):
10
+ print(f"calculating the {n=} fibonacci number")
11
+ if n <= 0:
12
+ return 0
13
+ if n == 1:
14
+ return 1
15
+ return self.Calculate(n - 1) + self.Calculate(n - 2)
16
+
17
+
18
+ if __name__ == "__main__":
19
+ print("example of using runtime dependencies, with nested function calls")
20
+ print("Fib(3)")
21
+ print("| \\")
22
+ print("| Fib(2)")
23
+ print("| | \\")
24
+ print("----> Fib(1)")
25
+ print(" | \\")
26
+ print(" ----> Fib(0)")
27
+ c = FibonacciExample()
28
+
29
+ print(f"Result of Fib(3) {c.Calculate(3)}") # calculates Calculate(3), Calculate(2), Calculate(1), Calculate(0)
30
+
31
+ print(f"Result of Fib(2) {c.Calculate(2)}") # cache works for Calculate(2), no more prints
32
+ print(f"Result of Fib(1) {c.Calculate(1)}") # cache works for Calculate(2), no more prints
33
+ print(f"Result of Fib(4) {c.Calculate(4)}") # calculates Calculate(4), rest cached
34
+ print(c.get_cached_values(), c.get_dependency_graph(), c.get_validation_state())
@@ -26,7 +26,7 @@ class FunctionCallObj(DependencyCacheBase):
26
26
 
27
27
 
28
28
  if __name__ == "__main__":
29
- print("dependency graph can have each function call cached")
29
+ print("example of manually defining function calls")
30
30
  c = FunctionCallObj(1)
31
31
 
32
32
  print(f"Result of B {c.B()}") # calculates parent B and does calculates A(0), C, A(1)
@@ -0,0 +1,30 @@
1
+ import time
2
+
3
+ from dependency_cache import DependencyCacheBase, dependency_cached
4
+
5
+
6
+ class UseCacheExample(DependencyCacheBase):
7
+ def __init__(self):
8
+ super().__init__()
9
+
10
+ @dependency_cached(use_cache=False)
11
+ def A(self):
12
+ print("calculating A")
13
+ return time.time()
14
+
15
+ @dependency_cached(dependencies=["A"])
16
+ def B(self):
17
+ print("calculating B")
18
+ return self.A() + 1
19
+
20
+
21
+ if __name__ == "__main__":
22
+ print("example of use_cache flagging permanent invalidation of graph")
23
+ print(" B")
24
+ print(" |")
25
+ print("A (always recalcs)")
26
+ c = UseCacheExample()
27
+ print(f"Result of B = {c.B()}") # calculates all
28
+ print(c.get_cached_values(), c.get_dependency_graph(), c.get_validation_state())
29
+ print(f"Result of B = {c.B()}") # still calculates all
30
+ print(c.get_cached_values(), c.get_dependency_graph(), c.get_validation_state())
@@ -329,7 +329,7 @@ wheels = [
329
329
 
330
330
  [[package]]
331
331
  name = "dependency-cache"
332
- version = "0.2.1"
332
+ version = "0.2.2"
333
333
  source = { editable = "." }
334
334
  dependencies = [
335
335
  { name = "matplotlib", version = "3.7.5", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.9'" },
@@ -1,30 +0,0 @@
1
- import time
2
-
3
- from dependency_cache import DependencyCacheBase, dependency_cached
4
-
5
-
6
- class UseCacheExample(DependencyCacheBase):
7
- def __init__(self):
8
- super().__init__()
9
-
10
- @dependency_cached(use_cache=False)
11
- def A(self):
12
- print("calculating A")
13
- return time.time()
14
-
15
- @dependency_cached(dependencies=["A"])
16
- def B(self):
17
- print("calculating B")
18
- return self.A() + 1
19
-
20
-
21
- if __name__ == "__main__":
22
- if __name__ == "__main__":
23
- print(" B")
24
- print(" |")
25
- print("A (always recalcs)")
26
- c = UseCacheExample()
27
- print(f"Result of B = {c.B()}") # calculates all
28
- print(c.get_cached_values(), c.get_dependency_graph(), c.get_validation_state())
29
- print(f"Result of B = {c.B()}") # still calculates all
30
- print(c.get_cached_values(), c.get_dependency_graph(), c.get_validation_state())