-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
do not autogenerate classes when loading namespace #555
Conversation
Looks good, though one test is failing. IIRC that test was the following: I think I figured out the core issue.
def get_container_cls(self, **kwargs):
"""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.
"""
namespace, data_type, autogen = getargs('namespace', 'data_type', 'autogen', kwargs)
cls = self.__get_container_cls(namespace, data_type)
if cls is None and autogen: # dynamically generate a class
spec = self.__ns_catalog.get_spec(namespace, data_type)
self.__resolve_dependent_container_classes(spec, namespace)
parent_cls = self.__get_parent_cls(namespace, data_type, spec)
attr_names = self.__default_mapper_cls.get_attr_names(spec)
cls = self.__class_generator.generate_class(data_type, spec, parent_cls, attr_names, self)
self.register_container_type(namespace, data_type, cls)
return cls
def __resolve_dependent_container_classes(self, spec, namespace):
"""Trigger class generation and registration for dependent data types."""
if spec.data_type_inc is not None:
self.get_container_cls(namespace, spec.data_type_inc)
if isinstance(spec, GroupSpec):
for child_spec in (spec.groups + spec.datasets):
if child_spec.data_type_inc is not None:
self.get_container_cls(namespace, child_spec.data_type_inc)
elif child_spec.data_type_def is not None:
self.get_container_cls(namespace, child_spec.data_type_def)
for child_spec in spec.links:
if child_spec.target_type is not None:
self.get_container_cls(namespace, child_spec.target_type)
So the test can be modified to generate classes all from the ndx-test namespace baz_cls = self.type_map.get_container_cls('ndx-test', 'Baz')
bar_cls = self.type_map.get_container_cls('ndx-test', 'Bar')
qux_cls = self.type_map.get_container_cls('ndx-test', 'Qux') This cross-namespace strategy might not work fully though. Type B inherits from type A built with namespace N2 I'm not sure what the solution to this is yet, but this situation is pretty rare. It has happened already with the Allen Institute so we should test that before releasing this (but we can merge this). |
This change will fix #554 as well. |
Never mind my comments above. I just realized the purpose of TypeSource and made a proposed change in #557 to fix the failing test. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. I'm wondering whether this will also help speed-up importing HDMF.
* Check dependent types, gen classes for them, and link them * Add comment * Update src/hdmf/build/manager.py Co-authored-by: Andrew Tritt <[email protected]>
Motivation
Fix #553
How to test the behavior?
Set breakpoints or print statements deep in TypeMap.get_container_cls.
Checklist
flake8
from the source directory.