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.
-
source
¶ The source of the object e.g. file source
-
location
¶ The location of the object. This can be thought of as a unique path
-
namespace
¶ The namespace from which the data_type of this Proxy came from
-
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
-
namespace_catalog
¶
-
type_map
¶
-
get_proxy
(object, source=None)¶ Parameters: - object (
BaseBuilder
orAbstractContainer
) – the container or builder to get a proxy for - source (
str
) – the source of container being built i.e. file path
- object (
-
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 Builder - source (
str
) – the source of container being built i.e. file path - spec_ext (
BaseStorageSpec
) – a spec that further refines the base specification - export (
bool
) – whether this build is for exporting - root (
bool
) – whether the container is the root of the build process
- container (
-
prebuilt
(container, builder)¶ Save the Builder for a given AbstractContainer for future use
Parameters: - container (
AbstractContainer
) – the AbstractContainer to save as prebuilt - builder (
DatasetBuilder
orGroupBuilder
) – the Builder representation of the given container
- container (
-
queue_ref
(func)¶ Set aside creating ReferenceBuilders
-
purge_outdated
()¶
-
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 BuilderReturns: The name a Builder should be given when building this container Return type: str
-
get_subspec
(spec, builder)¶ Get the specification from this spec that corresponds to the given builder
Parameters: - spec (
DatasetSpec
orGroupSpec
) – the parent spec to search - builder (
DatasetBuilder
orGroupBuilder
orLinkBuilder
) – the builder to get the sub-specification for
- spec (
-
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 check - parent_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: - builder (
-
-
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: -
namespace
¶
-
data_type
¶
-
-
class
hdmf.build.manager.
TypeMap
(namespaces=None, mapper_cls=None)¶ Bases:
object
A class to maintain the map between ObjectMappers and AbstractContainer classes
Parameters: - namespaces (
NamespaceCatalog
) – the NamespaceCatalog to use - mapper_cls (
type
) – the ObjectMapper class to use
-
namespace_catalog
¶
-
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 load - resolve (
bool
) – whether or not to include objects from included/parent spec objects - reader (
SpecReader
) – the class to user for reading specifications
Returns: the namespaces loaded from the given file
Return type:
-
get_container_cls
(data_type, namespace=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.
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 search - builder (
DatasetBuilder
orGroupBuilder
orLinkBuilder
) – the builder to get the sub-specification for
- spec (
-
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 forReturns: 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 to - data_type (
str
) – the data_type to map the class to - container_cls (
TypeSource
ortype
) – the class to map to the specified data_type
- namespace (
-
register_map
(container_cls, mapper_cls)¶ Map a container class to an ObjectMapper class
Parameters:
-
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 Builder - manager (
BuildManager
) – the BuildManager to use for managing this build - source (
str
) – the source of container being built i.e. file path - builder (
BaseBuilder
) – the Builder to build on - spec_ext (
BaseStorageSpec
) – a spec extension - export (
bool
) – whether this build is for exporting
- container (
-
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 from - build_manager (
BuildManager
) – the BuildManager for constructing - parent (
Proxy
orContainer
) – the parent Container/Proxy for the Container being built
- builder (
-
get_builder_name
(container)¶ Get the name a Builder should be given
Parameters: container ( AbstractContainer
) – the container to convert to a BuilderReturns: The name a Builder should be given when building this container Return type: str
- namespaces (