Skip to content

Commit 946a47d

Browse files
committed
Merge remote-tracking branch 'origin/main' into main
2 parents c032a0d + 531e3f6 commit 946a47d

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2020
* Added `faces_where`, `faces_where_predicate`, `cells_where`, `cells_where_predicate` to `compas.datastructures.HalfFace`.
2121
* Added `VolMeshArtist` to registered Blender artists.
2222
* Added `3.1` to supported versions for Blender installer.
23+
* Added `compas.artist.NoArtistContextError`.
2324

2425
### Changed
2526

@@ -51,6 +52,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5152
* Fixed `compas_blender.artists.VolMeshArtist.draw` and `compas_blender.artists.VolMeshArtist.draw_cells`.
5253
* Fixed `compas_ghpython.artists.VolMeshArtist.draw` and `compas_ghpython.artists.VolMeshArtist.draw_cells`.
5354
* Fixed `compas_rhino.artists.VolMeshArtist.draw` and `compas_rhino.artists.VolMeshArtist.draw_cells`.
55+
* Improved error messages when artist instance cannot be created.
5456
* Fixed bug in `compas_rhino.conversions.RhinoCurve.to_compas`.
5557
* Fixed bug in `compas_rhino.conversions.RhinoSurface.to_compas`.
5658

src/compas/artists/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
:nosignatures:
4040
4141
DataArtistNotRegistered
42+
NoArtistContextError
4243
4344
4445
Pluggables
@@ -58,6 +59,7 @@
5859
from __future__ import division
5960

6061
from .exceptions import DataArtistNotRegistered
62+
from .exceptions import NoArtistContextError
6163
from .artist import Artist
6264
from .curveartist import CurveArtist
6365
from .meshartist import MeshArtist
@@ -77,6 +79,7 @@
7779

7880
__all__ = [
7981
'DataArtistNotRegistered',
82+
'NoArtistContextError',
8083
'Artist',
8184
'CurveArtist',
8285
'MeshArtist',

src/compas/artists/artist.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
from collections import defaultdict
88

99
import compas
10-
from compas.artists import DataArtistNotRegistered
11-
from compas.plugins import pluggable
10+
from compas.artists.exceptions import DataArtistNotRegistered
11+
from compas.artists.exceptions import NoArtistContextError
1212
from compas.plugins import PluginValidator
13+
from compas.plugins import pluggable
1314

1415
from .colordict import DescriptorProtocol
1516

@@ -45,6 +46,9 @@ def _get_artist_cls(data, **kwargs):
4546
else:
4647
Artist.CONTEXT = identify_context()
4748

49+
if Artist.CONTEXT is None:
50+
raise NoArtistContextError()
51+
4852
dtype = type(data)
4953
cls = None
5054

@@ -85,11 +89,15 @@ class Artist(object):
8589
CONTEXT = None
8690
ITEM_ARTIST = defaultdict(dict)
8791

88-
def __new__(cls, *args, **kwargs):
92+
def __new__(cls, item, **kwargs):
8993
if not Artist.__ARTISTS_REGISTERED:
9094
register_artists()
9195
Artist.__ARTISTS_REGISTERED = True
92-
cls = _get_artist_cls(args[0], **kwargs)
96+
97+
if item is None:
98+
raise ValueError('Cannot create an artist for None. Please ensure you pass a instance of a supported class.')
99+
100+
cls = _get_artist_cls(item, **kwargs)
93101
PluginValidator.ensure_implementations(cls)
94102
return super(Artist, cls).__new__(cls)
95103

src/compas/artists/exceptions.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,13 @@
55

66
class DataArtistNotRegistered(Exception):
77
"""Exception that is raised when no artist is registered for a given data type."""
8+
9+
10+
class NoArtistContextError(Exception):
11+
"""Exception that is raised when no artist context is assigned is registered for a given data type."""
12+
def __init__(self):
13+
error_message = "No context defined."
14+
error_message += "\n\nThis usually means that the script that you are running requires"
15+
error_message += "\na CAD environment but it is being ran as a standalone script"
16+
error_message += "\n(ie. from the command line or code editor)."
17+
super(NoArtistContextError, self).__init__(error_message)

0 commit comments

Comments
 (0)