flambe.compile.registrable
¶
Module Contents¶
-
exception
flambe.compile.registrable.
RegistrationError
[source]¶ Bases:
Exception
Error thrown when acessing yaml tag on a non-registered class
Thrown when trying to access the default yaml tag for a class typically occurs when called on an abstract class
-
flambe.compile.registrable.
make_from_yaml_with_metadata
(from_yaml_fn: Callable[..., Any], tag: str, factory_name: Optional[str] = None) → Callable[..., Any][source]¶
-
flambe.compile.registrable.
make_to_yaml_with_metadata
(to_yaml_fn: Callable[..., Any]) → Callable[..., Any][source]¶
-
class
flambe.compile.registrable.
Registrable
[source]¶ Bases:
abc.ABC
Subclasses automatically registered as yaml tags
Automatically registers subclasses with the yaml loader by adding a constructor and representer which can be overridden
-
classmethod
__init_subclass__
(cls: Type[R], should_register: Optional[bool] = True, tag_override: Optional[str] = None, tag_namespace: Optional[str] = None, **kwargs: Mapping[str, Any])[source]¶
-
static
get_default_tag
(class_: RT, factory_name: Optional[str] = None)[source]¶ Retrieve default yaml tag for class cls
Retrieve the default tag (aka the last one, which will be the only one, or the alias if it exists) for use in yaml representation
-
classmethod
-
flambe.compile.registrable.
alias
(tag: str, tag_namespace: Optional[str] = None) → Callable[[RT], RT][source]¶ Decorate a Registrable subclass with a new tag
Can be added multiple times to give a class multiple aliases, however the top most alias tag will be the default tag which means it will be used when representing the class in YAML
-
flambe.compile.registrable.
register
(cls: Type[A], tag: str) → Type[A][source]¶ Safely register a new tag for a class
Similar to alias, but it’s intended to be used on classes that are not already subclasses of Registrable, and it is NOT a decorator
-
class
flambe.compile.registrable.
registrable_factory
(fn: Any)[source]¶ Decorate Registrable factory method for use in the config
This Descriptor class will set properties that allow the factory method to be specified directly in the config as a suffix to the tag; for example:
class MyModel(Component): @registrable_factory def from_file(cls, path): # load instance from path ... return instance
defines the factory, which can then be used in yaml:
model: !MyModel.from_file path: some/path/to/file.pt
-
class
flambe.compile.registrable.
MappedRegistrable
[source]¶