hdmf.build.manager module¶
- class hdmf.build.manager.Proxy(manager, source, location, namespace, data_type)¶
Bases:
object
A temporary object to represent a Container. This gets used when resolving the true location of a Container’s parent. Proxy objects allow simple bookkeeping of all potential parents a Container may have. This object is used by providing all the necessary information for describing the object. This object gets passed around and candidates are accumulated. Upon calling resolve, all saved candidates are matched against the information (provided to the constructor). The candidate that has an exact match is returned.
- property source¶
The source of the object e.g. file source
- property location¶
The location of the object. This can be thought of as a unique path
- property namespace¶
The namespace from which the data_type of this Proxy came from
- property data_type¶
The data_type of Container that should match this Proxy
- matches(object)¶
- Parameters:
object (
BaseBuilder
orContainer
) – the container or builder to get a proxy for
- add_candidate(container)¶
- Parameters:
container (
Container
) – the Container to add as a candidate match
- resolve()¶
- class hdmf.build.manager.BuildManager(type_map)¶
Bases:
object
A class for managing builds of AbstractContainers
- property namespace_catalog¶
- property type_map¶
- get_proxy(object, source=None)¶
- Parameters:
object (
BaseBuilder
orAbstractContainer
) – the container or builder to get a proxy forsource (
str
) – the source of container being built i.e. file path
- build(container, source=None, spec_ext=None, export=False, root=False)¶
Build the GroupBuilder/DatasetBuilder for the given AbstractContainer
- Parameters:
container (
AbstractContainer
) – the container to convert to a Buildersource (
str
) – the source of container being built i.e. file pathspec_ext (
BaseStorageSpec
) – a spec that further refines the base specificationexport (
bool
) – whether this build is for exportingroot (
bool
) – whether the container is the root of the build process
- prebuilt(container, builder)¶
Save the Builder for a given AbstractContainer for future use
- Parameters:
container (
AbstractContainer
) – the AbstractContainer to save as prebuiltbuilder (
DatasetBuilder
orGroupBuilder
) – the Builder representation of the given container
- queue_ref(func)¶
Set aside creating ReferenceBuilders
- purge_outdated()¶
- clear_cache()¶
- get_builder(container)¶
Return the prebuilt builder for the given container or None if it does not exist.
- Parameters:
container (
AbstractContainer
) – the container to get the builder for
- construct(builder)¶
Construct the AbstractContainer represented by the given builder
- Parameters:
builder (
DatasetBuilder
orGroupBuilder
) – the builder to construct the AbstractContainer from
- get_cls(builder)¶
Get the class object for the given Builder
- Parameters:
builder (
Builder
) – the Builder to get the class object for
- get_builder_name(container)¶
Get the name a Builder should be given
- Parameters:
container (
AbstractContainer
) – the container to convert to a Builder- Returns:
The name a Builder should be given when building this container
- Return type:
- get_subspec(spec, builder)¶
Get the specification from this spec that corresponds to the given builder
- Parameters:
spec (
DatasetSpec
orGroupSpec
) – the parent spec to searchbuilder (
DatasetBuilder
orGroupBuilder
orLinkBuilder
) – the builder to get the sub-specification for
- get_builder_ns(builder)¶
Get the namespace of a builder
- Parameters:
builder (
DatasetBuilder
orGroupBuilder
orLinkBuilder
) – the builder to get the sub-specification for
- get_builder_dt(builder)¶
Get the data_type of a builder
- Parameters:
builder (
DatasetBuilder
orGroupBuilder
orLinkBuilder
) – the builder to get the data_type for
- is_sub_data_type(builder, parent_data_type)¶
Return whether or not data_type of builder is a sub-data_type of parent_data_type
- Parameters:
builder (
GroupBuilder
orDatasetBuilder
orAbstractContainer
) – the builder or container to checkparent_data_type (
str
) – the potential parent data_type that refers to a data_type
- Returns:
True if data_type of builder is a sub-data_type of parent_data_type, False otherwise
- Return type:
- class hdmf.build.manager.TypeSource(namespace, data_type)¶
Bases:
object
A class to indicate the source of a data_type in a namespace. This class should only be used by TypeMap
- Parameters:
- property namespace¶
- property data_type¶
- class hdmf.build.manager.TypeMap(namespaces=None, mapper_cls=None, type_config=None)¶
Bases:
object
A class to maintain the map between ObjectMappers and AbstractContainer classes
- Parameters:
namespaces (
NamespaceCatalog
) – the NamespaceCatalog to usemapper_cls (
type
) – the ObjectMapper class to usetype_config (
TypeConfigurator
) – The TypeConfigurator to use.
- property namespace_catalog¶
- property container_types¶
- copy_mappers(type_map)¶
- merge(type_map, ns_catalog=False)¶
- register_generator(generator)¶
Add a custom class generator.
- Parameters:
generator (
type
) – the CustomClassGenerator class to register
- load_namespaces(namespace_path, resolve=True, reader=None)¶
- Load namespaces from a namespace file.
This method will call load_namespaces on the NamespaceCatalog used to construct this TypeMap. Additionally, it will process the return value to keep track of what types were included in the loaded namespaces. Calling load_namespaces here has the advantage of being able to keep track of type dependencies across namespaces.
- Parameters:
namespace_path (
str
) – the path to the file containing the namespaces(s) to loadresolve (
bool
) – whether or not to include objects from included/parent spec objectsreader (
SpecReader
) – the class to user for reading specifications
- Returns:
the namespaces loaded from the given file
- Return type:
- get_container_cls(namespace, data_type, autogen=True)¶
- Get the container class from data type specification.
If no class has been associated with the
data_type
fromnamespace
, a class will be dynamically created and returned.
- get_dt_container_cls(data_type, namespace=None, post_init_method=None, autogen=True)¶
- Get the container class from data type specification.
If no class has been associated with the
data_type
fromnamespace
, a class will be dynamically created and returned.Replaces get_container_cls but namespace is optional. If namespace is unknown, it will be looked up from all namespaces.
- Parameters:
- Returns:
the class for the given namespace and data_type
- Return type:
- get_builder_dt(builder)¶
Get the data_type of a builder
- Parameters:
builder (
DatasetBuilder
orGroupBuilder
orLinkBuilder
) – the builder to get the data_type for
- get_builder_ns(builder)¶
Get the namespace of a builder
- Parameters:
builder (
DatasetBuilder
orGroupBuilder
orLinkBuilder
) – the builder to get the sub-specification for
- get_cls(builder)¶
Get the class object for the given Builder
- Parameters:
builder (
Builder
) – the Builder object to get the corresponding AbstractContainer class for
- get_subspec(spec, builder)¶
Get the specification from this spec that corresponds to the given builder
- Parameters:
spec (
DatasetSpec
orGroupSpec
) – the parent spec to searchbuilder (
DatasetBuilder
orGroupBuilder
orLinkBuilder
) – the builder to get the sub-specification for
- get_container_ns_dt(obj)¶
- get_container_cls_dt(cls)¶
- get_container_classes(namespace=None)¶
- Parameters:
namespace (
str
) – the namespace to get the container classes for
- get_map(obj)¶
Return the ObjectMapper object that should be used for the given container
- Parameters:
obj (
AbstractContainer
orBuilder
) – the object to get the ObjectMapper for- Returns:
the ObjectMapper to use for mapping the given object
- Return type:
ObjectMapper
- register_container_type(namespace, data_type, container_cls)¶
Map a container class to a data_type
- Parameters:
namespace (
str
) – the namespace containing the data_type to map the class todata_type (
str
) – the data_type to map the class tocontainer_cls (
TypeSource
ortype
) – the class to map to the specified data_type
- register_map(container_cls, mapper_cls)¶
Map a container class to an ObjectMapper class
- build(container, manager=None, source=None, builder=None, spec_ext=None, export=False)¶
Build the GroupBuilder/DatasetBuilder for the given AbstractContainer
- Parameters:
container (
AbstractContainer
) – the container to convert to a Buildermanager (
BuildManager
) – the BuildManager to use for managing this buildsource (
str
) – the source of container being built i.e. file pathbuilder (
BaseBuilder
) – the Builder to build onspec_ext (
BaseStorageSpec
) – a spec extensionexport (
bool
) – whether this build is for exporting
- construct(builder, build_manager=None, parent=None)¶
Construct the AbstractContainer represented by the given builder
- Parameters:
builder (
DatasetBuilder
orGroupBuilder
) – the builder to construct the AbstractContainer frombuild_manager (
BuildManager
) – the BuildManager for constructingparent (
Proxy
orContainer
) – the parent Container/Proxy for the Container being built
- get_builder_name(container)¶
Get the name a Builder should be given
- Parameters:
container (
AbstractContainer
) – the container to convert to a Builder- Returns:
The name a Builder should be given when building this container
- Return type: