geomotif.core.registry
¶
Motif registration, lookup and introspection.
Registering a motif is what makes it discoverable by name -- to the CLI, to the gallery builder, to the conformance test suite, and to anyone who wants to round-trip a design through a JSON spec.
Third-party packages ship their own motifs by declaring an entry point::
[project.entry-points."geomotif.motifs"]
my_motifs = "my_package.motifs:register_all"
The builtin catalog and any such plugins are loaded lazily, on the first registry access rather than at import, so a motif family nobody touches costs nothing to have installed.
Classes:
| Name | Description |
|---|---|
ParamInfo |
One constructor parameter of a motif, as the CLI and docs see it. |
MotifInfo |
Everything known about a registered motif without instantiating it. |
Functions:
| Name | Description |
|---|---|
register |
Register a motif class under |
names |
Return every registered motif name, sorted; optionally one family only. |
families |
Return every family name that has at least one motif, sorted. |
get |
Return the motif class registered under |
create |
Instantiate the motif registered under |
describe |
Return a motif's documentation and parameter list without building it. |
name_for |
Return the name |
spec |
Return a reproducible description of |
ParamInfo
dataclass
¶
ParamInfo(name: str, annotation: str, default: object, required: bool, description: str | None = None, min: float | None = None, max: float | None = None, step: float | None = None)
One constructor parameter of a motif, as the CLI and docs see it.
The numeric range fields (min, max, step) come from a
:class:~geomotif.Range on the field's metadata; they are None
when a motif has not declared a bound, in which case a consumer falls
back to its own heuristic rather than guessing zero.
MotifInfo
dataclass
¶
MotifInfo(name: str, cls: type[Motif], family: str | None, requires: str | None, summary: str, doc: str, params: tuple[ParamInfo, ...], example: Mapping[str, object])
Everything known about a registered motif without instantiating it.
Attributes:
| Name | Type | Description |
|---|---|---|
available |
bool
|
Whether the optional dependency this motif needs is installed. |
available
property
¶
Whether the optional dependency this motif needs is installed.
A motif registered with requires= can be listed, described and
documented on a machine that lacks its dependency -- only building
one raises. This is what lets a listing say so instead of failing to
import, and what the conformance suite checks before it tries.
register
¶
register(name: str | None = None, *, family: str | None = None, requires: str | None = None, example: Mapping[str, object] | None = None) -> Callable[[type[MotifT]], type[MotifT]]
Register a motif class under name, returning it unchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Registry key. Derived from the class name in kebab-case when
omitted, so |
None
|
family
|
str
|
Grouping for |
None
|
requires
|
str
|
Name of an optional dependency the motif needs, e.g. |
None
|
example
|
mapping
|
Constructor arguments producing a representative instance -- what the gallery renders and what the conformance suite exercises. Required for motifs with parameters that have no default, since those cannot be instantiated any other way. |
None
|
Examples:
::
@register("rose", family="polar", example={"k": 5})
@dataclass(frozen=True, slots=True)
class Rose(PolarMotif): ...
Source code in src/geomotif/core/registry.py
names
¶
Return every registered motif name, sorted; optionally one family only.
Source code in src/geomotif/core/registry.py
families
¶
Return every family name that has at least one motif, sorted.
get
¶
get(name: str) -> type[Motif]
Return the motif class registered under name.
Raises:
| Type | Description |
|---|---|
KeyError
|
If no such motif is registered. The message lists near misses, since a typo is far more likely than a genuinely missing motif. |
Source code in src/geomotif/core/registry.py
create
¶
create(name: str, /, **params: object) -> Motif
Instantiate the motif registered under name with params.
Source code in src/geomotif/core/registry.py
describe
¶
describe(name: str) -> MotifInfo
Return a motif's documentation and parameter list without building it.
Parameters come from :func:dataclasses.fields, which is why every
builtin motif is a dataclass: one declaration drives the CLI flags, the
docs, the gallery and spec round-tripping. They are listed motif-first --
a motif's own parameters, then the ones it inherits -- which is the
opposite of the order __init__ needs and the right one to read.
Source code in src/geomotif/core/registry.py
name_for
¶
Return the name cls is registered under, or None if it is not.
Unlike the other lookups this one does not trigger a load: if an instance of the class exists, its module has already been imported, so anything the load would find is either present already or irrelevant.
Source code in src/geomotif/core/registry.py
spec
¶
spec(motif: SupportsBuild) -> Mapping[str, object]
Return a reproducible description of motif, for :attr:Design.meta.
The result is the motif's registered name under "motif" plus every
constructor parameter and its resolved value -- including any resolved
random seed -- which is exactly what is needed to rebuild the design
later via :func:create.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
motif
|
Motif or any object with ``build()``
|
The motif to describe. Usually a dataclass; anything else reports just its name, since there is nothing to introspect. |
required |
Returns:
| Type | Description |
|---|---|
Mapping[str, object]
|
Read-only, so it is safe to hand straight to :class: |