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 or Container) – 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 or AbstractContainer) – the container or builder to get a proxy for
  • source (str) – the source of container being built i.e. file path
build(container, source=None, spec_ext=None, export=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
prebuilt(container, builder)

Save the Builder for a given AbstractContainer for future use

Parameters:
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 or GroupBuilder) – 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:str
get_subspec(spec, builder)

Get the specification from this spec that corresponds to the given builder

Parameters:
get_builder_ns(builder)

Get the namespace of a builder

Parameters:builder (DatasetBuilder or GroupBuilder or LinkBuilder) – the builder to get the sub-specification for
get_builder_dt(builder)

Get the data_type of a builder

Parameters:builder (DatasetBuilder or GroupBuilder or LinkBuilder) – the builder to get the data_type for
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 (str) – the namespace the from, which the data_type originated
  • data_type (str) – the name of the type
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
copy_mappers(type_map)
merge(type_map, ns_catalog=False)
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:

dict

get_container_cls(namespace, data_type)
Get the container class from data type specification
If no class has been associated with the data_type from namespace, a class will be dynamically created and returned.
Parameters:
  • namespace (str) – the namespace containing the data_type
  • data_type (str) – the data type to create a AbstractContainer class for
Returns:

the class for the given namespace and data_type

Return type:

type

get_builder_dt(builder)

Get the data_type of a builder

Parameters:builder (DatasetBuilder or GroupBuilder or LinkBuilder) – the builder to get the data_type for
get_builder_ns(builder)

Get the namespace of a builder

Parameters:builder (DatasetBuilder or GroupBuilder or LinkBuilder) – 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:
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 or Builder) – 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 to
  • data_type (str) – the data_type to map the class to
  • container_cls (TypeSource or type) – the class to map to the specified data_type
register_map(container_cls, mapper_cls)

Map a container class to an ObjectMapper class

Parameters:
  • container_cls (type) – the AbstractContainer class for which the given ObjectMapper class gets used for
  • mapper_cls (type) – the ObjectMapper class to use to map
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
construct(builder, build_manager=None, parent=None)

Construct the AbstractContainer represented by the given builder

Parameters:
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:str
exception hdmf.build.manager.TypeDoesNotExistError

Bases: Exception