From e216fe17ef9363f4dffe8719ab4f86fbe35af775 Mon Sep 17 00:00:00 2001 From: Pete Gadomski Date: Sat, 31 May 2025 06:50:30 -0600 Subject: [PATCH] fix: object store typing --- pyproject.toml | 1 + python/rustac/__init__.py | 4 ++++ python/rustac/rustac.pyi | 9 ++++++--- tests/test_read.py | 11 +++++++++++ 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 0847ec4..444971a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -44,6 +44,7 @@ ignore_missing_imports = true asyncio_mode = "auto" asyncio_default_fixture_loop_scope = "function" testpaths = ["tests"] +filterwarnings = ["error"] [tool.ruff] exclude = [ diff --git a/python/rustac/__init__.py b/python/rustac/__init__.py index b39667b..e618138 100644 --- a/python/rustac/__init__.py +++ b/python/rustac/__init__.py @@ -252,3 +252,7 @@ class ItemCollection(TypedDict): __doc__ = rustac.__doc__ if hasattr(rustac, "__all__"): __all__ = rustac.__all__ +else: + __all__ = [] + +__all__.append("store") \ No newline at end of file diff --git a/python/rustac/rustac.pyi b/python/rustac/rustac.pyi index fe4e626..d5bec1a 100644 --- a/python/rustac/rustac.pyi +++ b/python/rustac/rustac.pyi @@ -5,10 +5,13 @@ from pathlib import Path from typing import Any, Literal import arro3.core +from obstore.store import ObjectStore as ObstoreObjectStore from rustac import Catalog, Collection, Item, ItemCollection from rustac.store import ObjectStore +AnyObjectStore = ObjectStore | ObstoreObjectStore + class RustacError(Exception): """A package-specific exception.""" @@ -212,7 +215,7 @@ async def read( href: str, *, format: str | None = None, - store: ObjectStore | None = None, + store: AnyObjectStore | None = None, set_self_link: bool = True, ) -> dict[str, Any]: """ @@ -347,7 +350,7 @@ async def search_to( filter: str | dict[str, Any] | None = None, query: dict[str, Any] | None = None, format: str | None = None, - store: ObjectStore | None = None, + store: AnyObjectStore | None = None, use_duckdb: bool | None = None, ) -> int: """ @@ -425,7 +428,7 @@ async def write( value: dict[str, Any] | Sequence[dict[str, Any]], *, format: str | None = None, - store: ObjectStore | None = None, + store: AnyObjectStore | None = None, ) -> dict[str, str] | None: """ Writes STAC to a href. diff --git a/tests/test_read.py b/tests/test_read.py index 4deb316..884f5b1 100644 --- a/tests/test_read.py +++ b/tests/test_read.py @@ -1,7 +1,9 @@ from pathlib import Path from typing import Any +import pytest import rustac +from obstore.store import LocalStore as ObstoreLocalStore from pystac import Item from rustac.store import LocalStore @@ -33,3 +35,12 @@ async def test_read_proj_geometry( async def test_read_store(examples: Path) -> None: store = LocalStore(prefix=str(examples)) await rustac.read("simple-item.json", store=store) + + +async def test_read_external_store(examples: Path) -> None: + store = ObstoreLocalStore(prefix=str(examples)) + with pytest.warns( + RuntimeWarning, + match="Successfully reconstructed a store defined in another Python module. Connection pooling will not be shared across store instances.", + ): + await rustac.read("simple-item.json", store=store)