eoio.writers.factory module#
eoio.writers.factory - writer factory and registry
Writers are resolved by name, not by inspecting a path:
WriterFactory.get_writer("netcdf") # -> NetCDFWriter
WriterFactory.list_writers() # -> ["netcdf", "zarr", ...]
This is deliberately unlike eoio.readers.factory.ReaderFactory, which matches
the product path against a table of regular expressions. The asymmetry is intentional:
on read, the format is a fact about the input that has to be discovered, whereas on
write it is the user’s choice. Inferring it from the output extension is rejected
because it silently guesses, and because it does not extend to directory-style products
such as .SAFE.
Built-in writers are imported lazily, so the cost of an optional backend is only paid
when that writer is actually used. Anything defined outside the package registers with
register_writer(), which is a decorator in the same style as
@register_processor:
@register_writer("myformat")
class MyWriter(BaseWriter):
...
- class eoio.writers.factory.WriterFactory[source]#
Bases:
objectWriter Factory class
- static get_writer(name: str) Type[BaseWriter][source]#
Return the writer registered under
name.- Parameters:
name – Writer name, e.g.
"netcdf".- Returns:
Writer class.
- Raises:
ValueError – If no writer is registered under that name.
- eoio.writers.factory.register_writer(name: str, writer_cls: Type[BaseWriter], overwrite: bool = False) Type[BaseWriter][source]#
- eoio.writers.factory.register_writer(name: str, writer_cls: None = None, overwrite: bool = False) Callable[[Type[BaseWriter]], Type[BaseWriter]]
Register a writer class under a name.
Used as a decorator, matching
eoio.processors.registry.register_processor():@register_writer("netcdf") class NetCDFWriter(BaseWriter): ...
Or called directly, which is what you want for a class you do not own:
register_writer("geotiff", SomeThirdPartyWriter)
Either way the class gets its
nameset, so a registered writer always knows what it is called - which is what ends up in the provenance a write records.- Parameters:
name – Name used to select the writer, e.g.
"netcdf".writer_cls – Writer class. Omit it to use this as a decorator.
overwrite – Whether replacing an already-registered name is permitted.
- Returns:
The registered class, or the decorator that will register it.
- Raises:
KeyError – If the name is taken and
overwriteis False.
- eoio.writers.factory.unregister_writer(name: str) Type[BaseWriter][source]#
Remove a writer registered with
register_writer().- Parameters:
name – Registered writer name.
- Returns:
The removed class.
- Raises:
KeyError – If no writer was registered at runtime under that name.