Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

* Fixed bug in `__getstate__`, `__setstate__` of `compas.base.Base`.
* Removed `ABCMeta` from the list of base clases of several objects in compas.

### Removed

Expand Down
35 changes: 20 additions & 15 deletions src/compas/base.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
"""
If you ever feel tempted to use ABCMeta in your code: don't, just DON'T.
Assigning __metaclass__ = ABCMeta to a class causes a severe memory leak/performance
degradation on IronPython 2.7.

See these issues for more details:
- https://github.com/compas-dev/compas/issues/562
- https://github.com/compas-dev/compas/issues/649
"""
from __future__ import print_function
from __future__ import absolute_import
from __future__ import division

import abc
import json
from uuid import uuid4

from compas.utilities import DataEncoder
from compas.utilities import DataDecoder
from compas.utilities import abstractclassmethod

ABC = abc.ABCMeta('ABC', (object,), {'__slots__': ()})


__all__ = [
'Base',
]


class Base(ABC):
# import abc
# ABC = abc.ABCMeta('ABC', (object,), {'__slots__': ()})


class Base(object):
"""Abstract base class for all COMPAS objects.

Attributes
Expand Down Expand Up @@ -73,24 +82,22 @@ def dtype(self):
"""
return "{}/{}".format(".".join(self.__class__.__module__.split(".")[:2]), self.__class__.__name__)

@abc.abstractproperty
@property
def data(self):
"""dict :
The representation of the object as native Python data.
The structure uf the data is described by the data schema.
"""
pass
raise NotImplementedError

@data.setter
def data(self, data):
pass

@abstractclassmethod
def from_data(cls, data):
"""Construct an object of this type from the provided data."""
pass
raise NotImplementedError

@abc.abstractmethod
def to_data(self):
"""Convert an object to its native data representation.

Expand All @@ -99,9 +106,8 @@ def to_data(self):
dict
The data representation of the object as described by the schema.
"""
pass
raise NotImplementedError

@abstractclassmethod
def from_json(cls, filepath):
"""Construct an object from serialised data contained in a JSON file.

Expand All @@ -110,9 +116,8 @@ def from_json(cls, filepath):
filepath: str
The path to the file for serialisation.
"""
pass
raise NotImplementedError

@abc.abstractmethod
def to_json(self, filepath):
"""Serialize the data representation of an object to a JSON file.

Expand All @@ -121,7 +126,7 @@ def to_json(self, filepath):
filepath: str
The path to the file containing the data.
"""
pass
raise NotImplementedError

def __getstate__(self):
"""Return the object data for state state serialisation with older pickle protocols."""
Expand Down
4 changes: 3 additions & 1 deletion src/compas/datastructures/_mutablemapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
* The Mapping class does not have a __metaclass__ = ABCMeta set
because this causes performance issues on IronPython 2.7.x

See this issue for more details: https://github.com/compas-dev/compas/issues/562
See these issues for more details:
- https://github.com/compas-dev/compas/issues/562
- https://github.com/compas-dev/compas/issues/649
"""
from __future__ import absolute_import
from __future__ import division
Expand Down
7 changes: 1 addition & 6 deletions src/compas/robots/base_artist/_artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,20 @@
from __future__ import division
from __future__ import print_function

import abc
import itertools

from compas.geometry import Frame
from compas.geometry import Scale
from compas.geometry import Transformation
from compas.robots import Geometry

ABC = abc.ABCMeta('ABC', (object,), {'__slots__': ()})


__all__ = [
'BaseRobotModelArtist'
]


class AbstractRobotModelArtist(ABC):
@abc.abstractmethod
class AbstractRobotModelArtist(object):
def transform(self, geometry, transformation):
"""Transforms a CAD-specific geometry using a **COMPAS** transformation.

Expand All @@ -32,7 +28,6 @@ def transform(self, geometry, transformation):
"""
raise NotImplementedError

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

Expand Down
9 changes: 2 additions & 7 deletions src/compas_ghpython/artists/_artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,19 @@
from __future__ import absolute_import
from __future__ import division

import abc

ABC = abc.ABCMeta('ABC', (object,), {'__slots__': ()})


__all__ = ["BaseArtist"]


class BaseArtist(ABC):
class BaseArtist(object):
"""Abstract base class for all GH artists.
"""

def __init__(self):
pass

@abc.abstractmethod
def draw(self):
pass
raise NotImplementedError

@staticmethod
def draw_collection(collection):
Expand Down
8 changes: 2 additions & 6 deletions src/compas_rhino/artists/_artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@
from __future__ import absolute_import
from __future__ import division

import abc
import compas_rhino

ABC = abc.ABCMeta('ABC', (object,), {'__slots__': ()})


__all__ = ["BaseArtist"]


_ITEM_ARTIST = {}


class BaseArtist(ABC):
class BaseArtist(object):
"""Base class for all Rhino artists.

Attributes
Expand Down Expand Up @@ -51,9 +48,8 @@ def build(item, **kwargs):
artist = artist_type(item, **kwargs)
return artist

@abc.abstractmethod
def draw(self):
pass
raise NotImplementedError

def redraw(self):
compas_rhino.rs.EnableRedraw(True)
Expand Down
10 changes: 2 additions & 8 deletions src/compas_rhino/forms/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,17 @@
from __future__ import absolute_import
from __future__ import division

import abc

import System
from System.Windows.Forms import DialogResult
from System.Windows.Forms import FormBorderStyle

import Rhino


ABC = abc.ABCMeta('ABC', (object,), {'__slots__': ()})


__all__ = ['BaseForm']


class BaseForm(System.Windows.Forms.Form, ABC):
class BaseForm(System.Windows.Forms.Form):
"""Base class for Windows forms."""

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

@abc.abstractmethod
def init(self):
pass
raise NotImplementedError

def show(self):
"""Show the form as a modal dialog.
Expand Down
8 changes: 2 additions & 6 deletions src/compas_rhino/geometry/_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@
from __future__ import absolute_import
from __future__ import division

import abc
import Rhino
import compas_rhino

from compas.utilities import abstractclassmethod

ABC = abc.ABCMeta('ABC', (object,), {'__slots__': ()})


__all__ = ['BaseRhinoGeometry']


class BaseRhinoGeometry(ABC):
class BaseRhinoGeometry(object):
"""Base class for Rhino geometry objects.

Attributes
Expand Down Expand Up @@ -107,9 +104,8 @@ def from_geometry(cls, geometry):
def from_selection(cls):
pass

@abc.abstractmethod
def to_compas(self, cls=None):
pass
raise NotImplementedError

def transform(self, T):
"""Transform the Rhino object.
Expand Down
20 changes: 6 additions & 14 deletions src/compas_rhino/objects/_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,17 @@
from __future__ import division
from __future__ import print_function

import abc
from uuid import uuid4
from compas_rhino.artists import BaseArtist

ABC = abc.ABCMeta('ABC', (object,), {'__slots__': ()})


__all__ = ['BaseObject']


_ITEM_OBJECT = {}


class BaseObject(ABC):
class BaseObject(object):
"""Abstract base class for COMPAS Rhino objects.

Parameters
Expand Down Expand Up @@ -133,38 +130,33 @@ def build(item, **kwargs):
object_type = _ITEM_OBJECT[type(item)]
return object_type(item, **kwargs)

@abc.abstractmethod
def clear(self):
"""Clear all previously created Rhino objects."""
pass
raise NotImplementedError

def clear_layer(self):
"""Clear the layer of the object."""
self.artist.clear_layer()

@abc.abstractmethod
def draw(self):
"""Draw the object representing the item."""
pass
raise NotImplementedError

def redraw(self):
"""Redraw the Rhino scene/view."""
self.artist.redraw()

@abc.abstractmethod
def select(self):
"""Select the object representing the item."""
pass
raise NotImplementedError

@abc.abstractmethod
def modify(self):
"""Modify the item represented by the object."""
pass
raise NotImplementedError

@abc.abstractmethod
def move(self):
"""Move the item represented by the object."""
pass
raise NotImplementedError


# ============================================================================
Expand Down