|
32 | 32 |
|
33 | 33 |
|
34 | 34 | def _make_async(fs: AbstractFileSystem) -> AsyncFileSystem: |
| 35 | + """Convert a sync FSSpec filesystem to an async FFSpec filesystem |
| 36 | +
|
| 37 | + If the filesystem class supports async operations, a new async instance is created |
| 38 | + from the existing instance. |
| 39 | +
|
| 40 | + If the filesystem class does not support async operations, the existing instance |
| 41 | + is wrapped with AsyncFileSystemWrapper. |
| 42 | + """ |
| 43 | + if fs.async_impl and fs.asynchronous: |
| 44 | + return fs |
| 45 | + if fs.async_impl: |
| 46 | + raise NotImplementedError( |
| 47 | + f"The filesystem '{fs}' is synchronous and wrapping synchronous filesystems using from_mapper has not been implemented. See https://github.com/zarr-developers/zarr-python/issues/2706 for more details." |
| 48 | + ) |
35 | 49 | try: |
36 | 50 | from fsspec.implementations.asyn_wrapper import AsyncFileSystemWrapper |
37 | 51 |
|
38 | | - fs = AsyncFileSystemWrapper(fs) |
| 52 | + return AsyncFileSystemWrapper(fs) |
39 | 53 | except ImportError as e: |
40 | 54 | raise ImportError( |
41 | 55 | f"The filesystem '{fs}' is synchronous, and the required " |
42 | 56 | "AsyncFileSystemWrapper is not available. Upgrade fsspec to version " |
43 | 57 | "2024.12.0 or later to enable this functionality." |
44 | 58 | ) from e |
45 | | - return fs |
46 | 59 |
|
47 | 60 |
|
48 | 61 | class FsspecStore(Store): |
@@ -174,14 +187,8 @@ def from_mapper( |
174 | 187 | ------- |
175 | 188 | FsspecStore |
176 | 189 | """ |
177 | | - if not fs_map.fs.async_impl: |
178 | | - raise NotImplementedError( |
179 | | - f"The filesystem '{fs_map.fs}' is synchronous and wrapping synchronous filesystems using from_mapper has not been implemented. See https://github.com/zarr-developers/zarr-python/issues/2706 for more details." |
180 | | - ) |
181 | 190 | if not fs_map.fs.asynchronous: |
182 | | - raise NotImplementedError( |
183 | | - f"The filesystem '{fs_map.fs}' is synchronous and conversion to an async instance has not been implemented. See https://github.com/zarr-developers/zarr-python/issues/2706 for more details." |
184 | | - ) |
| 191 | + fs_map.fs = _make_async(fs_map.fs) |
185 | 192 | return cls( |
186 | 193 | fs=fs_map.fs, |
187 | 194 | path=fs_map.root, |
|
0 commit comments