Backend Options
Call-time helpers for backend-selectable families whose default backend is built by calling the family.
Calling a family base class, such as PPOCRTextDetector("ppocrv6_tiny"), builds its default backend
through the family's build classmethod. FamilyBuildMeta routes that call, and
bind_backend_options checks the caller's options against the backend constructor's signature before
the backend is constructed.
FamilyBuildMeta
Bases: ABCMeta
Metaclass that makes calling a backend-selectable family base build its default backend.
Calling a concrete backend class, or any family subclass, behaves as usual. Calling the family base
itself delegates to its build classmethod, so the backend is constructed once and __init__
is not run a second time on the returned object.
__call__(*args, **kwargs)
Build the default backend when the family base is called, otherwise construct the class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Any
|
Positional constructor arguments, forwarded to the backend or the class. |
()
|
**kwargs
|
Any
|
Keyword constructor arguments. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The constructed backend instance, or the new instance of a concrete class. |
FamilyBuildMixin
Mixin giving a backend-selectable PP-OCR family a build that checks options before construction.
Each family sets _FAMILY_COMPONENT to its friendly component name, which appears in option errors. The mixin
must precede BackendSelectableProcessor in the bases, so its build replaces the registry's.
build(backend=None, *args, **kwargs)
classmethod
Build the backend selected by name, with the family's default when omitted.
The options are checked against the backend's constructor signature before it is constructed, so an
unknown option raises a taxonomy error instead of a raw TypeError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
str | MediaBackend | None
|
Backend key, such as |
None
|
*args
|
Any
|
Positional options forwarded to the backend constructor, such as the model source. |
()
|
**kwargs
|
Any
|
Keyword options forwarded to the backend constructor. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The instantiated backend. |
Raises:
| Type | Description |
|---|---|
ComponentConfigError
|
If the backend is unknown, or an option is not accepted by the backend. |
bind_backend_options(component, backend_cls, args, kwargs)
Check that caller options bind to a backend constructor's signature, before it is constructed.
The check reads the signature of __init__ rather than of the class, because a family's metaclass
defines __call__ and inspect.signature on the class would report that signature instead. Only
the call signature is checked, so a TypeError raised inside the constructor body keeps propagating
unchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
component
|
str
|
Friendly component name used in the error, such as |
required |
backend_cls
|
type
|
The backend class whose constructor receives the options. |
required |
args
|
tuple[Any, ...]
|
Positional options the caller passed. |
required |
kwargs
|
dict[str, Any]
|
Keyword options the caller passed. |
required |
Raises:
| Type | Description |
|---|---|
ComponentConfigError
|
If the options do not bind to the backend constructor's signature. The error names the keyword options the constructor does not accept, or asks for only the accepted options. |