Registry¶
registry
¶
Format registry for automatic format detection and handler selection.
The registry maintains a list of available format handlers and automatically selects the appropriate handler for reading/writing files based on file extension and content detection.
Classes¶
FormatRegistry
¶
Registry for file format handlers with automatic format detection.
The registry maintains a collection of format handlers and provides methods to automatically detect and handle different file formats.
Initialize empty registry.
Source code in optiscope/io/registry.py
Functions¶
register
¶
register(handler: type[BaseFormatHandler], extensions: list[str] | None = None) -> None
Register a format handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
handler
|
type[BaseFormatHandler]
|
Handler class to register |
required |
extensions
|
list[str] | None
|
Optional list of file extensions (overrides handler.file_extensions) |
None
|
Source code in optiscope/io/registry.py
unregister
¶
unregister(handler: type[BaseFormatHandler]) -> None
Unregister a format handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
handler
|
type[BaseFormatHandler]
|
Handler class to unregister |
required |
Source code in optiscope/io/registry.py
get_handler_for_file
¶
get_handler_for_file(filepath: Path | str, format_hint: str | None = None) -> BaseFormatHandler
Get appropriate handler for a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
Path | str
|
Path to file |
required |
format_hint
|
str | None
|
Optional format name to prefer |
None
|
Returns:
| Type | Description |
|---|---|
BaseFormatHandler
|
Handler instance |
Raises:
| Type | Description |
|---|---|
FormatDetectionError
|
If no suitable handler found |
Source code in optiscope/io/registry.py
load
¶
load(filepath: Path | str, format_hint: str | None = None, **kwargs: Any) -> OptimizationResult
Load optimization results from file with automatic format detection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
Path | str
|
Path to file |
required |
format_hint
|
str | None
|
Optional format name hint |
None
|
**kwargs
|
Any
|
Additional arguments passed to handler |
{}
|
Returns:
| Type | Description |
|---|---|
OptimizationResult
|
OptimizationResult object |
Raises:
| Type | Description |
|---|---|
FormatDetectionError
|
If format cannot be detected |
FormatReadError
|
If file cannot be read |
Source code in optiscope/io/registry.py
save
¶
save(result: OptimizationResult, filepath: Path | str, format_hint: str | None = None, **kwargs: Any) -> None
Save optimization results to file with automatic format selection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
OptimizationResult
|
OptimizationResult to save |
required |
filepath
|
Path | str
|
Output file path |
required |
format_hint
|
str | None
|
Optional format name hint |
None
|
**kwargs
|
Any
|
Additional arguments passed to handler |
{}
|
Raises:
| Type | Description |
|---|---|
FormatDetectionError
|
If format cannot be determined |
FormatWriteError
|
If file cannot be written |
Source code in optiscope/io/registry.py
list_formats
¶
List all registered formats.
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of format information dictionaries |
Source code in optiscope/io/registry.py
get_supported_extensions
¶
Functions¶
discover_handlers
¶
discover_handlers(registry: FormatRegistry, entry_point_group: str = 'optiscope.io.handlers')
Discover handlers from installed Python packages that declare them.
Source code in optiscope/io/registry.py
get_global_registry
¶
get_global_registry() -> FormatRegistry
Get the global format registry instance.
Returns:
| Type | Description |
|---|---|
FormatRegistry
|
Global FormatRegistry |
Source code in optiscope/io/registry.py
load_results
¶
load_results(filepath: Path | str, **kwargs: Any) -> OptimizationResult
Convenience function to load results using global registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
Path | str
|
Path to file |
required |
**kwargs
|
Any
|
Additional arguments |
{}
|
Returns:
| Type | Description |
|---|---|
OptimizationResult
|
OptimizationResult |
Source code in optiscope/io/registry.py
save_results
¶
save_results(result: OptimizationResult, filepath: Path | str, **kwargs: Any) -> None
Convenience function to save results using global registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
OptimizationResult
|
OptimizationResult to save |
required |
filepath
|
Path | str
|
Output path |
required |
**kwargs
|
Any
|
Additional arguments |
{}
|