Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion obstore/python/obstore/store/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ class LocalStore:
```
"""
def __init__(
self, prefix: str | Path | None = None, *, automatic_cleanup: bool = False
self,
prefix: str | Path | None = None,
*,
automatic_cleanup: bool = False,
mkdir: bool = False,
) -> None:
"""Create a new LocalStore.

Expand All @@ -36,6 +40,7 @@ class LocalStore:

Keyword Args:
automatic_cleanup: if `True`, enables automatic cleanup of empty directories when deleting files. Defaults to False.
mkdir: if `True` and `prefix` is not `None`, the directory at `prefix` will attempt to be created. Note that this root directory will not be cleaned up, even if `automatic_cleanup` is `True`.
"""
def __repr__(self) -> str: ...
@classmethod
Expand Down
7 changes: 6 additions & 1 deletion pyo3-object_store/src/local.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::fs::create_dir_all;
use std::sync::Arc;

use object_store::local::LocalFileSystem;
Expand Down Expand Up @@ -29,12 +30,16 @@ impl PyLocalStore {
#[pymethods]
impl PyLocalStore {
#[new]
#[pyo3(signature = (prefix = None, *, automatic_cleanup=false))]
#[pyo3(signature = (prefix = None, *, automatic_cleanup=false, mkdir=false))]
fn py_new(
prefix: Option<std::path::PathBuf>,
automatic_cleanup: bool,
mkdir: bool,
) -> PyObjectStoreResult<Self> {
let fs = if let Some(prefix) = prefix {
if mkdir {
create_dir_all(&prefix)?;
}
LocalFileSystem::new_with_prefix(prefix)?
} else {
LocalFileSystem::new()
Expand Down
12 changes: 12 additions & 0 deletions tests/store/test_local.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import tempfile
from pathlib import Path

import pytest
Expand Down Expand Up @@ -42,3 +43,14 @@ def test_local_from_url():
url = f"file://{HERE.absolute()}//"
with pytest.raises(GenericError):
store = LocalStore.from_url(url)


def test_create_prefix():
tmpdir = Path(tempfile.gettempdir()) / "abc"
assert not tmpdir.exists()
LocalStore(tmpdir, mkdir=True)
assert tmpdir.exists()

# Assert that mkdir=True works even when the dir already exists
LocalStore(tmpdir, mkdir=True)
assert tmpdir.exists()