dependency-cache 0.4.1__tar.gz → 0.4.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.4.1 → dependency_cache-0.4.2}/PKG-INFO +1 -1
  2. {dependency_cache-0.4.1 → dependency_cache-0.4.2}/pyproject.toml +1 -1
  3. {dependency_cache-0.4.1 → dependency_cache-0.4.2}/python/dependency_cache/dependency_cache.pyi +4 -2
  4. {dependency_cache-0.4.1 → dependency_cache-0.4.2}/python/test_python.py +28 -0
  5. {dependency_cache-0.4.1 → dependency_cache-0.4.2}/src/decorator.rs +1 -0
  6. {dependency_cache-0.4.1 → dependency_cache-0.4.2}/src/dependency_cache_base.rs +12 -3
  7. {dependency_cache-0.4.1 → dependency_cache-0.4.2}/uv.lock +1 -1
  8. {dependency_cache-0.4.1 → dependency_cache-0.4.2}/.github/workflows/CI.yml +0 -0
  9. {dependency_cache-0.4.1 → dependency_cache-0.4.2}/.github/workflows/Test.yml +0 -0
  10. {dependency_cache-0.4.1 → dependency_cache-0.4.2}/.gitignore +0 -0
  11. {dependency_cache-0.4.1 → dependency_cache-0.4.2}/Cargo.lock +0 -0
  12. {dependency_cache-0.4.1 → dependency_cache-0.4.2}/Cargo.toml +0 -0
  13. {dependency_cache-0.4.1 → dependency_cache-0.4.2}/LICENSE +0 -0
  14. {dependency_cache-0.4.1 → dependency_cache-0.4.2}/README.md +0 -0
  15. {dependency_cache-0.4.1 → dependency_cache-0.4.2}/python/dependency_cache/__init__.py +0 -0
  16. {dependency_cache-0.4.1 → dependency_cache-0.4.2}/python/dependency_cache/plot_dependency_graph.py +0 -0
  17. {dependency_cache-0.4.1 → dependency_cache-0.4.2}/python/examples/automagic_dependency_example.py +0 -0
  18. {dependency_cache-0.4.1 → dependency_cache-0.4.2}/python/examples/example.py +0 -0
  19. {dependency_cache-0.4.1 → dependency_cache-0.4.2}/python/examples/inheritance_example.py +0 -0
  20. {dependency_cache-0.4.1 → dependency_cache-0.4.2}/python/examples/manual_dependency_example.py +0 -0
  21. {dependency_cache-0.4.1 → dependency_cache-0.4.2}/python/examples/runtime_dependencies_example.py +0 -0
  22. {dependency_cache-0.4.1 → dependency_cache-0.4.2}/python/examples/runtime_function_calls_example.py +0 -0
  23. {dependency_cache-0.4.1 → dependency_cache-0.4.2}/python/examples/static_function_calls_example.py +0 -0
  24. {dependency_cache-0.4.1 → dependency_cache-0.4.2}/python/examples/use_cache_example.py +0 -0
  25. {dependency_cache-0.4.1 → dependency_cache-0.4.2}/python/test_python_automagic.py +0 -0
  26. {dependency_cache-0.4.1 → dependency_cache-0.4.2}/src/decorator_factory.rs +0 -0
  27. {dependency_cache-0.4.1 → dependency_cache-0.4.2}/src/dependency_graph.rs +0 -0
  28. {dependency_cache-0.4.1 → dependency_cache-0.4.2}/src/lib.rs +0 -0
  29. {dependency_cache-0.4.1 → dependency_cache-0.4.2}/src/metadata_hash_manager.rs +0 -0
  30. {dependency_cache-0.4.1 → dependency_cache-0.4.2}/src/py_introspection_utils.rs +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dependency_cache
3
- Version: 0.4.1
3
+ Version: 0.4.2
4
4
  Classifier: Programming Language :: Rust
5
5
  Classifier: Programming Language :: Python :: Implementation :: CPython
6
6
  Classifier: Programming Language :: Python :: Implementation :: PyPy
@@ -11,7 +11,7 @@ classifiers = [
11
11
  "Programming Language :: Python :: Implementation :: PyPy",
12
12
  ]
13
13
  keywords = ["caching", "dependency-graph", "invalidation"]
14
- version = "0.4.1"
14
+ version = "0.4.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" }
@@ -10,8 +10,10 @@ class DependencyCacheBase:
10
10
  @property
11
11
  def dependency_graph(self, /) -> dict: ...
12
12
  def dump_cache(self, /, order: Sequence[str] | None = None) -> dict: ...
13
- def get_cached_value(self, /, method_name: str, **kwargs) -> Any | None: ...
14
- def is_cached(self, /, method_name: str, kwargs: dict | None) -> bool: ...
13
+ def get_cached_value(
14
+ self, /, method_name: str, strict: bool = True, **kwargs
15
+ ) -> Any | None: ...
16
+ def is_cached(self, /, method_name: str, **kwargs) -> bool: ...
15
17
  def load_cache(self, /, data: dict, order: Sequence[str] | None = None) -> None: ...
16
18
  def update_cached_value(
17
19
  self, /, method_name: str, value: Any, **kwargs
@@ -139,6 +139,12 @@ class SerialisableObj(DependencyCacheBase):
139
139
  return None
140
140
 
141
141
 
142
+ class NonesObj(DependencyCacheBase):
143
+ @dependency_cached()
144
+ def A(self):
145
+ return None
146
+
147
+
142
148
  def test_raises_typeerror():
143
149
  with pytest.raises(TypeError):
144
150
  c = IncorrectInheritance()
@@ -345,3 +351,25 @@ def test_serialising_data(data, result):
345
351
  assert obj.C() is not None
346
352
 
347
353
  assert obj.C() == result
354
+
355
+
356
+ def test_strict_get_raises():
357
+ obj = NonesObj()
358
+
359
+ with pytest.raises(KeyError):
360
+ obj.get_cached_value("A")
361
+
362
+ assert obj.A() is None
363
+
364
+ assert obj.is_cached("A") is True
365
+
366
+ assert obj.get_cached_value("A") is None
367
+
368
+ obj.clear_cached_value("A")
369
+
370
+ assert obj.is_cached("A") is False
371
+
372
+ with pytest.raises(KeyError):
373
+ obj.get_cached_value("A")
374
+
375
+ assert obj.get_cached_value("A", strict=False) is None
@@ -64,6 +64,7 @@ impl DependencyCacheDecorator {
64
64
  let func = self.func.bind(py);
65
65
  let (hash, metadata) = normalise_function_signature_and_hash(py, &self.method_name, Some(func), args, kwargs)?;
66
66
 
67
+ // objects cannot pass themselves as an argument as the cache will trigger already borrowed error
67
68
  let key = base.try_borrow_mut()?.metadata_hash_manager.create_cache_key(py, hash, metadata.unbind())?;
68
69
 
69
70
  // 1. add/check child dependencies
@@ -122,16 +122,25 @@ impl DependencyCacheBase {
122
122
  };
123
123
  }
124
124
 
125
- #[pyo3(signature = (method_name, **kwargs))]
126
- pub fn get_cached_value(&mut self, py: Python<'_>, method_name: String, kwargs: Option<Py<PyDict>>) -> PyResult<Option<Py<PyAny>>> {
125
+ #[pyo3(signature = (method_name, strict=true, **kwargs))]
126
+ pub fn get_cached_value(&mut self, py: Python<'_>, method_name: String, strict: bool, kwargs: Option<Py<PyDict>>) -> PyResult<Option<Py<PyAny>>> {
127
127
  let key = self.get_key(py, &method_name, &kwargs)?;
128
128
 
129
129
  if self.method_dependency_graph.is_valid(key) {
130
- return Ok(self.cache.get(&key).map(|obj| obj.clone_ref(py)));
130
+ if let Some(obj) = self.cache.get(&key) {
131
+ return Ok(Some(obj.clone_ref(py)));
132
+ }
131
133
  }
134
+
135
+ if strict {
136
+ return Err(PyKeyError::new_err(format!(
137
+ "Cannot get cached value for '{method_name}'"
138
+ )));
139
+ };
132
140
  return Ok(None);
133
141
  }
134
142
 
143
+ #[pyo3(signature = (method_name, **kwargs))]
135
144
  pub fn is_cached(
136
145
  &mut self,
137
146
  py: Python<'_>,
@@ -329,7 +329,7 @@ wheels = [
329
329
 
330
330
  [[package]]
331
331
  name = "dependency-cache"
332
- version = "0.4.1"
332
+ version = "0.4.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'" },