dependency-cache 0.1.0__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 (27) hide show
  1. dependency_cache-0.1.0/.github/workflows/CI.yml +169 -0
  2. dependency_cache-0.1.0/.github/workflows/Test.yml +34 -0
  3. dependency_cache-0.1.0/.gitignore +76 -0
  4. dependency_cache-0.1.0/Cargo.lock +132 -0
  5. dependency_cache-0.1.0/Cargo.toml +27 -0
  6. dependency_cache-0.1.0/LICENSE +21 -0
  7. dependency_cache-0.1.0/PKG-INFO +118 -0
  8. dependency_cache-0.1.0/README.md +99 -0
  9. dependency_cache-0.1.0/pyproject.toml +35 -0
  10. dependency_cache-0.1.0/python/dependency_cache/__init__.py +13 -0
  11. dependency_cache-0.1.0/python/dependency_cache/dependency_cache.pyi +35 -0
  12. dependency_cache-0.1.0/python/dependency_cache/plot_dependency_graph.py +43 -0
  13. dependency_cache-0.1.0/python/examples/automagic_dependency_example.py +56 -0
  14. dependency_cache-0.1.0/python/examples/example.py +42 -0
  15. dependency_cache-0.1.0/python/examples/function_calls_example.py +37 -0
  16. dependency_cache-0.1.0/python/examples/inheritance_example.py +44 -0
  17. dependency_cache-0.1.0/python/examples/manual_dependency_example.py +54 -0
  18. dependency_cache-0.1.0/python/examples/use_cache_example.py +30 -0
  19. dependency_cache-0.1.0/python/test_python.py +310 -0
  20. dependency_cache-0.1.0/python/test_python_automagic.py +310 -0
  21. dependency_cache-0.1.0/src/decorator.rs +100 -0
  22. dependency_cache-0.1.0/src/decorator_factory.rs +148 -0
  23. dependency_cache-0.1.0/src/dependency_cache_base.rs +272 -0
  24. dependency_cache-0.1.0/src/dependency_graph.rs +380 -0
  25. dependency_cache-0.1.0/src/lib.rs +24 -0
  26. dependency_cache-0.1.0/src/normalise_method_args.rs +62 -0
  27. dependency_cache-0.1.0/uv.lock +2058 -0
@@ -0,0 +1,169 @@
1
+ # This file is autogenerated by maturin v1.9.6
2
+ # To update, run
3
+ #
4
+ # maturin generate-ci github
5
+ #
6
+ name: CI
7
+
8
+ on:
9
+ workflow_dispatch:
10
+
11
+ permissions:
12
+ contents: read
13
+
14
+ jobs:
15
+ linux:
16
+ runs-on: ${{ matrix.platform.runner }}
17
+ strategy:
18
+ matrix:
19
+ platform:
20
+ - runner: ubuntu-22.04
21
+ target: x86_64
22
+ - runner: ubuntu-22.04
23
+ target: x86
24
+ - runner: ubuntu-22.04
25
+ target: aarch64
26
+ - runner: ubuntu-22.04
27
+ target: armv7
28
+ - runner: ubuntu-22.04
29
+ target: s390x
30
+ - runner: ubuntu-22.04
31
+ target: ppc64le
32
+ steps:
33
+ - uses: actions/checkout@v4
34
+ - uses: actions/setup-python@v5
35
+ with:
36
+ python-version: 3.x
37
+ - name: Build wheels
38
+ uses: PyO3/maturin-action@v1
39
+ with:
40
+ target: ${{ matrix.platform.target }}
41
+ args: --release --out dist --find-interpreter
42
+ sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
43
+ manylinux: auto
44
+ - name: Upload wheels
45
+ uses: actions/upload-artifact@v4
46
+ with:
47
+ name: wheels-linux-${{ matrix.platform.target }}
48
+ path: dist
49
+
50
+ musllinux:
51
+ runs-on: ${{ matrix.platform.runner }}
52
+ strategy:
53
+ matrix:
54
+ platform:
55
+ - runner: ubuntu-22.04
56
+ target: x86_64
57
+ - runner: ubuntu-22.04
58
+ target: x86
59
+ - runner: ubuntu-22.04
60
+ target: aarch64
61
+ - runner: ubuntu-22.04
62
+ target: armv7
63
+ steps:
64
+ - uses: actions/checkout@v4
65
+ - uses: actions/setup-python@v5
66
+ with:
67
+ python-version: 3.x
68
+ - name: Build wheels
69
+ uses: PyO3/maturin-action@v1
70
+ with:
71
+ target: ${{ matrix.platform.target }}
72
+ args: --release --out dist --find-interpreter
73
+ sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
74
+ manylinux: musllinux_1_2
75
+ - name: Upload wheels
76
+ uses: actions/upload-artifact@v4
77
+ with:
78
+ name: wheels-musllinux-${{ matrix.platform.target }}
79
+ path: dist
80
+
81
+ windows:
82
+ runs-on: ${{ matrix.platform.runner }}
83
+ strategy:
84
+ matrix:
85
+ platform:
86
+ - runner: windows-latest
87
+ target: x64
88
+ - runner: windows-latest
89
+ target: x86
90
+ steps:
91
+ - uses: actions/checkout@v4
92
+ - uses: actions/setup-python@v5
93
+ with:
94
+ python-version: 3.x
95
+ architecture: ${{ matrix.platform.target }}
96
+ - name: Build wheels
97
+ uses: PyO3/maturin-action@v1
98
+ with:
99
+ target: ${{ matrix.platform.target }}
100
+ args: --release --out dist --find-interpreter
101
+ sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
102
+ - name: Upload wheels
103
+ uses: actions/upload-artifact@v4
104
+ with:
105
+ name: wheels-windows-${{ matrix.platform.target }}
106
+ path: dist
107
+
108
+ macos:
109
+ runs-on: ${{ matrix.platform.runner }}
110
+ strategy:
111
+ matrix:
112
+ platform:
113
+ - runner: macos-15-intel
114
+ target: x86_64
115
+ - runner: macos-14
116
+ target: aarch64
117
+ steps:
118
+ - uses: actions/checkout@v4
119
+ - uses: actions/setup-python@v5
120
+ with:
121
+ python-version: 3.x
122
+ - name: Build wheels
123
+ uses: PyO3/maturin-action@v1
124
+ with:
125
+ target: ${{ matrix.platform.target }}
126
+ args: --release --out dist --find-interpreter
127
+ sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
128
+ - name: Upload wheels
129
+ uses: actions/upload-artifact@v4
130
+ with:
131
+ name: wheels-macos-${{ matrix.platform.target }}
132
+ path: dist
133
+
134
+ sdist:
135
+ runs-on: ubuntu-latest
136
+ steps:
137
+ - uses: actions/checkout@v4
138
+ - name: Build sdist
139
+ uses: PyO3/maturin-action@v1
140
+ with:
141
+ command: sdist
142
+ args: --out dist
143
+ - name: Upload sdist
144
+ uses: actions/upload-artifact@v4
145
+ with:
146
+ name: wheels-sdist
147
+ path: dist
148
+
149
+ release:
150
+ name: Release
151
+ runs-on: ubuntu-latest
152
+ if: ${{ startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch' }}
153
+ needs: [linux, musllinux, windows, macos, sdist]
154
+ permissions:
155
+ id-token: write
156
+ contents: write
157
+ attestations: write
158
+ steps:
159
+ - uses: actions/download-artifact@v4
160
+ - name: Generate artifact attestation
161
+ uses: actions/attest-build-provenance@v2
162
+ with:
163
+ subject-path: 'wheels-*/*'
164
+ - name: Publish to PyPI
165
+ uses: PyO3/maturin-action@v1
166
+ with:
167
+ command: upload
168
+ args: --non-interactive --skip-existing wheels-*/*
169
+ trust-publishing: true
@@ -0,0 +1,34 @@
1
+ name: Test
2
+
3
+ on:
4
+ push:
5
+ branches: [ "master" ]
6
+ pull_request:
7
+ branches: [ "master" ]
8
+
9
+ env:
10
+ CARGO_TERM_COLOR: always
11
+
12
+ jobs:
13
+ build:
14
+ runs-on: ubuntu-latest
15
+
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+
19
+ - name: Set up Python
20
+ uses: actions/setup-python@v5
21
+ with:
22
+ python-version: "3.12"
23
+
24
+ - name: Testing Rust
25
+ run: cargo test --verbose
26
+
27
+ - name: Build and Testing Python
28
+ run: |
29
+ python -m venv venv
30
+ source venv/bin/activate
31
+ pip install --upgrade pip maturin
32
+ pip install --upgrade pip pytest
33
+ maturin develop --release
34
+ pytest -v
@@ -0,0 +1,76 @@
1
+ /target
2
+
3
+ # Byte-compiled / optimized / DLL files
4
+ __pycache__/
5
+ .pytest_cache/
6
+ *.py[cod]
7
+ *.pdb
8
+
9
+ # C extensions
10
+ *.so
11
+
12
+ # Distribution / packaging
13
+ .Python
14
+ .venv/
15
+ env/
16
+ bin/
17
+ build/
18
+ develop-eggs/
19
+ dist/
20
+ eggs/
21
+ lib/
22
+ lib64/
23
+ parts/
24
+ sdist/
25
+ var/
26
+ include/
27
+ man/
28
+ venv/
29
+ *.egg-info/
30
+ .installed.cfg
31
+ *.egg
32
+
33
+ # Installer logs
34
+ pip-log.txt
35
+ pip-delete-this-directory.txt
36
+ pip-selfcheck.json
37
+
38
+ # Unit test / coverage reports
39
+ htmlcov/
40
+ .tox/
41
+ .coverage
42
+ .cache
43
+ nosetests.xml
44
+ coverage.xml
45
+
46
+ # Translations
47
+ *.mo
48
+
49
+ # Mr Developer
50
+ .mr.developer.cfg
51
+ .project
52
+ .pydevproject
53
+
54
+ # Rope
55
+ .ropeproject
56
+
57
+ # Django stuff:
58
+ *.log
59
+ *.pot
60
+
61
+ .DS_Store
62
+
63
+ # Sphinx documentation
64
+ docs/_build/
65
+
66
+ # PyCharm
67
+ .idea/
68
+
69
+ # VSCode
70
+ .vscode/
71
+
72
+ # Pyenv
73
+ .python-version
74
+
75
+ # ruff cache
76
+ .ruff_cache
@@ -0,0 +1,132 @@
1
+ # This file is automatically @generated by Cargo.
2
+ # It is not intended for manual editing.
3
+ version = 4
4
+
5
+ [[package]]
6
+ name = "dependency_cache"
7
+ version = "0.1.0"
8
+ dependencies = [
9
+ "pyo3",
10
+ ]
11
+
12
+ [[package]]
13
+ name = "heck"
14
+ version = "0.5.0"
15
+ source = "registry+https://github.com/rust-lang/crates.io-index"
16
+ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
17
+
18
+ [[package]]
19
+ name = "libc"
20
+ version = "0.2.187"
21
+ source = "registry+https://github.com/rust-lang/crates.io-index"
22
+ checksum = "a7743783ea728ef5c31194c6590797eed286449b4a4e87d626d8a51f0a94e732"
23
+
24
+ [[package]]
25
+ name = "once_cell"
26
+ version = "1.21.4"
27
+ source = "registry+https://github.com/rust-lang/crates.io-index"
28
+ checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
29
+
30
+ [[package]]
31
+ name = "portable-atomic"
32
+ version = "1.14.0"
33
+ source = "registry+https://github.com/rust-lang/crates.io-index"
34
+ checksum = "3d20d5497ef88037a52ff98267d066e7f11fcc5e99bbfbd58a42336193aacec3"
35
+
36
+ [[package]]
37
+ name = "proc-macro2"
38
+ version = "1.0.107"
39
+ source = "registry+https://github.com/rust-lang/crates.io-index"
40
+ checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
41
+ dependencies = [
42
+ "unicode-ident",
43
+ ]
44
+
45
+ [[package]]
46
+ name = "pyo3"
47
+ version = "0.29.2"
48
+ source = "registry+https://github.com/rust-lang/crates.io-index"
49
+ checksum = "4688ddedf473e32662b9b067670129a8afb8c18e351482c70d62ba4a88171e8b"
50
+ dependencies = [
51
+ "libc",
52
+ "once_cell",
53
+ "portable-atomic",
54
+ "pyo3-build-config",
55
+ "pyo3-ffi",
56
+ "pyo3-macros",
57
+ ]
58
+
59
+ [[package]]
60
+ name = "pyo3-build-config"
61
+ version = "0.29.2"
62
+ source = "registry+https://github.com/rust-lang/crates.io-index"
63
+ checksum = "f41027e41b4bd03f6e60f9f417fe24a6341a6bb744edd62b6f709f2a52ea30e9"
64
+ dependencies = [
65
+ "target-lexicon",
66
+ ]
67
+
68
+ [[package]]
69
+ name = "pyo3-ffi"
70
+ version = "0.29.2"
71
+ source = "registry+https://github.com/rust-lang/crates.io-index"
72
+ checksum = "e591a95526fead067432c3b3a33fc74770b87b1e04e73671090d9c2055a2b327"
73
+ dependencies = [
74
+ "libc",
75
+ "pyo3-build-config",
76
+ ]
77
+
78
+ [[package]]
79
+ name = "pyo3-macros"
80
+ version = "0.29.2"
81
+ source = "registry+https://github.com/rust-lang/crates.io-index"
82
+ checksum = "73225868fc1cd84eef2c3c230ddb91273bf1de46aeb8a4248da76d32a0924a1c"
83
+ dependencies = [
84
+ "proc-macro2",
85
+ "pyo3-macros-backend",
86
+ "quote",
87
+ "syn",
88
+ ]
89
+
90
+ [[package]]
91
+ name = "pyo3-macros-backend"
92
+ version = "0.29.2"
93
+ source = "registry+https://github.com/rust-lang/crates.io-index"
94
+ checksum = "571575aa3749fa6216757dd47d2a3e7ef360f329a40f0666a9fbd14889024952"
95
+ dependencies = [
96
+ "heck",
97
+ "proc-macro2",
98
+ "quote",
99
+ "syn",
100
+ ]
101
+
102
+ [[package]]
103
+ name = "quote"
104
+ version = "1.0.47"
105
+ source = "registry+https://github.com/rust-lang/crates.io-index"
106
+ checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
107
+ dependencies = [
108
+ "proc-macro2",
109
+ ]
110
+
111
+ [[package]]
112
+ name = "syn"
113
+ version = "2.0.119"
114
+ source = "registry+https://github.com/rust-lang/crates.io-index"
115
+ checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297"
116
+ dependencies = [
117
+ "proc-macro2",
118
+ "quote",
119
+ "unicode-ident",
120
+ ]
121
+
122
+ [[package]]
123
+ name = "target-lexicon"
124
+ version = "0.13.5"
125
+ source = "registry+https://github.com/rust-lang/crates.io-index"
126
+ checksum = "adb6935a6f5c20170eeceb1a3835a49e12e19d792f6dd344ccc76a985ca5a6ca"
127
+
128
+ [[package]]
129
+ name = "unicode-ident"
130
+ version = "1.0.24"
131
+ source = "registry+https://github.com/rust-lang/crates.io-index"
132
+ checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
@@ -0,0 +1,27 @@
1
+ [package]
2
+ name = "dependency_cache"
3
+ version = "0.1.0"
4
+ edition = "2021"
5
+ readme = "README.md"
6
+
7
+ # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8
+ [lib]
9
+ name = "dependency_cache"
10
+ crate-type = ["cdylib"]
11
+
12
+ [dependencies.pyo3]
13
+ version = "0.29.*"
14
+ features = [
15
+ "abi3-py38",
16
+ "extension-module",
17
+ "experimental-inspect",
18
+ ]
19
+
20
+ [profile.release]
21
+ lto = "fat"
22
+ codegen-units = 1
23
+ opt-level = 3
24
+
25
+ [lints.clippy]
26
+ needless_return = "allow"
27
+ unused_unit = "allow"
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 XtdWt
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,118 @@
1
+ Metadata-Version: 2.4
2
+ Name: dependency_cache
3
+ Version: 0.1.0
4
+ Classifier: Programming Language :: Rust
5
+ Classifier: Programming Language :: Python :: Implementation :: CPython
6
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
7
+ Requires-Dist: matplotlib>=3.7.5
8
+ Requires-Dist: networkx>=3.1
9
+ License-File: LICENSE
10
+ Summary: A caching system with a dependency graph for invalidation
11
+ Keywords: caching,dependency-graph,invalidation
12
+ License: MIT
13
+ Requires-Python: >=3.8
14
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
15
+ Project-URL: Homepage, https://github.com/XtdWt/dependency_cache
16
+ Project-URL: Issues, https://github.com/XtdWt/dependency_cache/issues
17
+ Project-URL: Repository, https://github.com/XtdWt/dependency_cache
18
+
19
+ # Dependency Cache
20
+ ## :construction: Work In Progress :construction:
21
+
22
+ ### Description
23
+ A library for managing the caching of an object's methods with cache invalidation handled by a dependency graph.
24
+ Instead of recomputing expensive, deeply nested calculations on every call, Dependency Cache stores the result and only invalidates (and recalculates) it when one of its dependencies actually changes.
25
+ This project is written in rust, with [pyo3](https://github.com/PyO3/pyo3), and compiled using [maturin](https://github.com/PyO3/maturin).
26
+
27
+ ### API Overview
28
+
29
+ | Export | What it's for |
30
+ |---|---|
31
+ | `DependencyCacheBase` | Base class to inherit from. Gives your instance a cache and a dependency graph. |
32
+ | `dependency_cached(use_cache=True, dependencies=[...], track_runtime_dependencies=False)` | A footgun-enabled :gun: decorator for a method where you **explicitly declare** direct dependencies. |
33
+ | `automagically_dependency_cached(use_cache=True, dependencies=[...], track_runtime_dependencies=True)` | A decorator which **automagically infers** the direct dependencies with the option to override manually using `dependencies=`. |
34
+ | `plot_dependency_graph(obj, **kwargs)` | Visualizes an instance's dependency graph, for inspection/debugging. |
35
+
36
+ ### Setup
37
+ This project uses (and requires) [uv](https://github.com/astral-sh/uv) as a package manager and maturin to compile.
38
+
39
+ Steps:
40
+ - install python dependencies
41
+ ```bash
42
+ uv sync
43
+ ```
44
+ - generate local development file for testing (and update pyi file for accurate typechecking)
45
+ ```bash
46
+ maturin develop --generate-stubs
47
+ maturin develop -r --generate-stubs
48
+ ```
49
+ - run python tests
50
+ ```bash
51
+ uv run pytest
52
+ uv run pytest -vv
53
+ ```
54
+ - run rust tests
55
+ ```bash
56
+ cargo test
57
+ ```
58
+ - temporary fix: generate stubs currently produces a file that is incorrectly formatted, use ruff to format the pyi file immediately
59
+ ```bash
60
+ maturin develop --generate-stubs | uv run ruff format ./python/dependency_cache/dependency_cache.pyi
61
+ ```
62
+ ### Quick Example
63
+
64
+ ```python
65
+ from dependency_cache import DependencyCacheBase, automagically_dependency_cached
66
+
67
+
68
+ class ExampleCalculation(DependencyCacheBase):
69
+ """ C
70
+ // \\
71
+ A B
72
+ """
73
+
74
+ def __init__(self, x, y):
75
+ super().__init__()
76
+ self.x = x
77
+ self.y = y
78
+
79
+ @automagically_dependency_cached()
80
+ def A(self):
81
+ print("calculating A")
82
+ return self.x
83
+
84
+ @automagically_dependency_cached()
85
+ def B(self):
86
+ print("calculating B")
87
+ return self.y
88
+
89
+ @automagically_dependency_cached()
90
+ def C(self):
91
+ print("calculating C")
92
+ return self.B() + self.A()
93
+
94
+
95
+ c = ExampleCalculation(3, 5)
96
+ print(c.C()) # calculates A, B, C -> 8
97
+ print(c.C()) # hits cache -> 8
98
+
99
+ c.update_cached_value("A", 0) # invalidates C (but not B)
100
+ print(c.C()) # recalculates C -> 5
101
+ ```
102
+
103
+ 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.
104
+
105
+ ```bash
106
+ uv run ./python/examples/example.py
107
+ ```
108
+
109
+ ### TODOs
110
+ This project is still a work in progress, with everything from API to underlying design subject to change on my whim.
111
+
112
+ Current TODO list (in no particular order):
113
+ - load and dump cache methods for base class
114
+ - add back in ast parsing
115
+ - move plot_dependency_graph to rust side instead of python
116
+ - add object thread safety for python 3.14+
117
+ - work out how best to handle nested objects
118
+
@@ -0,0 +1,99 @@
1
+ # Dependency Cache
2
+ ## :construction: Work In Progress :construction:
3
+
4
+ ### Description
5
+ A library for managing the caching of an object's methods with cache invalidation handled by a dependency graph.
6
+ Instead of recomputing expensive, deeply nested calculations on every call, Dependency Cache stores the result and only invalidates (and recalculates) it when one of its dependencies actually changes.
7
+ This project is written in rust, with [pyo3](https://github.com/PyO3/pyo3), and compiled using [maturin](https://github.com/PyO3/maturin).
8
+
9
+ ### API Overview
10
+
11
+ | Export | What it's for |
12
+ |---|---|
13
+ | `DependencyCacheBase` | Base class to inherit from. Gives your instance a cache and a dependency graph. |
14
+ | `dependency_cached(use_cache=True, dependencies=[...], track_runtime_dependencies=False)` | A footgun-enabled :gun: decorator for a method where you **explicitly declare** direct dependencies. |
15
+ | `automagically_dependency_cached(use_cache=True, dependencies=[...], track_runtime_dependencies=True)` | A decorator which **automagically infers** the direct dependencies with the option to override manually using `dependencies=`. |
16
+ | `plot_dependency_graph(obj, **kwargs)` | Visualizes an instance's dependency graph, for inspection/debugging. |
17
+
18
+ ### Setup
19
+ This project uses (and requires) [uv](https://github.com/astral-sh/uv) as a package manager and maturin to compile.
20
+
21
+ Steps:
22
+ - install python dependencies
23
+ ```bash
24
+ uv sync
25
+ ```
26
+ - generate local development file for testing (and update pyi file for accurate typechecking)
27
+ ```bash
28
+ maturin develop --generate-stubs
29
+ maturin develop -r --generate-stubs
30
+ ```
31
+ - run python tests
32
+ ```bash
33
+ uv run pytest
34
+ uv run pytest -vv
35
+ ```
36
+ - run rust tests
37
+ ```bash
38
+ cargo test
39
+ ```
40
+ - temporary fix: generate stubs currently produces a file that is incorrectly formatted, use ruff to format the pyi file immediately
41
+ ```bash
42
+ maturin develop --generate-stubs | uv run ruff format ./python/dependency_cache/dependency_cache.pyi
43
+ ```
44
+ ### Quick Example
45
+
46
+ ```python
47
+ from dependency_cache import DependencyCacheBase, automagically_dependency_cached
48
+
49
+
50
+ class ExampleCalculation(DependencyCacheBase):
51
+ """ C
52
+ // \\
53
+ A B
54
+ """
55
+
56
+ def __init__(self, x, y):
57
+ super().__init__()
58
+ self.x = x
59
+ self.y = y
60
+
61
+ @automagically_dependency_cached()
62
+ def A(self):
63
+ print("calculating A")
64
+ return self.x
65
+
66
+ @automagically_dependency_cached()
67
+ def B(self):
68
+ print("calculating B")
69
+ return self.y
70
+
71
+ @automagically_dependency_cached()
72
+ def C(self):
73
+ print("calculating C")
74
+ return self.B() + self.A()
75
+
76
+
77
+ c = ExampleCalculation(3, 5)
78
+ print(c.C()) # calculates A, B, C -> 8
79
+ print(c.C()) # hits cache -> 8
80
+
81
+ c.update_cached_value("A", 0) # invalidates C (but not B)
82
+ print(c.C()) # recalculates C -> 5
83
+ ```
84
+
85
+ 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.
86
+
87
+ ```bash
88
+ uv run ./python/examples/example.py
89
+ ```
90
+
91
+ ### TODOs
92
+ This project is still a work in progress, with everything from API to underlying design subject to change on my whim.
93
+
94
+ Current TODO list (in no particular order):
95
+ - load and dump cache methods for base class
96
+ - add back in ast parsing
97
+ - move plot_dependency_graph to rust side instead of python
98
+ - add object thread safety for python 3.14+
99
+ - work out how best to handle nested objects