Skip to content

Commit eb95be4

Browse files
committed
return empty values rather than raising NotImplementedError
1 parent 77a6385 commit eb95be4

File tree

1 file changed

+37
-25
lines changed

1 file changed

+37
-25
lines changed

src/ai/backend/storage/volumes/noop/__init__.py

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from collections.abc import Sequence
2+
from datetime import datetime
23
from pathlib import Path, PurePosixPath
34
from typing import Any, AsyncIterator, Optional
45

@@ -10,18 +11,26 @@
1011
from ...types import (
1112
CapacityUsage,
1213
DirEntry,
14+
DirEntryType,
1315
FSPerfMetric,
1416
QuotaConfig,
1517
QuotaUsage,
18+
Stat,
1619
TreeUsage,
1720
VFolderID,
1821
)
1922
from ..abc import AbstractFSOpModel, AbstractQuotaModel, AbstractVolume
2023

2124

25+
async def _return_empty_dir_entry() -> AsyncIterator[DirEntry]:
26+
yield DirEntry(
27+
"", Path(), DirEntryType.FILE, Stat(0, "", 0, datetime.now(), datetime.now()), ""
28+
)
29+
30+
2231
class NoopQuotaModel(AbstractQuotaModel):
2332
def __init__(self) -> None:
24-
return
33+
pass
2534

2635
def mangle_qspath(self, ref: VFolderID | QuotaScopeID | str | None) -> Path:
2736
return Path()
@@ -32,32 +41,32 @@ async def create_quota_scope(
3241
options: Optional[QuotaConfig] = None,
3342
extra_args: Optional[dict[str, Any]] = None,
3443
) -> None:
35-
raise NotImplementedError
44+
pass
3645

3746
async def describe_quota_scope(
3847
self,
3948
quota_scope_id: QuotaScopeID,
4049
) -> Optional[QuotaUsage]:
41-
raise NotImplementedError
50+
pass
4251

4352
async def update_quota_scope(
4453
self,
4554
quota_scope_id: QuotaScopeID,
4655
config: QuotaConfig,
4756
) -> None:
48-
raise NotImplementedError
57+
pass
4958

5059
async def unset_quota(
5160
self,
5261
quota_scope_id: QuotaScopeID,
5362
) -> None:
54-
raise NotImplementedError
63+
pass
5564

5665
async def delete_quota_scope(
5766
self,
5867
quota_scope_id: QuotaScopeID,
5968
) -> None:
60-
raise NotImplementedError
69+
pass
6170

6271

6372
class NoopFSOpModel(AbstractFSOpModel):
@@ -69,40 +78,40 @@ async def copy_tree(
6978
src_path: Path,
7079
dst_path: Path,
7180
) -> None:
72-
raise NotImplementedError
81+
pass
7382

7483
async def move_tree(
7584
self,
7685
src_path: Path,
7786
dst_path: Path,
7887
) -> None:
79-
raise NotImplementedError
88+
pass
8089

8190
async def delete_tree(
8291
self,
8392
path: Path,
8493
) -> None:
85-
raise NotImplementedError
94+
pass
8695

8796
def scan_tree(
8897
self,
8998
path: Path,
9099
*,
91100
recursive: bool = True,
92101
) -> AsyncIterator[DirEntry]:
93-
raise NotImplementedError
102+
return _return_empty_dir_entry()
94103

95104
async def scan_tree_usage(
96105
self,
97106
path: Path,
98107
) -> TreeUsage:
99-
raise NotImplementedError
108+
return TreeUsage(0, 0)
100109

101110
async def scan_tree_size(
102111
self,
103112
path: Path,
104113
) -> BinarySize:
105-
raise NotImplementedError
114+
return BinarySize(0)
106115

107116

108117
class NoopVolume(AbstractVolume):
@@ -148,13 +157,13 @@ async def get_vfolder_mount(self, vfid: VFolderID, subpath: str) -> Path:
148157
return Path()
149158

150159
async def put_metadata(self, vfid: VFolderID, payload: bytes) -> None:
151-
raise NotImplementedError
160+
pass
152161

153162
async def get_metadata(self, vfid: VFolderID) -> bytes:
154-
raise NotImplementedError
163+
return b""
155164

156165
async def get_performance_metric(self) -> FSPerfMetric:
157-
raise NotImplementedError
166+
return FSPerfMetric(0, 0, 0, 0, 0.0, 0.0)
158167

159168
async def get_fs_usage(self) -> CapacityUsage:
160169
return CapacityUsage(0, 0)
@@ -178,7 +187,7 @@ def scandir(
178187
*,
179188
recursive: bool = True,
180189
) -> AsyncIterator[DirEntry]:
181-
raise NotImplementedError
190+
return _return_empty_dir_entry()
182191

183192
async def mkdir(
184193
self,
@@ -188,7 +197,7 @@ async def mkdir(
188197
parents: bool = False,
189198
exist_ok: bool = False,
190199
) -> None:
191-
raise NotImplementedError
200+
pass
192201

193202
async def rmdir(
194203
self,
@@ -197,42 +206,42 @@ async def rmdir(
197206
*,
198207
recursive: bool = False,
199208
) -> None:
200-
raise NotImplementedError
209+
pass
201210

202211
async def move_file(
203212
self,
204213
vfid: VFolderID,
205214
src: PurePosixPath,
206215
dst: PurePosixPath,
207216
) -> None:
208-
raise NotImplementedError
217+
pass
209218

210219
async def move_tree(
211220
self,
212221
vfid: VFolderID,
213222
src: PurePosixPath,
214223
dst: PurePosixPath,
215224
) -> None:
216-
raise NotImplementedError
225+
pass
217226

218227
async def copy_file(
219228
self,
220229
vfid: VFolderID,
221230
src: PurePosixPath,
222231
dst: PurePosixPath,
223232
) -> None:
224-
raise NotImplementedError
233+
pass
225234

226235
async def prepare_upload(self, vfid: VFolderID) -> str:
227-
raise NotImplementedError
236+
return ""
228237

229238
async def add_file(
230239
self,
231240
vfid: VFolderID,
232241
relpath: PurePosixPath,
233242
payload: AsyncIterator[bytes],
234243
) -> None:
235-
raise NotImplementedError
244+
pass
236245

237246
def read_file(
238247
self,
@@ -241,7 +250,10 @@ def read_file(
241250
*,
242251
chunk_size: int = 0,
243252
) -> AsyncIterator[bytes]:
244-
raise NotImplementedError
253+
async def _noop() -> AsyncIterator[bytes]:
254+
yield b""
255+
256+
return _noop()
245257

246258
async def delete_files(
247259
self,
@@ -250,7 +262,7 @@ async def delete_files(
250262
*,
251263
recursive: bool = False,
252264
) -> None:
253-
raise NotImplementedError
265+
pass
254266

255267

256268
def init_noop_volume(

0 commit comments

Comments
 (0)