dependency-cache 0.5.0__tar.gz → 0.5.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.
- {dependency_cache-0.5.0 → dependency_cache-0.5.2}/PKG-INFO +2 -2
- {dependency_cache-0.5.0 → dependency_cache-0.5.2}/README.md +1 -1
- {dependency_cache-0.5.0 → dependency_cache-0.5.2}/pyproject.toml +1 -1
- {dependency_cache-0.5.0 → dependency_cache-0.5.2}/src/decorator.rs +2 -2
- {dependency_cache-0.5.0 → dependency_cache-0.5.2}/src/dependency_cache_base.rs +102 -50
- {dependency_cache-0.5.0 → dependency_cache-0.5.2}/src/dependency_graph.rs +2 -0
- {dependency_cache-0.5.0 → dependency_cache-0.5.2}/src/metadata_hash_manager.rs +6 -6
- {dependency_cache-0.5.0 → dependency_cache-0.5.2}/src/py_introspection_utils.rs +2 -2
- {dependency_cache-0.5.0 → dependency_cache-0.5.2}/src/scenario.rs +5 -5
- {dependency_cache-0.5.0 → dependency_cache-0.5.2}/uv.lock +1 -1
- {dependency_cache-0.5.0 → dependency_cache-0.5.2}/.github/workflows/CI.yml +0 -0
- {dependency_cache-0.5.0 → dependency_cache-0.5.2}/.github/workflows/Test.yml +0 -0
- {dependency_cache-0.5.0 → dependency_cache-0.5.2}/.gitignore +0 -0
- {dependency_cache-0.5.0 → dependency_cache-0.5.2}/Cargo.lock +0 -0
- {dependency_cache-0.5.0 → dependency_cache-0.5.2}/Cargo.toml +0 -0
- {dependency_cache-0.5.0 → dependency_cache-0.5.2}/LICENSE +0 -0
- {dependency_cache-0.5.0 → dependency_cache-0.5.2}/python/dependency_cache/__init__.py +0 -0
- {dependency_cache-0.5.0 → dependency_cache-0.5.2}/python/dependency_cache/dependency_cache.pyi +0 -0
- {dependency_cache-0.5.0 → dependency_cache-0.5.2}/python/dependency_cache/plot_dependency_graph.py +0 -0
- {dependency_cache-0.5.0 → dependency_cache-0.5.2}/python/examples/automagic_dependency_example.py +0 -0
- {dependency_cache-0.5.0 → dependency_cache-0.5.2}/python/examples/custom_decorator_example.py +0 -0
- {dependency_cache-0.5.0 → dependency_cache-0.5.2}/python/examples/custom_scenario_example.py +0 -0
- {dependency_cache-0.5.0 → dependency_cache-0.5.2}/python/examples/example.py +0 -0
- {dependency_cache-0.5.0 → dependency_cache-0.5.2}/python/examples/inheritance_example.py +0 -0
- {dependency_cache-0.5.0 → dependency_cache-0.5.2}/python/examples/manual_dependency_example.py +0 -0
- {dependency_cache-0.5.0 → dependency_cache-0.5.2}/python/examples/runtime_dependencies_example.py +0 -0
- {dependency_cache-0.5.0 → dependency_cache-0.5.2}/python/examples/runtime_function_calls_example.py +0 -0
- {dependency_cache-0.5.0 → dependency_cache-0.5.2}/python/examples/serialisable_example.py +0 -0
- {dependency_cache-0.5.0 → dependency_cache-0.5.2}/python/examples/static_function_calls_example.py +0 -0
- {dependency_cache-0.5.0 → dependency_cache-0.5.2}/python/examples/use_cache_example.py +0 -0
- {dependency_cache-0.5.0 → dependency_cache-0.5.2}/python/test_python.py +0 -0
- {dependency_cache-0.5.0 → dependency_cache-0.5.2}/python/test_python_automagic.py +0 -0
- {dependency_cache-0.5.0 → dependency_cache-0.5.2}/src/decorator_factory.rs +0 -0
- {dependency_cache-0.5.0 → dependency_cache-0.5.2}/src/lib.rs +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dependency_cache
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.2
|
|
4
4
|
Classifier: Programming Language :: Rust
|
|
5
5
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
6
6
|
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
@@ -39,6 +39,7 @@ pip install dependency-cache
|
|
|
39
39
|
| `dependency_cached` | A footgun-enabled decorator for a method where you **explicitly declare** all direct dependencies. |
|
|
40
40
|
| `automagically_dependency_cached` | A decorator which **automagically infers** the direct dependencies. |
|
|
41
41
|
| `plot_dependency_graph` | Visualizes an instance's dependency graph, for inspection or debugging. |
|
|
42
|
+
| `custom_scenario` | A context manager to temporarily run a custom dependency scenario, restoring the original state on exit. |
|
|
42
43
|
|
|
43
44
|
All decorators accept optional parameters like use_cache, dependencies, track_runtime_dependencies, and serialisable. For exact signatures and types, see the
|
|
44
45
|
[generated stubs file](https://github.com/XtdWt/dependency_cache/blob/master/python/dependency_cache/dependency_cache.pyi).
|
|
@@ -120,7 +121,6 @@ uv run ./python/examples/example.py
|
|
|
120
121
|
This project is still a work in progress, with everything from API to underlying design subject to change on my whim.
|
|
121
122
|
|
|
122
123
|
Current TODO list (in no particular order):
|
|
123
|
-
- scenario analysis capability (add temporary cache to base)
|
|
124
124
|
- add global_variable to link objects together
|
|
125
125
|
- add validation to static dependencies, ensure methods are of decorator class (?)
|
|
126
126
|
- improve plot_dependency_graph (maybe to GUI?) with interactive nodes
|
|
@@ -21,6 +21,7 @@ pip install dependency-cache
|
|
|
21
21
|
| `dependency_cached` | A footgun-enabled decorator for a method where you **explicitly declare** all direct dependencies. |
|
|
22
22
|
| `automagically_dependency_cached` | A decorator which **automagically infers** the direct dependencies. |
|
|
23
23
|
| `plot_dependency_graph` | Visualizes an instance's dependency graph, for inspection or debugging. |
|
|
24
|
+
| `custom_scenario` | A context manager to temporarily run a custom dependency scenario, restoring the original state on exit. |
|
|
24
25
|
|
|
25
26
|
All decorators accept optional parameters like use_cache, dependencies, track_runtime_dependencies, and serialisable. For exact signatures and types, see the
|
|
26
27
|
[generated stubs file](https://github.com/XtdWt/dependency_cache/blob/master/python/dependency_cache/dependency_cache.pyi).
|
|
@@ -102,7 +103,6 @@ uv run ./python/examples/example.py
|
|
|
102
103
|
This project is still a work in progress, with everything from API to underlying design subject to change on my whim.
|
|
103
104
|
|
|
104
105
|
Current TODO list (in no particular order):
|
|
105
|
-
- scenario analysis capability (add temporary cache to base)
|
|
106
106
|
- add global_variable to link objects together
|
|
107
107
|
- add validation to static dependencies, ensure methods are of decorator class (?)
|
|
108
108
|
- improve plot_dependency_graph (maybe to GUI?) with interactive nodes
|
|
@@ -11,7 +11,7 @@ classifiers = [
|
|
|
11
11
|
"Programming Language :: Python :: Implementation :: PyPy",
|
|
12
12
|
]
|
|
13
13
|
keywords = ["caching", "dependency-graph", "invalidation"]
|
|
14
|
-
version = "0.5.
|
|
14
|
+
version = "0.5.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" }
|
|
@@ -23,12 +23,12 @@ impl DependencyCacheDecorator {
|
|
|
23
23
|
|
|
24
24
|
#[getter]
|
|
25
25
|
fn __name__(&self) -> &str {
|
|
26
|
-
&self.method_name
|
|
26
|
+
return &self.method_name;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
#[getter]
|
|
30
30
|
fn __qualname__(&self) -> &str {
|
|
31
|
-
&self.method_name
|
|
31
|
+
return &self.method_name;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
fn __get__(
|
|
@@ -5,7 +5,7 @@ use pyo3::exceptions::{PyKeyError, PyRuntimeError, PyValueError};
|
|
|
5
5
|
use rand::rng;
|
|
6
6
|
use rand::seq::SliceRandom;
|
|
7
7
|
|
|
8
|
-
use std::collections::
|
|
8
|
+
use std::collections::HashSet;
|
|
9
9
|
|
|
10
10
|
use crate::dependency_graph::{MethodDependencyGraph, ValidationState};
|
|
11
11
|
use crate::py_introspection_utils::{normalise_function_signature_and_hash, validate_self_only_method};
|
|
@@ -13,13 +13,28 @@ use crate::decorator::DependencyCacheDecorator;
|
|
|
13
13
|
use crate::metadata_hash_manager::{CacheKey, MetadataHashManager};
|
|
14
14
|
|
|
15
15
|
|
|
16
|
+
pub struct CacheLayer {
|
|
17
|
+
pub cache: Vec<Option<Py<PyAny>>>,
|
|
18
|
+
pub graph_snapshot: MethodDependencyGraph<CacheKey>, //TODO: maybe less expensive way to handling graph snapshot...
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
#[inline]
|
|
23
|
+
fn set_cache_value(cache: &mut Vec<Option<Py<PyAny>>>, key: usize, value: Py<PyAny>) {
|
|
24
|
+
if key >= cache.len() {
|
|
25
|
+
cache.resize_with(key + 1, || None);
|
|
26
|
+
}
|
|
27
|
+
cache[key] = Some(value);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
|
|
16
31
|
#[pyclass(subclass)]
|
|
17
32
|
pub struct DependencyCacheBase {
|
|
18
|
-
pub cache:
|
|
33
|
+
pub cache: Vec<Option<Py<PyAny>>>,
|
|
19
34
|
pub method_dependency_graph: MethodDependencyGraph<CacheKey>,
|
|
20
35
|
pub metadata_hash_manager: MetadataHashManager,
|
|
21
36
|
pub call_stack: Vec<(CacheKey, bool)>,
|
|
22
|
-
pub cache_stack: Vec<
|
|
37
|
+
pub cache_stack: Vec<CacheLayer>,
|
|
23
38
|
}
|
|
24
39
|
|
|
25
40
|
impl DependencyCacheBase {
|
|
@@ -28,10 +43,10 @@ impl DependencyCacheBase {
|
|
|
28
43
|
if !self.method_dependency_graph.is_valid(key) {
|
|
29
44
|
return ();
|
|
30
45
|
}
|
|
31
|
-
if let Some(
|
|
32
|
-
|
|
46
|
+
if let Some(layer) = self.cache_stack.last_mut() {
|
|
47
|
+
set_cache_value(&mut layer.cache, key, value);
|
|
33
48
|
} else {
|
|
34
|
-
self.cache
|
|
49
|
+
set_cache_value(&mut self.cache, key, value);
|
|
35
50
|
};
|
|
36
51
|
}
|
|
37
52
|
|
|
@@ -69,7 +84,7 @@ impl DependencyCacheBase {
|
|
|
69
84
|
}
|
|
70
85
|
|
|
71
86
|
pub fn current_call_stack_top(&self) -> Option<(CacheKey, bool)> {
|
|
72
|
-
self.call_stack.last().cloned()
|
|
87
|
+
return self.call_stack.last().cloned();
|
|
73
88
|
}
|
|
74
89
|
|
|
75
90
|
pub fn push_call_stack(&mut self, key: CacheKey, add_parent_dependencies: bool) {
|
|
@@ -92,10 +107,10 @@ impl DependencyCacheBase {
|
|
|
92
107
|
|
|
93
108
|
pub fn get_cached_value_by_key(&self, py: Python<'_>, key: CacheKey) -> Option<Py<PyAny>> {
|
|
94
109
|
if self.method_dependency_graph.is_valid(key) {
|
|
95
|
-
if let Some(temp_cache_value) = self.get_from_temporary_cache(py,
|
|
110
|
+
if let Some(temp_cache_value) = self.get_from_temporary_cache(py, key) {
|
|
96
111
|
return Some(temp_cache_value);
|
|
97
112
|
}
|
|
98
|
-
return self.cache.get(
|
|
113
|
+
return self.cache.get(key).and_then(|obj| obj.as_ref().map(|v| v.clone_ref(py)));
|
|
99
114
|
}
|
|
100
115
|
return None;
|
|
101
116
|
}
|
|
@@ -117,70 +132,107 @@ impl DependencyCacheBase {
|
|
|
117
132
|
}
|
|
118
133
|
|
|
119
134
|
pub fn push_cache_stack(&mut self) {
|
|
120
|
-
return self.cache_stack.push(
|
|
135
|
+
return self.cache_stack.push(CacheLayer {
|
|
136
|
+
cache: Vec::new(),
|
|
137
|
+
graph_snapshot: self.method_dependency_graph.clone(),
|
|
138
|
+
});
|
|
121
139
|
}
|
|
122
140
|
|
|
123
141
|
pub fn pop_cache_stack(&mut self) -> PyResult<()> {
|
|
124
|
-
let
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
142
|
+
let layer = self
|
|
143
|
+
.cache_stack
|
|
144
|
+
.pop()
|
|
145
|
+
.ok_or_else(|| PyRuntimeError::new_err("Attempted to remove non existant layer"))?;
|
|
146
|
+
|
|
147
|
+
self.method_dependency_graph = layer.graph_snapshot;
|
|
128
148
|
return Ok(());
|
|
129
149
|
}
|
|
130
150
|
|
|
131
|
-
pub fn get_from_temporary_cache(&self, py: Python<'_>, key:
|
|
151
|
+
pub fn get_from_temporary_cache(&self, py: Python<'_>, key: CacheKey) -> Option<Py<PyAny>> {
|
|
132
152
|
for layer in self.cache_stack.iter().rev() {
|
|
133
|
-
if let Some(v) = layer.get(key) {
|
|
153
|
+
if let Some(Some(v)) = layer.cache.get(key) {
|
|
134
154
|
return Some(v.clone_ref(py));
|
|
135
155
|
}
|
|
136
156
|
}
|
|
137
157
|
return None;
|
|
138
158
|
}
|
|
139
159
|
|
|
140
|
-
pub fn contains_cached_value(&self, key:
|
|
141
|
-
if !self.method_dependency_graph.is_valid(
|
|
160
|
+
pub fn contains_cached_value(&self, key: CacheKey) -> bool {
|
|
161
|
+
if !self.method_dependency_graph.is_valid(key) {
|
|
142
162
|
return false;
|
|
143
163
|
}
|
|
144
164
|
return self.cache_stack
|
|
145
165
|
.iter()
|
|
146
166
|
.rev()
|
|
147
|
-
.any(|layer| layer.
|
|
148
|
-
|| self.cache.
|
|
167
|
+
.any(|layer| layer.cache.get(key).is_some_and(|obj| obj.is_some()))
|
|
168
|
+
|| self.cache.get(key).is_some_and(|obj| obj.is_some());
|
|
149
169
|
}
|
|
150
170
|
|
|
151
|
-
pub fn remove_cached_value(&mut self, key:
|
|
171
|
+
pub fn remove_cached_value(&mut self, key: CacheKey) -> Option<Py<PyAny>> {
|
|
152
172
|
for layer in self.cache_stack.iter_mut().rev() {
|
|
153
|
-
if let Some(
|
|
154
|
-
|
|
173
|
+
if let Some(opt) = layer.cache.get_mut(key) {
|
|
174
|
+
if let Some(v) = opt.take() {
|
|
175
|
+
return Some(v);
|
|
176
|
+
}
|
|
155
177
|
}
|
|
156
178
|
}
|
|
157
|
-
self.cache.
|
|
179
|
+
if let Some(opt) = self.cache.get_mut(key) {
|
|
180
|
+
return opt.take();
|
|
181
|
+
}
|
|
182
|
+
return None;
|
|
158
183
|
}
|
|
159
184
|
|
|
160
|
-
pub fn effective_cache(&self) ->
|
|
161
|
-
let
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
185
|
+
pub fn effective_cache(&self) -> Vec<(CacheKey, &Py<PyAny>)> {
|
|
186
|
+
let max_len = self
|
|
187
|
+
.cache_stack
|
|
188
|
+
.iter()
|
|
189
|
+
.map(|l| l.cache.len())
|
|
190
|
+
.chain(std::iter::once(self.cache.len()))
|
|
191
|
+
.max()
|
|
192
|
+
.unwrap_or(0);
|
|
193
|
+
|
|
194
|
+
let mut result = Vec::new();
|
|
195
|
+
for i in 0..max_len {
|
|
196
|
+
let mut value: Option<&Py<PyAny>> =
|
|
197
|
+
self.cache.get(i).and_then(|opt| opt.as_ref());
|
|
198
|
+
|
|
199
|
+
for layer in &self.cache_stack {
|
|
200
|
+
if let Some(Some(v)) = layer.cache.get(i) {
|
|
201
|
+
value = Some(v);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if let Some(v) = value {
|
|
206
|
+
result.push((i, v));
|
|
165
207
|
}
|
|
166
208
|
}
|
|
167
|
-
return
|
|
209
|
+
return result;
|
|
168
210
|
}
|
|
169
211
|
|
|
170
212
|
pub fn clear_effective_cache(&mut self) -> () {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
213
|
+
let mut removed_keys: HashSet<CacheKey> = HashSet::new();
|
|
214
|
+
|
|
215
|
+
for layer in self.cache_stack.iter_mut() {
|
|
216
|
+
for (i, obj) in layer.cache.iter_mut().enumerate() {
|
|
217
|
+
if obj.is_some() {
|
|
218
|
+
*obj = None;
|
|
219
|
+
removed_keys.insert(i);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
for (i, obj) in self.cache.iter_mut().enumerate() {
|
|
224
|
+
if obj.is_some() {
|
|
225
|
+
*obj = None;
|
|
226
|
+
removed_keys.insert(i);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
if removed_keys.is_empty() {
|
|
231
|
+
self.method_dependency_graph.invalidate_all();
|
|
232
|
+
} else {
|
|
177
233
|
for key in removed_keys {
|
|
178
234
|
self.method_dependency_graph.temporarily_invalidate(key);
|
|
179
235
|
}
|
|
180
|
-
layer.clear();
|
|
181
|
-
} else {
|
|
182
|
-
self.method_dependency_graph.invalidate_all();
|
|
183
|
-
self.cache.clear();
|
|
184
236
|
}
|
|
185
237
|
}
|
|
186
238
|
}
|
|
@@ -191,7 +243,7 @@ impl DependencyCacheBase {
|
|
|
191
243
|
#[pyo3(signature = (*_args, **_kwargs))]
|
|
192
244
|
fn new(_args: &Bound<'_, PyTuple>, _kwargs: Option<&Bound<'_, PyDict>>) -> Self {
|
|
193
245
|
return Self {
|
|
194
|
-
cache:
|
|
246
|
+
cache: Vec::new(),
|
|
195
247
|
method_dependency_graph: MethodDependencyGraph::new(),
|
|
196
248
|
metadata_hash_manager: MetadataHashManager::new(),
|
|
197
249
|
call_stack: Vec::new(),
|
|
@@ -229,7 +281,7 @@ impl DependencyCacheBase {
|
|
|
229
281
|
kwargs: Option<Py<PyDict>>,
|
|
230
282
|
) -> PyResult<bool> {
|
|
231
283
|
let key = self.get_key(py, &method_name, &kwargs)?;
|
|
232
|
-
return Ok(self.contains_cached_value(
|
|
284
|
+
return Ok(self.contains_cached_value(key));
|
|
233
285
|
}
|
|
234
286
|
|
|
235
287
|
|
|
@@ -243,7 +295,7 @@ impl DependencyCacheBase {
|
|
|
243
295
|
) -> PyResult<()> {
|
|
244
296
|
let key = self.get_key(py, &method_name, &kwargs)?;
|
|
245
297
|
|
|
246
|
-
if !self.contains_cached_value(
|
|
298
|
+
if !self.contains_cached_value(key) {
|
|
247
299
|
return Err(PyKeyError::new_err(format!(
|
|
248
300
|
"Cannot update cached value for '{method_name}'"
|
|
249
301
|
)));
|
|
@@ -267,7 +319,7 @@ impl DependencyCacheBase {
|
|
|
267
319
|
) -> PyResult<()> {
|
|
268
320
|
let key = self.get_key(py, &method_name, &kwargs)?;
|
|
269
321
|
|
|
270
|
-
if self.remove_cached_value(
|
|
322
|
+
if self.remove_cached_value(key).is_none() {
|
|
271
323
|
return Err(PyKeyError::new_err(format!(
|
|
272
324
|
"Cannot clear cached value for '{method_name}'"
|
|
273
325
|
)));
|
|
@@ -298,7 +350,7 @@ impl DependencyCacheBase {
|
|
|
298
350
|
|
|
299
351
|
dict.set_item(key, value.clone_ref(py))?;
|
|
300
352
|
}
|
|
301
|
-
Ok(dict)
|
|
353
|
+
return Ok(dict);
|
|
302
354
|
}
|
|
303
355
|
|
|
304
356
|
#[getter]
|
|
@@ -342,7 +394,7 @@ impl DependencyCacheBase {
|
|
|
342
394
|
let list = PySet::new(py, parent_bounds)?;
|
|
343
395
|
dict.set_item(child_key, list)?;
|
|
344
396
|
}
|
|
345
|
-
Ok(dict)
|
|
397
|
+
return Ok(dict);
|
|
346
398
|
}
|
|
347
399
|
|
|
348
400
|
#[getter]
|
|
@@ -366,7 +418,7 @@ impl DependencyCacheBase {
|
|
|
366
418
|
|
|
367
419
|
dict.set_item(key, state)?;
|
|
368
420
|
}
|
|
369
|
-
Ok(dict)
|
|
421
|
+
return Ok(dict);
|
|
370
422
|
}
|
|
371
423
|
|
|
372
424
|
#[pyo3(signature = (order=None))]
|
|
@@ -416,7 +468,7 @@ impl DependencyCacheBase {
|
|
|
416
468
|
result.set_item(method_name, value)?;
|
|
417
469
|
}
|
|
418
470
|
|
|
419
|
-
Ok(result)
|
|
471
|
+
return Ok(result);
|
|
420
472
|
}
|
|
421
473
|
|
|
422
474
|
#[pyo3(signature = (data, order=None))]
|
|
@@ -467,7 +519,7 @@ impl DependencyCacheBase {
|
|
|
467
519
|
|
|
468
520
|
let mut base = slf.borrow_mut();
|
|
469
521
|
let key = base.create_key(py, name, &None)?;
|
|
470
|
-
base.cache.
|
|
522
|
+
set_cache_value(base.cache.as_mut(), key, loaded_value.unbind());
|
|
471
523
|
Ok(())
|
|
472
524
|
};
|
|
473
525
|
|
|
@@ -495,6 +547,6 @@ impl DependencyCacheBase {
|
|
|
495
547
|
load_method(&name)?;
|
|
496
548
|
}
|
|
497
549
|
|
|
498
|
-
Ok(())
|
|
550
|
+
return Ok(());
|
|
499
551
|
}
|
|
500
552
|
}
|
|
@@ -9,6 +9,8 @@ pub enum ValidationState {
|
|
|
9
9
|
PermanentlyInvalid,
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
|
|
13
|
+
#[derive(Clone)]
|
|
12
14
|
pub struct MethodDependencyGraph<T> {
|
|
13
15
|
validation_state: HashMap<T, ValidationState>,
|
|
14
16
|
dependency_graph: HashMap<T, HashSet<T>>, // maps child_name to set[parents_name], for ease of traversal
|
|
@@ -4,7 +4,7 @@ use pyo3::exceptions::PyKeyError;
|
|
|
4
4
|
|
|
5
5
|
use std::collections::HashMap;
|
|
6
6
|
|
|
7
|
-
pub type CacheKey =
|
|
7
|
+
pub type CacheKey = usize;
|
|
8
8
|
|
|
9
9
|
pub struct MetadataHashManager {
|
|
10
10
|
buckets: HashMap<isize, Vec<CacheKey>>,
|
|
@@ -32,7 +32,7 @@ impl MetadataHashManager {
|
|
|
32
32
|
return Ok(Some(key));
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
Ok(None)
|
|
35
|
+
return Ok(None);
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
pub fn get_cache_key(
|
|
@@ -41,8 +41,8 @@ impl MetadataHashManager {
|
|
|
41
41
|
hash: &isize,
|
|
42
42
|
sig: &Bound<'_, PyTuple>,
|
|
43
43
|
) -> PyResult<CacheKey> {
|
|
44
|
-
self.find_cache_key(py, hash, sig)?
|
|
45
|
-
.ok_or_else(|| PyKeyError::new_err("No cache key found for provided signature"))
|
|
44
|
+
return self.find_cache_key(py, hash, sig)?
|
|
45
|
+
.ok_or_else(|| PyKeyError::new_err("No cache key found for provided signature"));
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
pub fn create_cache_key(
|
|
@@ -58,10 +58,10 @@ impl MetadataHashManager {
|
|
|
58
58
|
self.next_id += 1;
|
|
59
59
|
self.buckets.entry(hash).or_default().push(key);
|
|
60
60
|
self.signatures.insert(key, sig);
|
|
61
|
-
Ok(key)
|
|
61
|
+
return Ok(key);
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
pub fn get_signature<'py>(&self, py: Python<'py>, id: &CacheKey) -> Option<Bound<'py, PyTuple>> {
|
|
65
|
-
self.signatures.get(id).map(|s| s.bind(py).clone())
|
|
65
|
+
return self.signatures.get(id).map(|s| s.bind(py).clone());
|
|
66
66
|
}
|
|
67
67
|
}
|
|
@@ -81,7 +81,7 @@ pub fn validate_self_only_method(py: Python<'_>, func: &Bound<'_, PyAny>) -> PyR
|
|
|
81
81
|
);
|
|
82
82
|
return Err(PyValueError::new_err(msg));
|
|
83
83
|
}
|
|
84
|
-
Ok(())
|
|
84
|
+
return Ok(());
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
|
|
@@ -165,7 +165,7 @@ fn visit(
|
|
|
165
165
|
visit(py, &child?, ast_module, dependencies, visited)?;
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
-
Ok(())
|
|
168
|
+
return Ok(());
|
|
169
169
|
}
|
|
170
170
|
|
|
171
171
|
|
|
@@ -20,13 +20,13 @@ impl Scenario {
|
|
|
20
20
|
.cast::<DependencyCacheBase>()
|
|
21
21
|
.map_err(|_| {
|
|
22
22
|
PyTypeError::new_err(
|
|
23
|
-
"
|
|
23
|
+
"custom_scenario() expects items to inherit from DependencyCacheBase",
|
|
24
24
|
)
|
|
25
25
|
})?;
|
|
26
26
|
base.borrow_mut().push_cache_stack();
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
-
Ok(slf.clone().into_any())
|
|
29
|
+
return Ok(slf.clone().into_any());
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
fn __exit__<'py>(
|
|
@@ -44,18 +44,18 @@ impl Scenario {
|
|
|
44
44
|
.cast::<DependencyCacheBase>()
|
|
45
45
|
.map_err(|_| {
|
|
46
46
|
PyTypeError::new_err(
|
|
47
|
-
"
|
|
47
|
+
"custom_scenario() expects items to inherit from DependencyCacheBase",
|
|
48
48
|
)
|
|
49
49
|
})?;
|
|
50
50
|
base.borrow_mut().pop_cache_stack()?;
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
-
Ok(false)
|
|
53
|
+
return Ok(false);
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
|
|
58
58
|
#[pyfunction]
|
|
59
59
|
pub fn custom_scenario(items: Vec<Py<PyAny>>) -> PyResult<Scenario> {
|
|
60
|
-
Ok(Scenario { items })
|
|
60
|
+
return Ok(Scenario { items });
|
|
61
61
|
}
|
|
@@ -329,7 +329,7 @@ wheels = [
|
|
|
329
329
|
|
|
330
330
|
[[package]]
|
|
331
331
|
name = "dependency-cache"
|
|
332
|
-
version = "0.5.
|
|
332
|
+
version = "0.5.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'" },
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{dependency_cache-0.5.0 → dependency_cache-0.5.2}/python/dependency_cache/dependency_cache.pyi
RENAMED
|
File without changes
|
{dependency_cache-0.5.0 → dependency_cache-0.5.2}/python/dependency_cache/plot_dependency_graph.py
RENAMED
|
File without changes
|
{dependency_cache-0.5.0 → dependency_cache-0.5.2}/python/examples/automagic_dependency_example.py
RENAMED
|
File without changes
|
{dependency_cache-0.5.0 → dependency_cache-0.5.2}/python/examples/custom_decorator_example.py
RENAMED
|
File without changes
|
{dependency_cache-0.5.0 → dependency_cache-0.5.2}/python/examples/custom_scenario_example.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{dependency_cache-0.5.0 → dependency_cache-0.5.2}/python/examples/manual_dependency_example.py
RENAMED
|
File without changes
|
{dependency_cache-0.5.0 → dependency_cache-0.5.2}/python/examples/runtime_dependencies_example.py
RENAMED
|
File without changes
|
{dependency_cache-0.5.0 → dependency_cache-0.5.2}/python/examples/runtime_function_calls_example.py
RENAMED
|
File without changes
|
|
File without changes
|
{dependency_cache-0.5.0 → dependency_cache-0.5.2}/python/examples/static_function_calls_example.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|