civiqhub_selene.registry¶
Registry of estimators, read from entry points. Standard library only.
The registry is the extension point of the engine. A package adds a method by declaring a class in its metadata; no class of the engine is modified:
[project.entry-points."civiqhub_selene.estimators"]
"coclustering.single" = "civiqhub_selene.blocks.single:LatentBlockModel"
A key reads family.choice in lower case. Facades translate a plain word
("single", "mixed") into an estimator through the registry:
spec = default_registry()["coclustering.single"]
estimator_class = spec.load()
Reading the registry imports nothing: a class is imported when its entry is loaded.
- civiqhub_selene.registry.GROUP = 'civiqhub_selene.estimators'¶
Entry-point group under which estimators are declared.
- class civiqhub_selene.registry.EstimatorSpec(key, target)[source]¶
Bases:
objectOne entry of the registry.
- key¶
family.choice, lower case, for examplecoclustering.single.- Type:
str
- target¶
Where the class lives, written
module:Class.- Type:
str
- Raises:
InvalidParameterError – If the key or the target is malformed.
- Parameters:
key (str)
target (str)
- property family: str¶
The first half of the key: the family of methods.
- property choice: str¶
The second half of the key: the method chosen within its family.
- load()[source]¶
Import the module and return the estimator class. The class is kept.
- Raises:
UnknownEstimatorError – If the module or the class does not exist.
EstimatorDefinitionError – If the target is not a subclass of
Estimator.MissingExtraError – Raised by the import itself when an optional dependency is missing; it goes through unchanged.
- Return type:
type[Estimator[Any, Any]]
- class civiqhub_selene.registry.Registry(specs=())[source]¶
Bases:
Mapping[str,EstimatorSpec]Immutable mapping from
family.choicekeys toEstimatorSpec.Iteration yields the keys in sorted order. A missing key raises
UnknownEstimatorError, which lists the choices of the same family.left | rightgives a new registry whererightwins on a shared key.- Parameters:
specs (Iterable[EstimatorSpec]) – The entries. When two entries share a key, the last one wins.
- classmethod from_entry_points(group=GROUP)[source]¶
Read the installed entry points of
group. No class is imported.- Raises:
InvalidParameterError – If an installed entry point has a malformed key.
EstimatorDefinitionError – If two installed packages declare the same key with different targets.
- Parameters:
group (str)
- Return type:
- classmethod from_classes(classes)[source]¶
Build a registry from classes at hand, for tests and uses without install.
- Raises:
InvalidParameterError – If a key is malformed.
EstimatorDefinitionError – If a value is not a subclass of
Estimator.
- Parameters:
classes (Mapping[str, type[Estimator[Any, Any]]])
- Return type:
- get(key: str, /) EstimatorSpec | None[source]¶
- get(key: str, /, default: EstimatorSpec | _DefaultT) EstimatorSpec | _DefaultT
Return the entry under
key, ordefaultwhen there is none.- Parameters:
key (str)
default (EstimatorSpec | _DefaultT | None)
- Return type:
EstimatorSpec | _DefaultT | None
- family(name)[source]¶
Return the entries of one family, indexed by
choice.- Parameters:
name (str)
- Return type:
dict[str, EstimatorSpec]