Skip to content

Commit 9f65dd1

Browse files
committed
Switch to object_store
1 parent 19a57bb commit 9f65dd1

File tree

2 files changed

+24
-33
lines changed

2 files changed

+24
-33
lines changed

icechunk-python/benchmarks/datasets.py

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
from functools import partial
88
from typing import Any, Literal, Self, TypeAlias
99

10-
import fsspec
1110
import numpy as np
11+
from object_store import ObjectStore
1212

1313
import icechunk as ic
1414
import icechunk.xarray
@@ -129,22 +129,30 @@ def env_vars(self) -> dict[str, str]:
129129
# return {"AWS_ENDPOINT_URL_IAM": "https://fly.iam.storage.tigris.dev"}
130130
return {}
131131

132-
@property
133-
def protocol(self) -> str:
134-
if self.store in ("s3", "tigris"):
135-
protocol = "s3"
136-
elif self.store == "gcs":
137-
protocol = "gcs"
138-
else:
139-
protocol = "file"
140-
return protocol
132+
_SCHEMES = {"s3": "s3", "s3_ob": "s3", "gcs": "gs", "tigris": "s3", "r2": "s3"}
133+
134+
def clear_prefix(self) -> None:
135+
"""Delete all objects under this prefix using object_store."""
136+
import shutil
141137

142-
def clear_uri(self) -> str:
143-
"""URI to clear when re-creating data from scratch."""
144138
if self.store == "local":
145-
return f"{self.protocol}://{self.path}"
146-
else:
147-
return f"{self.protocol}://{self.bucket}/{self.prefix}"
139+
shutil.rmtree(self.path, ignore_errors=True)
140+
return
141+
142+
scheme = self._SCHEMES.get(self.store)
143+
if scheme is None:
144+
warnings.warn(
145+
f"Clearing not supported for store {self.store!r}",
146+
RuntimeWarning,
147+
stacklevel=2,
148+
)
149+
return
150+
151+
store_url = f"{scheme}://{self.bucket}"
152+
store = ObjectStore(store_url)
153+
objects = store.list(prefix=self.prefix)
154+
for obj in objects:
155+
store.delete(obj["path"])
148156

149157
def get_coiled_kwargs(self) -> dict[str, str]:
150158
assert self.store is not None, (
@@ -174,22 +182,7 @@ def create(
174182
self, clear: bool = False, config: ic.RepositoryConfig | None = None
175183
) -> ic.Repository:
176184
if clear:
177-
clear_uri = self.storage_config.clear_uri()
178-
if clear_uri is None:
179-
raise NotImplementedError
180-
if self.storage_config.protocol not in ["file", "s3", "gcs"]:
181-
warnings.warn(
182-
f"Only clearing of GCS, S3-compatible URIs supported at the moment. Received {clear_uri!r}",
183-
RuntimeWarning,
184-
stacklevel=2,
185-
)
186-
else:
187-
fs = fsspec.filesystem(self.storage_config.protocol)
188-
try:
189-
logger.info(f"Clearing prefix: {clear_uri!r}")
190-
fs.rm(clear_uri, recursive=True)
191-
except FileNotFoundError:
192-
pass
185+
self.storage_config.clear_prefix()
193186
logger.info(repr(self.storage))
194187
return ic.Repository.create(self.storage, config=config)
195188

icechunk-python/pyproject.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ test = [
5454
benchmark = [
5555
"boto3",
5656
"object-store-python",
57-
"s3fs",
58-
"gcsfs",
5957
"pytest-benchmark[histogram]",
6058
"h5netcdf",
6159
"pooch",

0 commit comments

Comments
 (0)