dependency_cache 0.2.3__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 (29) hide show
  1. dependency_cache-0.2.3/.github/workflows/CI.yml +208 -0
  2. dependency_cache-0.2.3/.github/workflows/Test.yml +44 -0
  3. dependency_cache-0.2.3/.gitignore +76 -0
  4. dependency_cache-0.2.3/Cargo.lock +194 -0
  5. dependency_cache-0.2.3/Cargo.toml +30 -0
  6. dependency_cache-0.2.3/LICENSE +21 -0
  7. dependency_cache-0.2.3/PKG-INFO +126 -0
  8. dependency_cache-0.2.3/README.md +107 -0
  9. dependency_cache-0.2.3/pyproject.toml +35 -0
  10. dependency_cache-0.2.3/python/dependency_cache/__init__.py +13 -0
  11. dependency_cache-0.2.3/python/dependency_cache/dependency_cache.pyi +39 -0
  12. dependency_cache-0.2.3/python/dependency_cache/plot_dependency_graph.py +43 -0
  13. dependency_cache-0.2.3/python/examples/automagic_dependency_example.py +57 -0
  14. dependency_cache-0.2.3/python/examples/example.py +43 -0
  15. dependency_cache-0.2.3/python/examples/inheritance_example.py +44 -0
  16. dependency_cache-0.2.3/python/examples/manual_dependency_example.py +55 -0
  17. dependency_cache-0.2.3/python/examples/runtime_dependencies_example.py +60 -0
  18. dependency_cache-0.2.3/python/examples/runtime_function_calls_example.py +34 -0
  19. dependency_cache-0.2.3/python/examples/static_function_calls_example.py +37 -0
  20. dependency_cache-0.2.3/python/examples/use_cache_example.py +30 -0
  21. dependency_cache-0.2.3/python/test_python.py +347 -0
  22. dependency_cache-0.2.3/python/test_python_automagic.py +310 -0
  23. dependency_cache-0.2.3/src/decorator.rs +101 -0
  24. dependency_cache-0.2.3/src/decorator_factory.rs +145 -0
  25. dependency_cache-0.2.3/src/dependency_cache_base.rs +360 -0
  26. dependency_cache-0.2.3/src/dependency_graph.rs +389 -0
  27. dependency_cache-0.2.3/src/lib.rs +24 -0
  28. dependency_cache-0.2.3/src/py_introspection_utils.rs +204 -0
  29. dependency_cache-0.2.3/uv.lock +2058 -0
@@ -0,0 +1,208 @@
1
+ # This file is autogenerated by maturin v1.14.1
2
+ # To update, run
3
+ #
4
+ # maturin generate-ci github -o .github\workflows\CI.yml
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@v6
34
+ - uses: actions/setup-python@v6
35
+ with:
36
+ python-version: "3.8"
37
+ - name: Build wheels
38
+ uses: PyO3/maturin-action@v1
39
+ with:
40
+ target: ${{ matrix.platform.target }}
41
+ args: --release --out dist
42
+ sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
43
+ manylinux: auto
44
+ - name: Build free-threaded wheels
45
+ uses: PyO3/maturin-action@v1
46
+ with:
47
+ target: ${{ matrix.platform.target }}
48
+ args: --release --out dist -i python3.14t
49
+ sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
50
+ manylinux: auto
51
+ - name: Upload wheels
52
+ uses: actions/upload-artifact@v6
53
+ with:
54
+ name: wheels-linux-${{ matrix.platform.target }}
55
+ path: dist
56
+
57
+ musllinux:
58
+ runs-on: ${{ matrix.platform.runner }}
59
+ strategy:
60
+ matrix:
61
+ platform:
62
+ - runner: ubuntu-22.04
63
+ target: x86_64
64
+ - runner: ubuntu-22.04
65
+ target: x86
66
+ - runner: ubuntu-22.04
67
+ target: aarch64
68
+ - runner: ubuntu-22.04
69
+ target: armv7
70
+ steps:
71
+ - uses: actions/checkout@v6
72
+ - uses: actions/setup-python@v6
73
+ with:
74
+ python-version: "3.8"
75
+ - name: Build wheels
76
+ uses: PyO3/maturin-action@v1
77
+ with:
78
+ target: ${{ matrix.platform.target }}
79
+ args: --release --out dist
80
+ sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
81
+ manylinux: musllinux_1_2
82
+ - name: Build free-threaded wheels
83
+ uses: PyO3/maturin-action@v1
84
+ with:
85
+ target: ${{ matrix.platform.target }}
86
+ args: --release --out dist -i python3.14t
87
+ sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
88
+ manylinux: musllinux_1_2
89
+ - name: Upload wheels
90
+ uses: actions/upload-artifact@v6
91
+ with:
92
+ name: wheels-musllinux-${{ matrix.platform.target }}
93
+ path: dist
94
+
95
+ windows:
96
+ runs-on: ${{ matrix.platform.runner }}
97
+ strategy:
98
+ matrix:
99
+ platform:
100
+ - runner: windows-latest
101
+ target: x64
102
+ python_arch: x64
103
+ - runner: windows-latest
104
+ target: x86
105
+ python_arch: x86
106
+ - runner: windows-11-arm
107
+ target: aarch64
108
+ python_arch: arm64
109
+ steps:
110
+ - uses: actions/checkout@v6
111
+ - uses: actions/setup-python@v6
112
+ with:
113
+ python-version: "3.13"
114
+ architecture: ${{ matrix.platform.python_arch }}
115
+ - name: Build wheels
116
+ uses: PyO3/maturin-action@v1
117
+ with:
118
+ target: ${{ matrix.platform.target }}
119
+ args: --release --out dist
120
+ sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
121
+ - uses: actions/setup-python@v6
122
+ with:
123
+ python-version: "3.14t"
124
+ architecture: ${{ matrix.platform.python_arch }}
125
+ - name: Build free-threaded wheels
126
+ uses: PyO3/maturin-action@v1
127
+ with:
128
+ target: ${{ matrix.platform.target }}
129
+ args: --release --out dist -i python3.14t
130
+ sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
131
+ - name: Upload wheels
132
+ uses: actions/upload-artifact@v6
133
+ with:
134
+ name: wheels-windows-${{ matrix.platform.target }}
135
+ path: dist
136
+
137
+ macos:
138
+ runs-on: ${{ matrix.platform.runner }}
139
+ strategy:
140
+ matrix:
141
+ platform:
142
+ - runner: macos-15-intel
143
+ target: x86_64
144
+ - runner: macos-latest
145
+ target: aarch64
146
+ steps:
147
+ - uses: actions/checkout@v6
148
+ - uses: actions/setup-python@v6
149
+ with:
150
+ python-version: "3.8"
151
+ - name: Build wheels
152
+ uses: PyO3/maturin-action@v1
153
+ with:
154
+ target: ${{ matrix.platform.target }}
155
+ args: --release --out dist
156
+ sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
157
+ - uses: actions/setup-python@v6
158
+ with:
159
+ python-version: "3.14t"
160
+ - name: Build free-threaded wheels
161
+ uses: PyO3/maturin-action@v1
162
+ with:
163
+ target: ${{ matrix.platform.target }}
164
+ args: --release --out dist -i python3.14t
165
+ sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
166
+ - name: Upload wheels
167
+ uses: actions/upload-artifact@v6
168
+ with:
169
+ name: wheels-macos-${{ matrix.platform.target }}
170
+ path: dist
171
+
172
+ sdist:
173
+ runs-on: ubuntu-latest
174
+ steps:
175
+ - uses: actions/checkout@v6
176
+ - name: Build sdist
177
+ uses: PyO3/maturin-action@v1
178
+ with:
179
+ command: sdist
180
+ args: --out dist
181
+ - name: Upload sdist
182
+ uses: actions/upload-artifact@v6
183
+ with:
184
+ name: wheels-sdist
185
+ path: dist
186
+
187
+ release:
188
+ name: Release
189
+ runs-on: ubuntu-latest
190
+ if: ${{ startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch' }}
191
+ needs: [linux, musllinux, windows, macos, sdist]
192
+ permissions:
193
+ # Use to sign the release artifacts
194
+ id-token: write
195
+ # Used to upload release artifacts
196
+ contents: write
197
+ # Used to generate artifact attestation
198
+ attestations: write
199
+ steps:
200
+ - uses: actions/download-artifact@v7
201
+ - name: Generate artifact attestation
202
+ uses: actions/attest@v4
203
+ with:
204
+ subject-path: 'wheels-*/*'
205
+ - name: Install uv
206
+ uses: astral-sh/setup-uv@v7
207
+ - name: Publish to PyPI
208
+ run: uv publish 'wheels-*/*'
@@ -0,0 +1,44 @@
1
+ name: Test
2
+
3
+ on:
4
+ push:
5
+ branches: [ "master" ]
6
+ pull_request:
7
+ branches: [ "master" ]
8
+ types: [ opened, synchronize, reopened, ready_for_review ]
9
+
10
+ env:
11
+ CARGO_TERM_COLOR: always
12
+
13
+ jobs:
14
+ build:
15
+ runs-on: ubuntu-latest
16
+ if: github.event_name != 'pull_request' || github.event.pull_request.draft == false
17
+
18
+ steps:
19
+ - uses: actions/checkout@v4
20
+
21
+ - name: Set up Python
22
+ uses: actions/setup-python@v5
23
+ with:
24
+ python-version: "3.12"
25
+
26
+ - name: Testing Rust
27
+ run: cargo test --verbose
28
+
29
+ - name: Build and Testing Python
30
+ run: |
31
+ python -m venv venv
32
+ source venv/bin/activate
33
+ pip install --upgrade pip maturin
34
+ pip install --upgrade pip pytest
35
+ maturin develop --release
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
@@ -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,194 @@
1
+ # This file is automatically @generated by Cargo.
2
+ # It is not intended for manual editing.
3
+ version = 4
4
+
5
+ [[package]]
6
+ name = "cfg-if"
7
+ version = "1.0.4"
8
+ source = "registry+https://github.com/rust-lang/crates.io-index"
9
+ checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
10
+
11
+ [[package]]
12
+ name = "chacha20"
13
+ version = "0.10.2"
14
+ source = "registry+https://github.com/rust-lang/crates.io-index"
15
+ checksum = "65c35e4b699c7e15ccbe7ee35c005e4fc0a278d22238a2857e6ce2dadeda1b06"
16
+ dependencies = [
17
+ "cfg-if",
18
+ "cpufeatures",
19
+ "rand_core",
20
+ ]
21
+
22
+ [[package]]
23
+ name = "cpufeatures"
24
+ version = "0.3.1"
25
+ source = "registry+https://github.com/rust-lang/crates.io-index"
26
+ checksum = "5ca28b0ae3115b884660db4118d803791fd6756b6e88f39c0f3f7859060d7566"
27
+ dependencies = [
28
+ "libc",
29
+ ]
30
+
31
+ [[package]]
32
+ name = "dependency_cache"
33
+ version = "0.1.0"
34
+ dependencies = [
35
+ "pyo3",
36
+ "rand",
37
+ ]
38
+
39
+ [[package]]
40
+ name = "getrandom"
41
+ version = "0.4.3"
42
+ source = "registry+https://github.com/rust-lang/crates.io-index"
43
+ checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099"
44
+ dependencies = [
45
+ "cfg-if",
46
+ "libc",
47
+ "r-efi",
48
+ "rand_core",
49
+ ]
50
+
51
+ [[package]]
52
+ name = "heck"
53
+ version = "0.5.0"
54
+ source = "registry+https://github.com/rust-lang/crates.io-index"
55
+ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
56
+
57
+ [[package]]
58
+ name = "libc"
59
+ version = "0.2.187"
60
+ source = "registry+https://github.com/rust-lang/crates.io-index"
61
+ checksum = "a7743783ea728ef5c31194c6590797eed286449b4a4e87d626d8a51f0a94e732"
62
+
63
+ [[package]]
64
+ name = "once_cell"
65
+ version = "1.21.4"
66
+ source = "registry+https://github.com/rust-lang/crates.io-index"
67
+ checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
68
+
69
+ [[package]]
70
+ name = "portable-atomic"
71
+ version = "1.14.0"
72
+ source = "registry+https://github.com/rust-lang/crates.io-index"
73
+ checksum = "3d20d5497ef88037a52ff98267d066e7f11fcc5e99bbfbd58a42336193aacec3"
74
+
75
+ [[package]]
76
+ name = "proc-macro2"
77
+ version = "1.0.107"
78
+ source = "registry+https://github.com/rust-lang/crates.io-index"
79
+ checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
80
+ dependencies = [
81
+ "unicode-ident",
82
+ ]
83
+
84
+ [[package]]
85
+ name = "pyo3"
86
+ version = "0.29.2"
87
+ source = "registry+https://github.com/rust-lang/crates.io-index"
88
+ checksum = "4688ddedf473e32662b9b067670129a8afb8c18e351482c70d62ba4a88171e8b"
89
+ dependencies = [
90
+ "libc",
91
+ "once_cell",
92
+ "portable-atomic",
93
+ "pyo3-build-config",
94
+ "pyo3-ffi",
95
+ "pyo3-macros",
96
+ ]
97
+
98
+ [[package]]
99
+ name = "pyo3-build-config"
100
+ version = "0.29.2"
101
+ source = "registry+https://github.com/rust-lang/crates.io-index"
102
+ checksum = "f41027e41b4bd03f6e60f9f417fe24a6341a6bb744edd62b6f709f2a52ea30e9"
103
+ dependencies = [
104
+ "target-lexicon",
105
+ ]
106
+
107
+ [[package]]
108
+ name = "pyo3-ffi"
109
+ version = "0.29.2"
110
+ source = "registry+https://github.com/rust-lang/crates.io-index"
111
+ checksum = "e591a95526fead067432c3b3a33fc74770b87b1e04e73671090d9c2055a2b327"
112
+ dependencies = [
113
+ "libc",
114
+ "pyo3-build-config",
115
+ ]
116
+
117
+ [[package]]
118
+ name = "pyo3-macros"
119
+ version = "0.29.2"
120
+ source = "registry+https://github.com/rust-lang/crates.io-index"
121
+ checksum = "73225868fc1cd84eef2c3c230ddb91273bf1de46aeb8a4248da76d32a0924a1c"
122
+ dependencies = [
123
+ "proc-macro2",
124
+ "pyo3-macros-backend",
125
+ "quote",
126
+ "syn",
127
+ ]
128
+
129
+ [[package]]
130
+ name = "pyo3-macros-backend"
131
+ version = "0.29.2"
132
+ source = "registry+https://github.com/rust-lang/crates.io-index"
133
+ checksum = "571575aa3749fa6216757dd47d2a3e7ef360f329a40f0666a9fbd14889024952"
134
+ dependencies = [
135
+ "heck",
136
+ "proc-macro2",
137
+ "quote",
138
+ "syn",
139
+ ]
140
+
141
+ [[package]]
142
+ name = "quote"
143
+ version = "1.0.47"
144
+ source = "registry+https://github.com/rust-lang/crates.io-index"
145
+ checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
146
+ dependencies = [
147
+ "proc-macro2",
148
+ ]
149
+
150
+ [[package]]
151
+ name = "r-efi"
152
+ version = "6.0.0"
153
+ source = "registry+https://github.com/rust-lang/crates.io-index"
154
+ checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf"
155
+
156
+ [[package]]
157
+ name = "rand"
158
+ version = "0.10.2"
159
+ source = "registry+https://github.com/rust-lang/crates.io-index"
160
+ checksum = "c7f5fa3a058cd35567ef9bfa5e75732bee0f9e4c55fa90477bef2dfcdbc4be80"
161
+ dependencies = [
162
+ "chacha20",
163
+ "getrandom",
164
+ "rand_core",
165
+ ]
166
+
167
+ [[package]]
168
+ name = "rand_core"
169
+ version = "0.10.1"
170
+ source = "registry+https://github.com/rust-lang/crates.io-index"
171
+ checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69"
172
+
173
+ [[package]]
174
+ name = "syn"
175
+ version = "2.0.119"
176
+ source = "registry+https://github.com/rust-lang/crates.io-index"
177
+ checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297"
178
+ dependencies = [
179
+ "proc-macro2",
180
+ "quote",
181
+ "unicode-ident",
182
+ ]
183
+
184
+ [[package]]
185
+ name = "target-lexicon"
186
+ version = "0.13.5"
187
+ source = "registry+https://github.com/rust-lang/crates.io-index"
188
+ checksum = "adb6935a6f5c20170eeceb1a3835a49e12e19d792f6dd344ccc76a985ca5a6ca"
189
+
190
+ [[package]]
191
+ name = "unicode-ident"
192
+ version = "1.0.24"
193
+ source = "registry+https://github.com/rust-lang/crates.io-index"
194
+ checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
@@ -0,0 +1,30 @@
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]
13
+ rand = "0.10.2"
14
+
15
+ [dependencies.pyo3]
16
+ version = "0.29.*"
17
+ features = [
18
+ "abi3-py38",
19
+ "extension-module",
20
+ "experimental-inspect",
21
+ ]
22
+
23
+ [profile.release]
24
+ lto = "fat"
25
+ codegen-units = 1
26
+ opt-level = 3
27
+
28
+ [lints.clippy]
29
+ needless_return = "allow"
30
+ 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,126 @@
1
+ Metadata-Version: 2.4
2
+ Name: dependency_cache
3
+ Version: 0.2.3
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 library for Python object methods that utilises a dependency graph to track relationships and control invalidation, enabling efficient recomputation
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
+ ## 🚧 Work In Progress 🚧
21
+
22
+ ### Description
23
+ Dependency Cache is a caching layer for object methods, with invalidation driven by a dependency graph.
24
+ Rather than re-running expensive, deeply nested calculations on every call, it stores each method's result and only recomputes (and marks downstream methods for recalculation) when one of its declared dependencies actually changes.
25
+ Under the hood, this project is written in Rust using [pyo3](https://github.com/PyO3/pyo3) and built with [maturin](https://github.com/PyO3/maturin).
26
+ ### Installation
27
+
28
+ Install the latest stable version from [PyPI](https://pypi.org/project/dependency-cache/):
29
+
30
+ ```bash
31
+ pip install dependency-cache
32
+ ```
33
+
34
+ ### API Overview
35
+
36
+ | Export | What it's for |
37
+ |---|---|
38
+ | `DependencyCacheBase` | Base class to inherit from. Gives your instance a cache and a dependency graph. |
39
+ | `dependency_cached(use_cache=True, dependencies=[...], track_runtime_dependencies=False, serialisable=False)` | A footgun-enabled decorator for a method where you **explicitly declare** all direct dependencies. |
40
+ | `automagically_dependency_cached(use_cache=True, dependencies=[...], track_runtime_dependencies=True, serialisable=False)` | A decorator which **automagically infers** the direct dependencies. Optionally override the defaults and inference using the `dependencies` parameter. |
41
+ | `plot_dependency_graph(obj, **kwargs)` | Visualizes an instance's dependency graph, for inspection/debugging. |
42
+
43
+ ### Setup
44
+ This project uses (and requires) [uv](https://github.com/astral-sh/uv) as a package manager and maturin to compile.
45
+
46
+ To set up a local dev environment:
47
+
48
+ - install python dependencies
49
+ ```bash
50
+ uv sync
51
+ ```
52
+ - generate local development file for testing (and update pyi file for accurate typechecking)
53
+ ```bash
54
+ maturin develop --generate-stubs
55
+ maturin develop -r --generate-stubs
56
+ ```
57
+ - run python tests
58
+ ```bash
59
+ uv run pytest
60
+ uv run pytest -vv
61
+ ```
62
+ - run rust tests
63
+ ```bash
64
+ cargo test
65
+ ```
66
+ - temporary fix: generate stubs currently produces a file that is incorrectly formatted, use ruff to format the pyi file immediately
67
+ ```bash
68
+ maturin develop --generate-stubs | uv run ruff format ./python/dependency_cache/dependency_cache.pyi
69
+ ```
70
+ ### Quick Example
71
+
72
+ ```python
73
+ from dependency_cache import DependencyCacheBase, automagically_dependency_cached
74
+
75
+
76
+ class ExampleCalculation(DependencyCacheBase):
77
+ """ C
78
+ // \\
79
+ A B
80
+ """
81
+
82
+ def __init__(self, x, y):
83
+ super().__init__()
84
+ self.x = x
85
+ self.y = y
86
+
87
+ @automagically_dependency_cached()
88
+ def A(self):
89
+ print("calculating A")
90
+ return self.x
91
+
92
+ @automagically_dependency_cached()
93
+ def B(self):
94
+ print("calculating B")
95
+ return self.y
96
+
97
+ @automagically_dependency_cached()
98
+ def C(self):
99
+ print("calculating C")
100
+ return self.B() + self.A()
101
+
102
+
103
+ c = ExampleCalculation(3, 5)
104
+ print(c.C()) # calculates A, B, C -> 8
105
+ print(c.C()) # hits cache -> 8
106
+
107
+ c.update_cached_value("A", 0) # invalidates C (but not B)
108
+ print(c.C()) # recalculates C -> 5
109
+ ```
110
+
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
+
113
+ ```bash
114
+ uv run ./python/examples/example.py
115
+ ```
116
+
117
+ ### TODOs
118
+ This project is still a work in progress, with everything from API to underlying design subject to change on my whim.
119
+
120
+ Current TODO list (in no particular order):
121
+ - scenario analysis capability (add temporary cache to base)
122
+ - add validation to static dependencies, ensure methods are of decorator class
123
+ - improve plot_dependency_graph (maybe to GUI?) with moveable nodes
124
+ - add object thread safety for python 3.14+
125
+ - work out how best to handle nested objects
126
+