-
Notifications
You must be signed in to change notification settings - Fork 206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace sketchy opener interfaces with ABCs in fiona.abc #1415
Conversation
This also adds support for GDAL VSI multi-range reads.
from fiona.abc import FileContainer | ||
|
||
class CustomContainer: | ||
"""GDAL's VSI ReadDir() uses 5 of FileContainer's methods.""" | ||
def isdir(self, path): | ||
return pathlib.Path(path).is_dir() | ||
|
||
def isfile(self, path): | ||
return pathlib.Path(path).is_file() | ||
|
||
def ls(self, path): | ||
return list(pathlib.Path(path).iterdir()) | ||
|
||
def mtime(self, path): | ||
return pathlib.Path(path).stat().st_mtime | ||
|
||
def size(self, path): | ||
return pathlib.Path(path).stat().st_size | ||
|
||
FileContainer.register(CustomContainer) | ||
|
||
listing = fiona.listdir("tests/data", opener=CustomContainer()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is how a Fiona user creates a custom opener for their own application.
@vincentsarago @mwtoews @snorfalorpagus what do you think of a fiona.abc module? Vincent, I think this is what we should do for Rasterio. |
@@ -353,7 +376,7 @@ def _opener_registration(urlpath, obj): | |||
cdef bytes prefix_bytes = f"/{namespace}/".encode("utf-8") | |||
|
|||
# Might raise. | |||
opener = _create_opener(obj) | |||
opener = to_pyopener(obj) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
def size(self, path): | ||
return pathlib.Path(path).stat().st_size | ||
|
||
FileContainer.register(CustomContainer) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔥
Also adds support for GDAL VSI multi-range reads. This is an attempt to take rasterio/rasterio#3117 all the way to a stable interface and API.
io.open()
, fsspec filesystems, and to a lesser degree,tiledb.VFS
, are privileged openers. There are built-in adapters for these objects.Otherwise, users should implement
fiona.abc.FileContainer
and register their class as a virtual subclass within their application likeFileContainer.register(NewClass)
.fiona.abc.MultiByteRangeResourceContainer
exists for completeness, to provide a template for Rasterio, and for compatibility with future GDAL/OGR drivers that may exploit it. Currently no vectors drivers do and there is no point in implementing this interface.