Skip to content

Commit 12551fd

Browse files
authored
Ensure LocalStore.prefix is a pathlib.Path (#219)
* Ensure `LocalStore.prefix` is a `pathlib.Path` * bump to 0.4.0-beta.3
1 parent e621e9b commit 12551fd

File tree

5 files changed

+28
-4
lines changed

5 files changed

+28
-4
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

obstore/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "obstore"
3-
version = "0.4.0-beta.2"
3+
version = "0.4.0-beta.3"
44
authors = { workspace = true }
55
edition = { workspace = true }
66
description = "The simplest, highest-throughput interface to Amazon S3, Google Cloud Storage, Azure Blob Storage, and S3-compliant APIs like Cloudflare R2."

obstore/python/obstore/store/__init__.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ class LocalStore:
153153

154154
def __getnewargs_ex__(self): ...
155155
def __repr__(self) -> str: ...
156+
@property
157+
def prefix(self) -> Path | None:
158+
"""Get the prefix applied to all operations in this store, if any."""
156159

157160
class MemoryStore:
158161
"""A fully in-memory implementation of ObjectStore.

pyo3-object_store/src/local.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,19 @@ impl PyLocalStore {
113113
}
114114

115115
#[getter]
116-
fn prefix(&self) -> Option<&std::path::PathBuf> {
117-
self.config.prefix.as_ref()
116+
fn prefix(&self, py: Python) -> PyResult<PyObject> {
117+
// Note: returning a std::path::Path or std::path::PathBuf converts back to a Python _str_
118+
// not a Python _pathlib.Path_.
119+
// So we manually convert to a pathlib.Path
120+
if let Some(prefix) = &self.config.prefix {
121+
let pathlib_mod = py.import(intern!(py, "pathlib"))?;
122+
let path_object = pathlib_mod.call_method1(
123+
intern!(py, "Path"),
124+
PyTuple::new(py, vec![prefix.into_pyobject(py)?])?,
125+
)?;
126+
path_object.into_py_any(py)
127+
} else {
128+
Ok(py.None())
129+
}
118130
}
119131
}

tests/store/test_local.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,12 @@ def test_create_prefix():
5454
# Assert that mkdir=True works even when the dir already exists
5555
LocalStore(tmpdir, mkdir=True)
5656
assert tmpdir.exists()
57+
58+
59+
def test_prefix_property():
60+
tmpdir = Path(tempfile.gettempdir())
61+
store = LocalStore(tmpdir)
62+
assert store.prefix == tmpdir
63+
assert isinstance(store.prefix, Path)
64+
# Can pass it back to the store init
65+
LocalStore(store.prefix)

0 commit comments

Comments
 (0)