ExtensionRegistry

class hugr.ext.ExtensionRegistry(extensions: dict[ExtensionId, Extension] = <factory>)[source]

Bases: object

Registry of extensions.

Methods

add_extension

Add an extension to the registry.

extend

Add a registry of extensions to this registry.

from_extensions

Create an extension registry from a list of extensions.

get_extension

Retrieve an extension by name.

ids

Get the set of extension IDs in the registry.

register_updated

Add or update an extension in the registry.

Attributes

extensions

Extensions in the registry, indexed by name.

exception ExtensionExists(extension_id: ExtensionId)[source]

Bases: Exception

Extension already exists in registry.

add_note(note, /)

Add a note to the exception

with_traceback(tb, /)

Set self.__traceback__ to tb and return self.

exception ExtensionNotFound(extension_id: ExtensionId)[source]

Bases: Exception

Extension not found in registry.

add_note(note, /)

Add a note to the exception

with_traceback(tb, /)

Set self.__traceback__ to tb and return self.

add_extension(extension: Extension) Extension[source]

Add an extension to the registry.

Parameters:

extension – The extension to add.

Returns:

The added extension.

Raises:

ExtensionExists – If an extension with the same name already exists.

extend(other: ExtensionRegistry) None[source]

Add a registry of extensions to this registry.

If an extension with the same name already exists, the one with the higher version is kept.

Parameters:

other – The extension registry to add.

extensions: dict[ExtensionId, Extension]

Extensions in the registry, indexed by name.

classmethod from_extensions(extensions: Iterable[Extension]) ExtensionRegistry[source]

Create an extension registry from a list of extensions.

get_extension(name: ExtensionId) Extension[source]

Retrieve an extension by name.

Parameters:

name – The name of the extension.

Returns:

Extension in the registry.

Raises:

ExtensionNotFound – If the extension is not found in the registry.

ids() set[ExtensionId][source]

Get the set of extension IDs in the registry.

Returns:

Set of extension IDs.

register_updated(extension: Extension) None[source]

Add or update an extension in the registry.

If an extension with the same name already exists, keeps the one with the higher version.

Parameters:

extension – The extension to add or update.