Skip to content

Commit 3e1fbdc

Browse files
authored
Enable automatic cleanup for local store (#175)
1 parent ec0c6ca commit 3e1fbdc

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

obstore/python/obstore/store/__init__.pyi

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,17 @@ class LocalStore:
2626
store = LocalStore(prefix=Path("."))
2727
```
2828
"""
29-
def __init__(self, prefix: str | Path | None = None) -> None: ...
29+
def __init__(
30+
self, prefix: str | Path | None = None, *, automatic_cleanup: bool = False
31+
) -> None:
32+
"""Create a new LocalStore.
33+
34+
Args:
35+
prefix: Use the specified prefix applied to all paths. Defaults to `None`.
36+
37+
Keyword Args:
38+
automatic_cleanup: if `True`, enables automatic cleanup of empty directories when deleting files. Defaults to False.
39+
"""
3040
def __repr__(self) -> str: ...
3141
@classmethod
3242
def from_url(cls, url: str) -> LocalStore:

pyo3-object_store/src/local.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,17 @@ impl PyLocalStore {
2929
#[pymethods]
3030
impl PyLocalStore {
3131
#[new]
32-
#[pyo3(signature = (prefix = None))]
33-
fn py_new(prefix: Option<std::path::PathBuf>) -> PyObjectStoreResult<Self> {
32+
#[pyo3(signature = (prefix = None, *, automatic_cleanup=false))]
33+
fn py_new(
34+
prefix: Option<std::path::PathBuf>,
35+
automatic_cleanup: bool,
36+
) -> PyObjectStoreResult<Self> {
3437
let fs = if let Some(prefix) = prefix {
3538
LocalFileSystem::new_with_prefix(prefix)?
3639
} else {
3740
LocalFileSystem::new()
3841
};
42+
let fs = fs.with_automatic_cleanup(automatic_cleanup);
3943
Ok(Self(Arc::new(fs)))
4044
}
4145

0 commit comments

Comments
 (0)