Source code for ursa.store.backends.local
"""Local filesystem backend backed by `obstore.store.LocalStore`.
The configured `root` is combined with `prefix` (if any) and resolved to
an absolute path; `LocalStore` confines all keys under that directory
and creates it on demand.
"""
from __future__ import annotations
from obstore.store import LocalStore
from ursa.store.backends._obstore import ObstoreBackend
from ursa.store.base import ObjectStore
from ursa.store.config import LocalStoreConfig
[docs]
def build_local_store(cfg: LocalStoreConfig, *, role: str) -> ObjectStore:
"""Construct a Local-filesystem-backed `ObjectStore` for the given role."""
root = (cfg.root / cfg.prefix).resolve() if cfg.prefix else cfg.root.resolve()
inner = LocalStore(prefix=root, mkdir=True)
# obstore's LocalStore does not implement put_opts with attributes
# or UpdateVersion modes — the wrapper raises typed errors when
# callers ask for them, rather than letting the obstore exception
# leak through.
# The prefix is *already* part of `root` for LocalStore (the obstore
# handle's prefix is the resolved root). LocalStore returns relative
# paths from head/list, so we pass `prefix=""` to skip stripping.
# lancedb's local backend takes a plain absolute path (no scheme).
# The catalog appends `/catalog` to this root.
return ObstoreBackend(
inner,
role=role,
backend="local",
prefix="",
supports_attributes=False,
supports_etag_match=False,
lance_uri=str(root),
lance_storage_options={},
)