Skip to content

Commit

Permalink
Remove _multi_child... and create_many_to_many_relationship() sin…
Browse files Browse the repository at this point in the history
…ce Neo no longer has any such relationships
  • Loading branch information
apdavison committed May 2, 2023
1 parent 95420ee commit 1f84881
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 93 deletions.
12 changes: 0 additions & 12 deletions doc/source/images/generate_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def get_rect_height(name, obj):
nlines = 1.5
nlines += len(getattr(obj, '_all_attrs', []))
nlines += len(getattr(obj, '_single_child_objects', []))
nlines += len(getattr(obj, '_multi_child_objects', []))
return nlines * line_heigth


Expand Down Expand Up @@ -75,7 +74,6 @@ def generate_diagram(rect_pos, rect_width, figsize):
for name, pos in rect_pos.items():
obj = objs[name]
relationships = [getattr(obj, '_single_child_objects', []),
getattr(obj, '_multi_child_objects', []),
getattr(obj, '_child_properties', [])]

for r in range(3):
Expand Down Expand Up @@ -122,16 +120,6 @@ def generate_diagram(rect_pos, rect_width, figsize):
facecolor='c', edgecolor='k', alpha=.5)
ax.add_patch(rect)

# multi relationship
relationship = list(getattr(obj, '_multi_child_objects', []))
pos2 = (pos[1] + htotal - line_heigth * (1.5 + len(relationship))
- rect_height)
rect_height = len(relationship) * line_heigth

rect = Rectangle((pos[0], pos2), rect_width, rect_height,
facecolor='m', edgecolor='k', alpha=.5)
ax.add_patch(rect)

# necessary attr
pos2 = (pos[1] + htotal
- line_heigth * (1.5 + len(allrelationship) + len(obj._necessary_attrs)))
Expand Down
84 changes: 7 additions & 77 deletions neo/core/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,6 @@ class Container(BaseNeo):
class.__name__.lower()+'s' will be automatically
defined to hold this child and will be
initialized to an empty list.
:_multi_child_objects: Neo container objects that can be children
of this object. This attribute is used in
cases where the child can have multiple
parents of this type. An instance attribute
named class.__name__.lower()+'s' will be
automatically defined to hold this child and
will be initialized to an empty list.
:_child_properties: Properties that return sub-children of a particular
type. These properties must still be defined.
This is mostly used for generate_diagram.
Expand All @@ -134,25 +127,17 @@ class Container(BaseNeo):
have one parent of this type.
:_container_child_objects: +
:_data_child_objects:
:_child_objects: All child objects.
:_single_child_objects: + :_multi_child_objects:
:_child_objects: All child objects. Same as :_single_child_objects:
:_container_child_containers: The names of the container attributes
used to store :_container_child_objects:
:_data_child_containers: The names of the container attributes used
to store :_data_child_objects:
:_single_child_containers: The names of the container attributes used
to store :_single_child_objects:
:_multi_child_containers: The names of the container attributes used
to store :_multi_child_objects:
:_child_containers: All child container attributes.
:_single_child_containers: +
:_multi_child_containers:
:_child_containers: All child container attributes. Same as :_single_child_containers:
:_single_children: All objects that are children of the current object
where the child can only have one parent of
this type.
:_multi_children: All objects that are children of the current object
where the child can have multiple parents of
this type.
:data_children: All data objects that are children of
the current object.
:container_children: All container objects that are children of
Expand Down Expand Up @@ -186,15 +171,7 @@ class Container(BaseNeo):
single parent, set its parent
to be the current object.
:create_many_to_many_relationship(**args): For children of the current
object that can have more
than one parent of this
type, put the current
object in the parent list.
:create_relationship(**args): Combines
:create_many_to_one_relationship: and
:create_many_to_many_relationship:
:create_relationship(**args): Same as :create_many_to_one_relationship:
:merge(**args): Annotations are merged based on the rules of
:merge_annotations:. Child objects with the same name
Expand All @@ -218,8 +195,6 @@ class Container(BaseNeo):
_container_child_objects = ()
# Child objects that have data and have a single parent
_data_child_objects = ()
# Child objects that can have multiple parents
_multi_child_objects = ()
# Properties returning children of children [of children...]
_child_properties = ()
# Containers that are listed when pretty-printing
Expand Down Expand Up @@ -265,27 +240,19 @@ def _single_child_containers(self):
return tuple([_container_name(child) for child in
self._single_child_objects])

@property
def _multi_child_containers(self):
"""
Containers for child objects that can have multiple parents.
"""
return tuple([_container_name(child) for child in
self._multi_child_objects])

@property
def _child_objects(self):
"""
All types for child objects.
"""
return self._single_child_objects + self._multi_child_objects
return self._single_child_objects

@property
def _child_containers(self):
"""
All containers for child objects.
"""
return self._single_child_containers + self._multi_child_containers
return self._single_child_containers

@property
def _single_children(self):
Expand All @@ -296,15 +263,6 @@ def _single_children(self):
self._single_child_containers]
return tuple(sum(childs, []))

@property
def _multi_children(self):
"""
All child objects that can have multiple parents.
"""
childs = [list(getattr(self, attr)) for attr in
self._multi_child_containers]
return tuple(sum(childs, []))

@property
def data_children(self):
"""
Expand All @@ -322,8 +280,7 @@ def container_children(self):
Not recursive.
"""
childs = [list(getattr(self, attr)) for attr in
self._container_child_containers +
self._multi_child_containers]
self._container_child_containers]
return tuple(sum(childs, []))

@property
Expand Down Expand Up @@ -475,31 +432,6 @@ def create_many_to_one_relationship(self, force=False, recursive=True):
child.create_many_to_one_relationship(force=force,
recursive=True)

def create_many_to_many_relationship(self, append=True, recursive=True):
"""
For children of the current object that can have more than one parent
of this type, put the current object in the parent list.
If append is True add it to the list, otherwise overwrite the list.
If recursive is True descend into child objects and create
relationships there
"""
parent_name = _container_name(self.__class__.__name__)
for child in self._multi_children:
if not hasattr(child, parent_name):
continue
if append:
target = getattr(child, parent_name)
if self not in target:
target.append(self)
continue
setattr(child, parent_name, [self])

if recursive:
for child in self.container_children:
child.create_many_to_many_relationship(append=append,
recursive=True)

def create_relationship(self, force=False, append=True, recursive=True):
"""
For each child of the current object that can only have a single
Expand All @@ -517,7 +449,6 @@ def create_relationship(self, force=False, append=True, recursive=True):
relationships there
"""
self.create_many_to_one_relationship(force=force, recursive=False)
self.create_many_to_many_relationship(append=append, recursive=False)
if recursive:
for child in self.container_children:
child.create_relationship(force=force, append=append,
Expand Down Expand Up @@ -565,8 +496,7 @@ def merge(self, other):
after the merge operation and should not be used further.
"""
# merge containers with the same name
for container in (self._container_child_containers +
self._multi_child_containers):
for container in self._container_child_containers:
lookup = {obj.name: obj for obj in getattr(self, container)}
ids = [id(obj) for obj in getattr(self, container)]
for obj in getattr(other, container):
Expand Down
4 changes: 0 additions & 4 deletions neo/test/coretest/test_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ def test__children(self):

self.assertEqual(container._container_child_objects, ())
self.assertEqual(container._data_child_objects, ())
self.assertEqual(container._multi_child_objects, ())
self.assertEqual(container._child_properties, ())

self.assertEqual(container._repr_pretty_containers, ())
Expand All @@ -66,12 +65,10 @@ def test__children(self):
self.assertEqual(container._container_child_containers, ())
self.assertEqual(container._data_child_containers, ())
self.assertEqual(container._single_child_containers, ())
self.assertEqual(container._multi_child_containers, ())

self.assertEqual(container._child_objects, ())
self.assertEqual(container._child_containers, ())

self.assertEqual(container._multi_children, ())
self.assertEqual(container._single_children, ())
self.assertEqual(container.data_children, ())
self.assertEqual(container.container_children, ())
Expand All @@ -95,7 +92,6 @@ def test__children(self):
self.assertEqual(container.size, {})

container.create_many_to_one_relationship()
container.create_many_to_many_relationship()
container.create_relationship()

def test_filter(self):
Expand Down

0 comments on commit 1f84881

Please sign in to comment.