Skip to content

Commit 7facb43

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 31d35d2 + 662659f commit 7facb43

File tree

9 files changed

+39
-63
lines changed

9 files changed

+39
-63
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
* Fixed bug in `__getstate__`, `__setstate__` of `compas.base.Base`.
1515
* Fixed bug in `compas_rhino.artists.MeshArtist` and `compas_rhino.artists.NetworkArtist`.
1616
* Changed length and force constraints of DR to optional parameters.
17+
* Removed `ABCMeta` from the list of base clases of several objects in compas.
1718

1819
### Removed
1920

src/compas/base.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,33 @@
1+
"""
2+
If you ever feel tempted to use ABCMeta in your code: don't, just DON'T.
3+
Assigning __metaclass__ = ABCMeta to a class causes a severe memory leak/performance
4+
degradation on IronPython 2.7.
5+
6+
See these issues for more details:
7+
- https://github.com/compas-dev/compas/issues/562
8+
- https://github.com/compas-dev/compas/issues/649
9+
"""
110
from __future__ import print_function
211
from __future__ import absolute_import
312
from __future__ import division
413

5-
import abc
614
import json
715
from uuid import uuid4
816

917
from compas.utilities import DataEncoder
1018
from compas.utilities import DataDecoder
11-
from compas.utilities import abstractclassmethod
12-
13-
ABC = abc.ABCMeta('ABC', (object,), {'__slots__': ()})
1419

1520

1621
__all__ = [
1722
'Base',
1823
]
1924

2025

21-
class Base(ABC):
26+
# import abc
27+
# ABC = abc.ABCMeta('ABC', (object,), {'__slots__': ()})
28+
29+
30+
class Base(object):
2231
"""Abstract base class for all COMPAS objects.
2332
2433
Attributes
@@ -73,24 +82,22 @@ def dtype(self):
7382
"""
7483
return "{}/{}".format(".".join(self.__class__.__module__.split(".")[:2]), self.__class__.__name__)
7584

76-
@abc.abstractproperty
85+
@property
7786
def data(self):
7887
"""dict :
7988
The representation of the object as native Python data.
8089
The structure uf the data is described by the data schema.
8190
"""
82-
pass
91+
raise NotImplementedError
8392

8493
@data.setter
8594
def data(self, data):
8695
pass
8796

88-
@abstractclassmethod
8997
def from_data(cls, data):
9098
"""Construct an object of this type from the provided data."""
91-
pass
99+
raise NotImplementedError
92100

93-
@abc.abstractmethod
94101
def to_data(self):
95102
"""Convert an object to its native data representation.
96103
@@ -99,9 +106,8 @@ def to_data(self):
99106
dict
100107
The data representation of the object as described by the schema.
101108
"""
102-
pass
109+
raise NotImplementedError
103110

104-
@abstractclassmethod
105111
def from_json(cls, filepath):
106112
"""Construct an object from serialised data contained in a JSON file.
107113
@@ -110,9 +116,8 @@ def from_json(cls, filepath):
110116
filepath: str
111117
The path to the file for serialisation.
112118
"""
113-
pass
119+
raise NotImplementedError
114120

115-
@abc.abstractmethod
116121
def to_json(self, filepath):
117122
"""Serialize the data representation of an object to a JSON file.
118123
@@ -121,7 +126,7 @@ def to_json(self, filepath):
121126
filepath: str
122127
The path to the file containing the data.
123128
"""
124-
pass
129+
raise NotImplementedError
125130

126131
def __getstate__(self):
127132
"""Return the object data for state state serialisation with older pickle protocols."""

src/compas/datastructures/_mutablemapping.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
* The Mapping class does not have a __metaclass__ = ABCMeta set
66
because this causes performance issues on IronPython 2.7.x
77
8-
See this issue for more details: https://github.com/compas-dev/compas/issues/562
8+
See these issues for more details:
9+
- https://github.com/compas-dev/compas/issues/562
10+
- https://github.com/compas-dev/compas/issues/649
911
"""
1012
from __future__ import absolute_import
1113
from __future__ import division

src/compas/robots/base_artist/_artist.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,20 @@
22
from __future__ import division
33
from __future__ import print_function
44

5-
import abc
65
import itertools
76

87
from compas.geometry import Frame
98
from compas.geometry import Scale
109
from compas.geometry import Transformation
1110
from compas.robots import Geometry
1211

13-
ABC = abc.ABCMeta('ABC', (object,), {'__slots__': ()})
14-
1512

1613
__all__ = [
1714
'BaseRobotModelArtist'
1815
]
1916

2017

21-
class AbstractRobotModelArtist(ABC):
22-
@abc.abstractmethod
18+
class AbstractRobotModelArtist(object):
2319
def transform(self, geometry, transformation):
2420
"""Transforms a CAD-specific geometry using a **COMPAS** transformation.
2521
@@ -32,7 +28,6 @@ def transform(self, geometry, transformation):
3228
"""
3329
raise NotImplementedError
3430

35-
@abc.abstractmethod
3631
def draw_geometry(self, geometry, name=None, color=None):
3732
"""Draw a **COMPAS** geometry in the respective CAD environment.
3833

src/compas_ghpython/artists/_artist.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,19 @@
22
from __future__ import absolute_import
33
from __future__ import division
44

5-
import abc
6-
7-
ABC = abc.ABCMeta('ABC', (object,), {'__slots__': ()})
8-
95

106
__all__ = ["BaseArtist"]
117

128

13-
class BaseArtist(ABC):
9+
class BaseArtist(object):
1410
"""Abstract base class for all GH artists.
1511
"""
1612

1713
def __init__(self):
1814
pass
1915

20-
@abc.abstractmethod
2116
def draw(self):
22-
pass
17+
raise NotImplementedError
2318

2419
@staticmethod
2520
def draw_collection(collection):

src/compas_rhino/artists/_artist.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,16 @@
22
from __future__ import absolute_import
33
from __future__ import division
44

5-
import abc
65
import compas_rhino
76

8-
ABC = abc.ABCMeta('ABC', (object,), {'__slots__': ()})
9-
107

118
__all__ = ["BaseArtist"]
129

1310

1411
_ITEM_ARTIST = {}
1512

1613

17-
class BaseArtist(ABC):
14+
class BaseArtist(object):
1815
"""Base class for all Rhino artists.
1916
2017
Attributes
@@ -51,9 +48,8 @@ def build(item, **kwargs):
5148
artist = artist_type(item, **kwargs)
5249
return artist
5350

54-
@abc.abstractmethod
5551
def draw(self):
56-
pass
52+
raise NotImplementedError
5753

5854
def redraw(self):
5955
compas_rhino.rs.EnableRedraw(True)

src/compas_rhino/forms/base.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,17 @@
22
from __future__ import absolute_import
33
from __future__ import division
44

5-
import abc
6-
75
import System
86
from System.Windows.Forms import DialogResult
97
from System.Windows.Forms import FormBorderStyle
108

119
import Rhino
1210

1311

14-
ABC = abc.ABCMeta('ABC', (object,), {'__slots__': ()})
15-
16-
1712
__all__ = ['BaseForm']
1813

1914

20-
class BaseForm(System.Windows.Forms.Form, ABC):
15+
class BaseForm(System.Windows.Forms.Form):
2116
"""Base class for Windows forms."""
2217

2318
def __init__(self, title='Form', width=None, height=None):
@@ -33,9 +28,8 @@ def __init__(self, title='Form', width=None, height=None):
3328
self.ResumeLayout()
3429
self.FormClosed += self.on_form_closed
3530

36-
@abc.abstractmethod
3731
def init(self):
38-
pass
32+
raise NotImplementedError
3933

4034
def show(self):
4135
"""Show the form as a modal dialog.

src/compas_rhino/geometry/_geometry.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,16 @@
22
from __future__ import absolute_import
33
from __future__ import division
44

5-
import abc
65
import Rhino
76
import compas_rhino
87

98
from compas.utilities import abstractclassmethod
109

11-
ABC = abc.ABCMeta('ABC', (object,), {'__slots__': ()})
12-
1310

1411
__all__ = ['BaseRhinoGeometry']
1512

1613

17-
class BaseRhinoGeometry(ABC):
14+
class BaseRhinoGeometry(object):
1815
"""Base class for Rhino geometry objects.
1916
2017
Attributes
@@ -107,9 +104,8 @@ def from_geometry(cls, geometry):
107104
def from_selection(cls):
108105
pass
109106

110-
@abc.abstractmethod
111107
def to_compas(self, cls=None):
112-
pass
108+
raise NotImplementedError
113109

114110
def transform(self, T):
115111
"""Transform the Rhino object.

src/compas_rhino/objects/_object.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,17 @@
22
from __future__ import division
33
from __future__ import print_function
44

5-
import abc
65
from uuid import uuid4
76
from compas_rhino.artists import BaseArtist
87

9-
ABC = abc.ABCMeta('ABC', (object,), {'__slots__': ()})
10-
118

129
__all__ = ['BaseObject']
1310

1411

1512
_ITEM_OBJECT = {}
1613

1714

18-
class BaseObject(ABC):
15+
class BaseObject(object):
1916
"""Abstract base class for COMPAS Rhino objects.
2017
2118
Parameters
@@ -133,38 +130,33 @@ def build(item, **kwargs):
133130
object_type = _ITEM_OBJECT[type(item)]
134131
return object_type(item, **kwargs)
135132

136-
@abc.abstractmethod
137133
def clear(self):
138134
"""Clear all previously created Rhino objects."""
139-
pass
135+
raise NotImplementedError
140136

141137
def clear_layer(self):
142138
"""Clear the layer of the object."""
143139
self.artist.clear_layer()
144140

145-
@abc.abstractmethod
146141
def draw(self):
147142
"""Draw the object representing the item."""
148-
pass
143+
raise NotImplementedError
149144

150145
def redraw(self):
151146
"""Redraw the Rhino scene/view."""
152147
self.artist.redraw()
153148

154-
@abc.abstractmethod
155149
def select(self):
156150
"""Select the object representing the item."""
157-
pass
151+
raise NotImplementedError
158152

159-
@abc.abstractmethod
160153
def modify(self):
161154
"""Modify the item represented by the object."""
162-
pass
155+
raise NotImplementedError
163156

164-
@abc.abstractmethod
165157
def move(self):
166158
"""Move the item represented by the object."""
167-
pass
159+
raise NotImplementedError
168160

169161

170162
# ============================================================================

0 commit comments

Comments
 (0)