Skip to content

Commit c81ca68

Browse files
authored
Merge pull request #162 from vidartf/test-examples-output
Ensure examples pass non-lax nbval test
2 parents 0a73eb6 + 524a139 commit c81ca68

File tree

8 files changed

+1915
-1853
lines changed

8 files changed

+1915
-1853
lines changed

examples/Animation.ipynb

Lines changed: 1308 additions & 1216 deletions
Large diffs are not rendered by default.

examples/Geometries.ipynb

Lines changed: 536 additions & 624 deletions
Large diffs are not rendered by default.

examples/Textures.ipynb

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@
3131
{
3232
"cell_type": "code",
3333
"execution_count": 3,
34-
"metadata": {},
34+
"metadata": {
35+
"tags": [
36+
"nbval-ignore-output"
37+
]
38+
},
3539
"outputs": [
3640
{
3741
"data": {
@@ -70,7 +74,11 @@
7074
{
7175
"cell_type": "code",
7276
"execution_count": 4,
73-
"metadata": {},
77+
"metadata": {
78+
"tags": [
79+
"nbval-ignore-output"
80+
]
81+
},
7482
"outputs": [
7583
{
7684
"data": {
@@ -150,7 +158,11 @@
150158
{
151159
"cell_type": "code",
152160
"execution_count": 6,
153-
"metadata": {},
161+
"metadata": {
162+
"tags": [
163+
"nbval-ignore-output"
164+
]
165+
},
154166
"outputs": [
155167
{
156168
"data": {

examples/conftest.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
def pytest_collectstart(collector):
3+
if collector.fspath and collector.fspath.ext == '.ipynb':
4+
collector.skip_compare += ('application/vnd.jupyter.widget-view+json', 'text/html')

js/scripts/generate-wrappers.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,15 @@ function getClassConfig(className) {
157157
classConfigs._defaults
158158
);
159159

160+
if ('type' in result.allProperties && result.allProperties.type instanceof Types.String) {
161+
if ('type' in result.properties) {
162+
result.properties.type.defaultValue = className;
163+
} else {
164+
result.properties.type = new Types.String(className);
165+
result.allProperties.type = result.properties.type;
166+
}
167+
}
168+
160169
return result;
161170
}
162171

js/scripts/three-class-config.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ module.exports = {
102102
relativePath: './cameras/CubeCamera',
103103
superClass: 'Object3D',
104104
properties: {
105-
type: new Types.String('CubeCamera'),
106105
}
107106
},
108107
OrthographicCamera: {
@@ -116,7 +115,6 @@ module.exports = {
116115
bottom: new Types.Float(),
117116
near: new Types.Float(0.1),
118117
far: new Types.Float(2000),
119-
type: new Types.String('OrthographicCamera'),
120118
},
121119
constructorArgs: [ 'left', 'right', 'top', 'bottom', 'near', 'far' ],
122120
},
@@ -133,15 +131,13 @@ module.exports = {
133131
// view: new Types.Dict(),
134132
// filmGauge: new Types.Float(35.0),
135133
// filmOffset: new Types.Float(0.0),
136-
type: new Types.String('PerspectiveCamera'),
137134
},
138135
constructorArgs: [ 'fov', 'aspect', 'near', 'far' ],
139136
},
140137
ArrayCamera: {
141138
relativePath: './cameras/ArrayCamera',
142139
superClass: 'PerspectiveCamera',
143140
properties: {
144-
type: new Types.String('ArrayCamera'),
145141
},
146142
constructorArgs: [ 'fov', 'aspect', 'near', 'far' ],
147143
},
@@ -347,7 +343,6 @@ module.exports = {
347343
attributes: new Types.ThreeTypeDict(['BufferAttribute', 'InterleavedBufferAttribute']),
348344
morphAttributes: new Types.BufferMorphAttributes(),
349345
MaxIndex: new Types.Int(65535),
350-
type: new Types.String('BufferGeometry'),
351346
// TODO: These likely require special types:
352347
//groups: new Types.GeometryGroup(),
353348
//drawRange: new Types.DrawRange(),
@@ -675,7 +670,6 @@ module.exports = {
675670
refractionRatio: new Types.Float(0.98),
676671
skinning: new Types.Bool(false),
677672
specularMap: new Types.ThreeType('Texture'),
678-
type: new Types.String('MeshBasicMaterial'),
679673
wireframe: new Types.Bool(false),
680674
wireframeLinewidth: new Types.Float(1),
681675
wireframeLinecap: new Types.String('round'), // TODO: enum?
@@ -1044,7 +1038,6 @@ module.exports = {
10441038
geometry: new Types.ThreeType(['BaseGeometry', 'BaseBufferGeometry'], {nullable: false}),
10451039
drawMode: new Types.Enum('DrawModes', 'TrianglesDrawMode'),
10461040
morphTargetInfluences: new Types.Array(),
1047-
type: new Types.String('Mesh'),
10481041
},
10491042
propsDefinedByThree: ['morphTargetInfluences'],
10501043
},
@@ -1682,7 +1675,6 @@ module.exports = {
16821675
hex: new Types.Int(0),
16831676
headLength: new Types.Float(null, {nullable: true}),
16841677
headWidth: new Types.Float(null, {nullable: true}),
1685-
type: new Types.String('ArrowHelper'),
16861678
},
16871679
},
16881680
AxesHelper: {

pythreejs/core/BufferGeometry.py

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
from ipywidgets import register, widget_serialization
3-
from traitlets import validate, TraitError
4-
from ipydatawidgets import NDArrayWidget
3+
from traitlets import validate, TraitError, Undefined
4+
from ipydatawidgets import NDArrayWidget, get_union_array
55

66
from .BufferGeometry_autogen import BufferGeometry as BufferGeometryBase
77

@@ -30,3 +30,43 @@ def validate(self, proposal):
3030
raise TraitError('Index attribute must be a flat array. Consider using array.ravel().')
3131

3232
return value
33+
34+
35+
def _gen_repr_from_keys(self, keys):
36+
# Hide data in repr to avoid overly large datasets
37+
# Replace with uuids of buffer attributes
38+
class_name = self.__class__.__name__
39+
signature_parts = [
40+
'%s=%r' % (key, getattr(self, key))
41+
for key in keys if key not in ('attributes', 'morphAttributes')
42+
]
43+
for name in ('attributes', 'morphAttributes'):
44+
if not _dict_is_default(self, name):
45+
signature_parts.append('%s=%s' % (name, _attr_dict_repr(getattr(self, name))))
46+
return '%s(%s)' % (class_name, ', '.join(signature_parts))
47+
48+
49+
def _dict_is_default(ht, name):
50+
value = getattr(ht, name)
51+
return (
52+
getattr(ht.__class__, name).default_value == Undefined and
53+
(value is None or len(value) == 0)
54+
)
55+
56+
def _attr_value_repr(v):
57+
array = get_union_array(v.array)
58+
# Return full repr if array size is small:
59+
if array.size < 50:
60+
return repr(v)
61+
# Otherwise, return a summary:
62+
return '<%s shape=%r, dtype=%s>' % (v.__class__.__name__, array.shape, array.dtype)
63+
64+
def _attr_dict_repr(d):
65+
parts = []
66+
for key, value in d.items():
67+
if isinstance(value, tuple):
68+
value_parts = [_attr_value_repr(v) for v in value]
69+
else:
70+
value_parts = [_attr_value_repr(value)]
71+
parts.append('%r: %s' % (key, ', '.join(value_parts)))
72+
return '{%s}' % (', '.join(parts),)

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
'test': [
7878
'nbval',
7979
'pytest-check-links',
80+
'numpy>=1.14',
8081
],
8182
'examples': [
8283
'scipy',

0 commit comments

Comments
 (0)