Skip to content

nrcatalogtools.registry

Lightweight catalog plugin registry.

Catalogs register themselves with @register_catalog("TAG") and are looked up with get_catalog("TAG"). The built-in catalogs (RIT, SXS, MAYA) are registered automatically at import time.


register_catalog

register_catalog(tag: str) -> Callable[[Type], Type]

Class decorator that registers a catalog under tag.

Parameters:

Name Type Description Default
tag str

Short uppercase identifier (e.g. "RIT"). Must be unique within the registry.

required

Returns:

Type Description
callable

A class decorator; the class itself is returned unchanged so the decorator can be stacked with other decorators.

Raises:

Type Description
ValueError

If tag is already registered, to prevent silent overwrites.

Examples:

>>> @register_catalog("LVCNR")
... class LVCNRCatalog(CatalogBase):
...     CATALOG_TYPE = "LVCNR"
Source code in nrcatalogtools/registry.py
def register_catalog(tag: str) -> Callable[[Type], Type]:
    """Class decorator that registers a catalog under *tag*.

    Parameters
    ----------
    tag : str
        Short uppercase identifier (e.g. ``"RIT"``).  Must be unique
        within the registry.

    Returns
    -------
    callable
        A class decorator; the class itself is returned unchanged so the
        decorator can be stacked with other decorators.

    Raises
    ------
    ValueError
        If *tag* is already registered, to prevent silent overwrites.

    Examples
    --------
    >>> @register_catalog("LVCNR")
    ... class LVCNRCatalog(CatalogBase):
    ...     CATALOG_TYPE = "LVCNR"
    """

    def decorator(cls):
        if tag in _REGISTRY and _REGISTRY[tag].__name__ != cls.__name__:
            raise ValueError(
                f"Catalog tag '{tag}' is already registered "
                f"(by {_REGISTRY[tag].__qualname__}). "
                "Use a different tag or unregister the existing entry first."
            )
        _REGISTRY[tag] = cls
        return cls

    return decorator

get_catalog

get_catalog(tag: str) -> Type

Return the catalog class registered under tag.

Parameters:

Name Type Description Default
tag str

Short uppercase identifier (e.g. "RIT").

required

Returns:

Type Description
type

The registered catalog class.

Raises:

Type Description
KeyError

If tag is not in the registry.

Examples:

>>> cls = get_catalog("SXS")
>>> catalog = cls.load()
Source code in nrcatalogtools/registry.py
def get_catalog(tag: str) -> Type:
    """Return the catalog class registered under *tag*.

    Parameters
    ----------
    tag : str
        Short uppercase identifier (e.g. ``"RIT"``).

    Returns
    -------
    type
        The registered catalog class.

    Raises
    ------
    KeyError
        If *tag* is not in the registry.

    Examples
    --------
    >>> cls = get_catalog("SXS")
    >>> catalog = cls.load()
    """
    if tag not in _REGISTRY:
        known = ", ".join(sorted(_REGISTRY)) or "(none)"
        raise KeyError(
            f"No catalog registered under tag '{tag}'. " f"Known tags: {known}."
        )
    return _REGISTRY[tag]

list_catalogs

list_catalogs() -> set

Return the set of all registered catalog tags.

Returns:

Type Description
set[str]

Copy of the current tag set; modifying it has no effect on the registry.

Examples:

>>> list_catalogs()
{'MAYA', 'RIT', 'SXS'}
Source code in nrcatalogtools/registry.py
def list_catalogs() -> set:
    """Return the set of all registered catalog tags.

    Returns
    -------
    set[str]
        Copy of the current tag set; modifying it has no effect on the registry.

    Examples
    --------
    >>> list_catalogs()
    {'MAYA', 'RIT', 'SXS'}
    """
    return set(_REGISTRY)