Skip to content

Commit 0d5a75a

Browse files
committed
remove random attributes dict everywhere + add name to data object
1 parent 5aa5559 commit 0d5a75a

File tree

14 files changed

+58
-3309
lines changed

14 files changed

+58
-3309
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111

1212
* Added `compas.dtastructures.Network` as alias of `compas.datastructures.Graph`.
13+
* Added `compas.data.Data.name` and included it in serialisation in case `compas.data.Data._name is not None`.
1314

1415
### Changed
1516

@@ -22,6 +23,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2223
* Removed `compas.datastructures.Network`.
2324
* Removed `compas.datastructures.Halfedge`.
2425
* Removed `compas.datastructures.Halfface`.
26+
* Removed `compas.data.Data.attributes`.
27+
* Removed `compas.data.Datastructure.attributes`.
28+
* Removed `attributes` from `compas.datastructures.Assembly.data`.
29+
* Removed `attributes` from `compas.datastructures.CellNetwork.data`.
30+
* Removed `attributes` from `compas.datastructures.Graph.data`.
31+
* Removed `attributes` from `compas.datastructures.Mesh.data`.
32+
* Removed `attributes` from `compas.datastructures.Tree.data`.
33+
* Removed `attributes` from `compas.datastructures.VolMesh.data`.
2534

2635
## [2.0.0-beta.2] 2024-01-12
2736

src/compas/data/data.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,6 @@ class Data(object):
3939
4040
Attributes
4141
----------
42-
dtype : str, read-only
43-
The type of the object in the form of a fully qualified module name and a class name, separated by a forward slash ("/").
44-
For example: ``"compas.datastructures/Mesh"``.
45-
data : dict
46-
The representation of the object as a dictionary containing only built-in Python data types.
47-
The structure of the dict is described by the data schema.
4842
guid : str, read-only
4943
The globally unique identifier of the object.
5044
The guid is generated with ``uuid.uuid4()``.
@@ -97,7 +91,8 @@ def __jsondump__(self, minimal=False):
9791
}
9892
if minimal:
9993
return state
100-
state["name"] = self.name
94+
if self._name is not None:
95+
state["name"] = self._name
10196
state["guid"] = str(self.guid)
10297
return state
10398

src/compas/data/encoders.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,6 @@ def object_hook(self, o):
237237
if IDictionary and isinstance(o, IDictionary[str, object]):
238238
data = {key: data[key] for key in data.Keys}
239239

240-
obj = cls.__jsonload__(data, guid, name)
240+
obj = cls.__jsonload__(data, guid=guid, name=name)
241241

242242
return obj

src/compas/datastructures/assembly/assembly.py

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ class Assembly(Datastructure):
1717
1818
Attributes
1919
----------
20-
attributes : dict[str, Any]
21-
General attributes of the data structure that will be included in the data dict and serialization.
2220
graph : :class:`compas.datastructures.Graph`
2321
The graph that is used under the hood to store the parts and their connections.
2422
@@ -33,16 +31,13 @@ class Assembly(Datastructure):
3331
DATASCHEMA = {
3432
"type": "object",
3533
"properties": {
36-
"attributes": {"type": "object"},
3734
"graph": Graph.DATASCHEMA,
3835
},
3936
"required": ["graph"],
4037
}
4138

42-
def __init__(self, name=None, **kwargs):
43-
super(Assembly, self).__init__()
44-
self.attributes = {"name": name or "Assembly"}
45-
self.attributes.update(kwargs)
39+
def __init__(self, name=None):
40+
super(Assembly, self).__init__(name=name)
4641
self.graph = Graph()
4742
self._parts = {}
4843

@@ -57,30 +52,16 @@ def __str__(self):
5752
@property
5853
def data(self):
5954
return {
60-
"attributes": self.attributes,
6155
"graph": self.graph.data,
6256
}
6357

6458
@classmethod
6559
def from_data(cls, data):
6660
assembly = cls()
67-
assembly.attributes.update(data["attributes"] or {})
6861
assembly.graph = Graph.from_data(data["graph"])
6962
assembly._parts = {part.guid: part.key for part in assembly.parts()} # type: ignore
7063
return assembly
7164

72-
# ==========================================================================
73-
# Properties
74-
# ==========================================================================
75-
76-
@property
77-
def name(self):
78-
return self.attributes.get("name") or self.__class__.__name__
79-
80-
@name.setter
81-
def name(self, value):
82-
self.attributes["name"] = value
83-
8465
# ==========================================================================
8566
# Constructors
8667
# ==========================================================================

src/compas/datastructures/cell_network/cell_network.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,11 @@ class CellNetwork(Datastructure):
5252
Default values for face attributes.
5353
default_cell_attributes: dict, optional
5454
Default values for cell attributes.
55-
**kwargs : dict, optional
56-
Additional attributes for the data structure itself.
55+
name : str, optional
56+
The name of the cell network.
5757
5858
Attributes
5959
----------
60-
attributes : dict[str, Any]
61-
General attributes of the data structure which will be included in the data representation.
6260
default_vertex_attributes : dict[str, Any]
6361
Default attributes of the vertices.
6462
default_edge_attributes: dict[str, Any]
@@ -85,7 +83,6 @@ class CellNetwork(Datastructure):
8583
DATASCHEMA = {
8684
"type": "object",
8785
"properties": {
88-
"attributes": {"type": "object"},
8986
"dva": {"type": "object"},
9087
"dea": {"type": "object"},
9188
"dfa": {"type": "object"},
@@ -169,9 +166,9 @@ def __init__(
169166
default_edge_attributes=None,
170167
default_face_attributes=None,
171168
default_cell_attributes=None,
172-
**kwargs
169+
name=None,
173170
):
174-
super(CellNetwork, self).__init__(**kwargs)
171+
super(CellNetwork, self).__init__(name=name)
175172
self._max_vertex = -1
176173
self._max_face = -1
177174
self._max_cell = -1
@@ -233,7 +230,6 @@ def data(self):
233230
cell[c] = sorted(list(faces))
234231

235232
return {
236-
"attributes": self.attributes,
237233
"dva": self.default_vertex_attributes,
238234
"dea": self.default_edge_attributes,
239235
"dfa": self.default_face_attributes,
@@ -256,14 +252,11 @@ def from_data(cls, data):
256252
dfa = data.get("dfa") or {}
257253
dca = data.get("dca") or {}
258254

259-
attributes = data.get("attributes") or {}
260-
261255
cell_network = cls(
262256
default_vertex_attributes=dva,
263257
default_edge_attributes=dea,
264258
default_face_attributes=dfa,
265259
default_cell_attributes=dca,
266-
**attributes
267260
)
268261

269262
vertex = data["vertex"] or {}

0 commit comments

Comments
 (0)