diff --git a/obstore/python/obstore/store/__init__.pyi b/obstore/python/obstore/store/__init__.pyi index 414521b1..f7499c4f 100644 --- a/obstore/python/obstore/store/__init__.pyi +++ b/obstore/python/obstore/store/__init__.pyi @@ -1,4 +1,6 @@ # TODO: move to reusable types package +from pathlib import Path + from ._aws import S3ConfigKey as S3ConfigKey from ._aws import S3Store as S3Store from ._azure import AzureConfigKey as AzureConfigKey @@ -16,11 +18,15 @@ class LocalStore: Can optionally be created with a directory prefix. ```py + from pathlib import Path + store = LocalStore() store = LocalStore(prefix="/path/to/directory") + store = LocalStore(prefix=Path(".")) ``` """ - def __init__(self, prefix: str | None = None) -> None: ... + def __init__(self, prefix: str | Path | None = None) -> None: ... + def __repr__(self) -> str: ... class MemoryStore: """A fully in-memory implementation of ObjectStore. @@ -31,6 +37,7 @@ class MemoryStore: ``` """ def __init__(self) -> None: ... + def __repr__(self) -> str: ... ObjectStore = AzureStore | GCSStore | HTTPStore | S3Store | LocalStore | MemoryStore """All supported ObjectStore implementations.""" diff --git a/obstore/python/obstore/store/_aws.pyi b/obstore/python/obstore/store/_aws.pyi index be0620f2..b288fd01 100644 --- a/obstore/python/obstore/store/_aws.pyi +++ b/obstore/python/obstore/store/_aws.pyi @@ -213,3 +213,5 @@ class S3Store: Returns: S3Store """ + + def __repr__(self) -> str: ... diff --git a/obstore/python/obstore/store/_azure.pyi b/obstore/python/obstore/store/_azure.pyi index 8c7d8956..e36421e0 100644 --- a/obstore/python/obstore/store/_azure.pyi +++ b/obstore/python/obstore/store/_azure.pyi @@ -210,3 +210,5 @@ class AzureStore: Returns: AzureStore """ + + def __repr__(self) -> str: ... diff --git a/obstore/python/obstore/store/_gcs.pyi b/obstore/python/obstore/store/_gcs.pyi index 2b74f9cc..71ef74cf 100644 --- a/obstore/python/obstore/store/_gcs.pyi +++ b/obstore/python/obstore/store/_gcs.pyi @@ -103,3 +103,5 @@ class GCSStore: Returns: GCSStore """ + + def __repr__(self) -> str: ... diff --git a/obstore/python/obstore/store/_http.pyi b/obstore/python/obstore/store/_http.pyi index d9922cd3..c1ce3cfa 100644 --- a/obstore/python/obstore/store/_http.pyi +++ b/obstore/python/obstore/store/_http.pyi @@ -26,3 +26,5 @@ class HTTPStore: Returns: HTTPStore """ + + def __repr__(self) -> str: ... diff --git a/pyo3-object_store/src/aws.rs b/pyo3-object_store/src/aws.rs index f804a3f0..20d930ea 100644 --- a/pyo3-object_store/src/aws.rs +++ b/pyo3-object_store/src/aws.rs @@ -140,6 +140,11 @@ impl PyS3Store { } Ok(Self(Arc::new(builder.build()?))) } + + fn __repr__(&self) -> String { + let repr = self.0.to_string(); + repr.replacen("AmazonS3", "S3Store", 1) + } } #[derive(Debug, PartialEq, Eq, Hash)] diff --git a/pyo3-object_store/src/azure.rs b/pyo3-object_store/src/azure.rs index e9750e70..aa84ddad 100644 --- a/pyo3-object_store/src/azure.rs +++ b/pyo3-object_store/src/azure.rs @@ -78,6 +78,11 @@ impl PyAzureStore { } Ok(Self(Arc::new(builder.build()?))) } + + fn __repr__(&self) -> String { + let repr = self.0.to_string(); + repr.replacen("MicrosoftAzure", "AzureStore", 1) + } } #[derive(Debug, PartialEq, Eq, Hash)] diff --git a/pyo3-object_store/src/gcp.rs b/pyo3-object_store/src/gcp.rs index 5f6b783d..0ed2499b 100644 --- a/pyo3-object_store/src/gcp.rs +++ b/pyo3-object_store/src/gcp.rs @@ -78,6 +78,11 @@ impl PyGCSStore { } Ok(Self(Arc::new(builder.build()?))) } + + fn __repr__(&self) -> String { + let repr = self.0.to_string(); + repr.replacen("GoogleCloudStorage", "GCSStore", 1) + } } #[derive(Debug, PartialEq, Eq, Hash)] diff --git a/pyo3-object_store/src/http.rs b/pyo3-object_store/src/http.rs index 086f35fd..b43f7f59 100644 --- a/pyo3-object_store/src/http.rs +++ b/pyo3-object_store/src/http.rs @@ -23,6 +23,10 @@ impl PyHttpStore { pub fn into_inner(self) -> Arc { self.0 } + + fn __repr__(&self) -> String { + self.0.to_string() + } } #[pymethods] diff --git a/pyo3-object_store/src/local.rs b/pyo3-object_store/src/local.rs index fd5d4693..6b1cc2aa 100644 --- a/pyo3-object_store/src/local.rs +++ b/pyo3-object_store/src/local.rs @@ -34,4 +34,9 @@ impl PyLocalStore { }; Ok(Self(Arc::new(fs))) } + + fn __repr__(&self) -> String { + let repr = self.0.to_string(); + repr.replacen("LocalFileSystem", "LocalStore", 1) + } } diff --git a/pyo3-object_store/src/memory.rs b/pyo3-object_store/src/memory.rs index f697ea1b..e2b0aa5b 100644 --- a/pyo3-object_store/src/memory.rs +++ b/pyo3-object_store/src/memory.rs @@ -1,7 +1,9 @@ use std::sync::Arc; use object_store::memory::InMemory; +use pyo3::intern; use pyo3::prelude::*; +use pyo3::types::PyString; /// A Python-facing wrapper around an [`InMemory`]. #[pyclass(name = "MemoryStore")] @@ -13,11 +15,15 @@ impl AsRef> for PyMemoryStore { } } -impl PyMemoryStore { +impl<'py> PyMemoryStore { /// Consume self and return the underlying [`InMemory`]. pub fn into_inner(self) -> Arc { self.0 } + + fn __repr__(&'py self, py: Python<'py>) -> &Bound<'py, PyString> { + intern!(py, "MemoryStore") + } } #[pymethods] diff --git a/tests/store/__init__.py b/tests/store/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/store/test_local.py b/tests/store/test_local.py new file mode 100644 index 00000000..9fea8790 --- /dev/null +++ b/tests/store/test_local.py @@ -0,0 +1,17 @@ +from pathlib import Path + +import obstore as obs +from obstore.store import LocalStore + + +def test_local_store(): + here = Path(".") + store = LocalStore(here) + list_result = obs.list(store).collect() + assert any("test_local.py" in x["path"] for x in list_result) + + +def test_repr(): + here = Path(".") + store = LocalStore(here) + assert repr(store).startswith("LocalStore")