Source code for shapelib.core.cloud.writers.generic_cloud_writer
"""Generic cloud writer for any file format."""
from __future__ import annotations
from typing import Any
from shapelib.core.cloud.cloud_path import CloudPath
from shapelib.core.cloud.writers.base_cloud_writer import BaseCloudWriter
from shapelib.factories.cloud_registry import register_cloud_writer
[docs]
@register_cloud_writer
class GenericCloudWriter(BaseCloudWriter):
"""
Generic cloud writer for any file format.
This is the fallback writer used when no format-specific writer
is registered. It passes arguments directly to gdf.to_file()
without format-specific optimizations.
Examples
--------
>>> writer = GenericCloudWriter()
>>> if writer.supports(cloud_path):
... writer.write(gdf, cloud_path)
Big-O
-----
O(n) where n is data size, plus network upload time.
"""
[docs]
def supports(self, cloud_path: CloudPath) -> bool:
"""
Check if this writer handles the given path.
This is the fallback writer, so it supports any remote path.
Parameters
----------
cloud_path : CloudPath
The parsed destination path.
Returns
-------
bool
True if the path is remote.
"""
return cloud_path.is_remote
def _build_write_kwargs(
self,
temp_dir: str,
driver: str | None,
schema: Any | None,
index: Any | None,
**kwargs: Any,
) -> dict[str, Any]:
"""
Build kwargs for to_file() without format-specific optimizations.
Simply passes through the provided arguments.
"""
return {
"driver": driver,
"schema": schema,
"index": index,
**kwargs,
}