Skip to content

Commit 69e0629

Browse files
authored
Merge pull request #139 from vidartf/fixes
Various minor fixes that cropped up
2 parents dbf8681 + ecaa592 commit 69e0629

23 files changed

+671
-570
lines changed

MANIFEST.in

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,33 @@
11
recursive-include pythreejs/static *.*
22

33
include setupbase.py
4+
5+
include LICENSE
6+
include README.md
7+
include pytest.ini
8+
9+
# Documentation
10+
graft docs
11+
exclude docs/\#*
12+
13+
# docs subdirs we want to skip
14+
prune docs/build
15+
prune docs/dist
16+
17+
# Examples
18+
graft examples
19+
20+
# Patterns to exclude from any directory
21+
global-exclude *~
22+
global-exclude *.pyc
23+
global-exclude *.pyo
24+
global-exclude .git
25+
global-exclude .ipynb_checkpoints
26+
27+
# JS files
28+
graft js
29+
prune js/node_modules
30+
graft jslab
31+
prune jslab/node_modules
32+
33+
# TODO: include / exclude autogenerated code?

examples/renderer_limit.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"# - no prior image is lost because of subsequent renderings\n",
5050
"VBox(children=[\n",
5151
" HBox(children=[\n",
52-
" PreviewWidget(mesh, _width=150, _height=150, layout=Layout(padding='2px'))\n",
52+
" Preview(mesh, _width=150, _height=150, layout=Layout(padding='2px'))\n",
5353
" for mesh in [mesh1, mesh2, mesh3, mesh4, mesh5, mesh6]])\n",
5454
" for _ in range(5)\n",
5555
"])"

js/package.json

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,15 @@
2020
},
2121
"devDependencies": {
2222
"eslint": "^4.11.0",
23-
"fs-extra": "^4.0.1",
24-
"glob": "^7.0.6",
25-
"handlebars": "^4.0.5",
26-
"rimraf": "^2.4.1",
27-
"underscore": "^1.8.3",
28-
"webpack": "^3.6.0"
23+
"fs-extra": "^4.0.2",
24+
"glob": "^7.1.2",
25+
"handlebars": "^4.0.11",
26+
"rimraf": "^2.6.2",
27+
"webpack": "^3.8.1"
2928
},
3029
"dependencies": {
31-
"@jupyter-widgets/base": "^1.0.0",
32-
"bluebird": "^3.4.3",
30+
"@jupyter-widgets/base": "^1.1.4",
31+
"bluebird": "^3.5.1",
3332
"jupyter-dataserializers": "^1.0.0",
3433
"three": "^0.87.1",
3534
"underscore": "^1.8.3"

js/scripts/generate-wrappers.js

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,10 @@
22

33
const _ = require('underscore');
44
const path = require('path');
5-
const fs = require('fs');
65
const fse = require('fs-extra');
76
const Glob = require('glob').Glob;
8-
const Promise = require('bluebird');
97
const Handlebars = require('handlebars');
108

11-
Promise.promisifyAll(fs);
12-
Promise.promisifyAll(fse);
13-
149
const classConfigs = require('./three-class-config');
1510
const Types = require('./prop-types.js');
1611

@@ -56,9 +51,17 @@ const IGNORE_FILES = [
5651
'**/animation/KeyframeTrackConstructor.js', // Sub-part of one object, ignore
5752
'**/animation/KeyframeTrackPrototype.js', // Sub-part of one object, ignore
5853
'**/audio/AudioContext.js', // JS API for audio, nothing to expose
54+
'**/core/Face3.js', // Implemented as trait only, not widget model
5955
'**/geometries/Geometries.js', // index.js like file, nothing new here
6056
'**/materials/Materials.js', // index.js like file, nothing new here
6157
'**/materials/MeshDistanceMaterial.js', // TODO: Undocumented as of yet
58+
'**/math/Vector2.js', // Implemented as trait only, not widget model
59+
'**/math/Vector3.js', // Implemented as trait only, not widget model
60+
'**/math/Vector4.js', // Implemented as trait only, not widget model
61+
'**/math/Matrix3.js', // Implemented as trait only, not widget model
62+
'**/math/Matrix4.js', // Implemented as trait only, not widget model
63+
'**/math/Color.js', // Implemented as trait only, not widget model
64+
'**/math/Euler.js', // Implemented as trait only, not widget model
6265
'**/renderers/WebGLRenderer.js', // For now, the internals of the webgl
6366
'**/renderers/WebGL2Renderer.js', // render is not exposed.
6467
//'**/renderers/webgl/**',
@@ -87,7 +90,7 @@ const IGNORE_FILES = [
8790
function compileTemplate(templateName) {
8891
templateName = path.basename(templateName, '.mustache');
8992
const templatePath = path.resolve(templateDir, templateName + '.mustache');
90-
return Handlebars.compile(fs.readFileSync(templatePath, {
93+
return Handlebars.compile(fse.readFileSync(templatePath, {
9194
encoding: 'utf-8'
9295
}));
9396
}
@@ -306,7 +309,7 @@ class JavascriptWrapper {
306309

307310
// check if manual file exists
308311
const customSrcPath = path.join(path.dirname(this.jsDestPath), path.basename(this.jsDestPath, '.js') + '.js');
309-
this.hasOverride = fs.existsSync(customSrcPath);
312+
this.hasOverride = fse.existsSync(customSrcPath);
310313

311314
this.processSuperClass();
312315
this.processDependencies();
@@ -363,7 +366,7 @@ class JavascriptWrapper {
363366

364367
result.absolutePath = path.resolve(jsSrcDir, result.relativePath);
365368
let absPath = result.absolutePath;
366-
if (fs.existsSync(absPath + '.js')) {
369+
if (fse.existsSync(absPath + '.js')) {
367370
absPath += '.js';
368371
} else {
369372
absPath += JS_AUTOGEN_EXT;
@@ -524,7 +527,7 @@ function createJavascriptWrapper(modulePath, className) {
524527
console.log('skipping: ' + modulePath + (className ? ':' + className : ''));
525528
return Promise.resolve(false);
526529
}
527-
return fse.outputFileAsync(wrapper.getOutputFilename(), wrapper.output);
530+
return fse.outputFile(wrapper.getOutputFilename(), wrapper.output);
528531

529532
// NOTE: Old implementation
530533
// const wrapper = new JavascriptWrapper(modulePath);
@@ -553,7 +556,7 @@ function writeJavascriptIndexFiles() {
553556
const dirAbsPath = path.resolve(jsSrcDir, dirPath);
554557

555558
// Generate list of files in dir to include in index.js as require lines
556-
return fs.readdirAsync(dirAbsPath).then(function(dirFiles) {
559+
return fse.readdir(dirAbsPath).then(function(dirFiles) {
557560

558561
// get proper relative path for file
559562
dirFiles = dirFiles.map(function(filename) {
@@ -616,7 +619,7 @@ function writeJavascriptIndexFiles() {
616619
const output = jsIndexTemplate(context);
617620
const outputPath = path.resolve(jsSrcDir, dirPath, 'index.js');
618621

619-
return fse.outputFileAsync(outputPath, output);
622+
return fse.outputFile(outputPath, output);
620623

621624
});
622625
}
@@ -668,7 +671,9 @@ class PythonWrapper {
668671
this.pyBaseRelativePath = relativePathToPythonImportPath(this.pyBaseRelativePath);
669672

670673
// check if manual file exists
671-
this.hasOverride = fs.existsSync(this.pyDestPath);
674+
this.hasOverride = fse.existsSync(this.pyDestPath);
675+
676+
this.isCustom = CUSTOM_CLASSES.indexOf(modulePath) !== -1;
672677

673678
this.hasParameters = false;
674679

@@ -681,7 +686,6 @@ class PythonWrapper {
681686
this.processConstructorArgs();
682687

683688
// Template and context
684-
this.template = pyWrapperTemplate;
685689
this.context = {
686690
now: new Date(),
687691
generatorScriptName: path.basename(__filename),
@@ -698,10 +702,11 @@ class PythonWrapper {
698702
properties: this.properties,
699703
dependencies: this.dependencies,
700704
hasOverride: this.hasOverride,
705+
isCustom: this.isCustom,
701706
};
702707

703708
// Render template
704-
this.output = this.template(this.context);
709+
this.output = pyWrapperTemplate(this.context);
705710

706711
}
707712

@@ -727,7 +732,7 @@ class PythonWrapper {
727732
// get path of dependency relative to module dir
728733
result.absolutePath = path.resolve(pySrcDir, result.relativePath);
729734

730-
if (!fs.existsSync(result.absolutePath + '.py')) {
735+
if (!fse.existsSync(result.absolutePath + '.py')) {
731736
result.absolutePath += '_' + AUTOGEN_EXT;
732737
}
733738

@@ -821,12 +826,16 @@ class PythonWrapper {
821826

822827
processDocsUrl() {
823828

829+
if (this.isCustom) {
830+
this.docsUrl = null;
831+
}
832+
824833
const refTokens = this.modulePath.split(pathSep);
825834

826835
// strip extension off filename
827836
refTokens[refTokens.length - 1] = path.basename(refTokens[refTokens.length - 1], '.js');
828837

829-
let refUrl = 'http://threejs.org/docs/#api/' + refTokens.join('/');
838+
let refUrl = 'https://threejs.org/docs/#api/' + refTokens.join('/');
830839

831840
// combine middle elements of url with dot
832841
refUrl = refUrl.replace('Renderers/WebGL/Plugins/', 'Renderers.WebGL.Plugins/');
@@ -859,8 +868,10 @@ function createPythonWrapper(modulePath, className) {
859868
console.log('skipping: ' + modulePath + (className ? ':' + className : ''));
860869
return Promise.resolve(false);
861870
}
862-
return fse.outputFileAsync(wrapper.getOutputFilename(), wrapper.output);
871+
let fname = wrapper.getOutputFilename();
872+
let pyPromise = fse.outputFile(fname, wrapper.output);
863873

874+
return pyPromise;
864875
}
865876

866877
function createPythonModuleInitFile(modulePath) {
@@ -892,7 +903,7 @@ function createTopLevelPythonModuleFile() {
892903
if (/autogen/.test(moduleName)) {
893904
const overrideName = moduleName.replace('_autogen', '');
894905
const overridePath = path.resolve(pySrcDir, modulePath, overrideName + '.py');
895-
if (fs.existsSync(overridePath)) {
906+
if (fse.existsSync(overridePath)) {
896907
console.log('Python override exists: ' + overrideName + '. Skipping...');
897908
return;
898909
}
@@ -925,7 +936,7 @@ function createTopLevelPythonModuleFile() {
925936
const output = pyTopLevelInitTemplate(context);
926937
const outFilePath = path.resolve(pySrcDir, '__init__.py');
927938

928-
return fse.outputFileAsync(outFilePath, output);
939+
return fse.outputFile(outFilePath, output);
929940

930941
});
931942

@@ -945,7 +956,7 @@ function createJavascriptFiles() {
945956
function createPythonFiles() {
946957

947958
// Prevent python file generation when outside dir (e.g. npm install in dependent)
948-
if (!fs.existsSync(pySrcDir)) {
959+
if (!fse.existsSync(pySrcDir)) {
949960
return Promise.resolve();
950961
}
951962

@@ -975,6 +986,7 @@ function createPythonFiles() {
975986

976987
}
977988

989+
978990
function generateFiles() {
979991

980992
return Promise.all([

js/scripts/prop-types.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class BaseType {
1313
if (this.defaultValue === false) { return 'False'; }
1414
if (this.defaultValue === true) { return 'True'; }
1515
if (this.defaultValue === 0) { return '0'; }
16-
if (this.defaultValue === '') { return '""'; }
16+
if (this.defaultValue === '') { return "''"; }
1717
if (this.defaultValue === Infinity) { return "float('inf')"; }
1818
if (this.defaultValue === -Infinity) { return "-float('inf')"; }
1919
if (!this.defaultValue) { return 'None'; }
@@ -66,9 +66,9 @@ class ThreeType extends BaseType {
6666
getTraitlet() {
6767
let typeName = this.typeName;
6868
if (typeName instanceof Array) {
69-
for (let tname of typeName) {
69+
typeName = typeName.map(tname => {
7070
return `${tname || 'ThreeWidget'}`;
71-
}
71+
});
7272
} else {
7373
typeName = `${typeName || 'ThreeWidget'}`;
7474
}
@@ -99,7 +99,7 @@ class ForwardDeclaredThreeType extends ThreeType {
9999

100100
class InitializedThreeType extends ThreeType {
101101
getJSPropertyValue() {
102-
return '"uninitialized"';
102+
return "'uninitialized'";
103103
}
104104
getPythonDefaultValue() {
105105
return 'UninitializedSentinel';
@@ -304,7 +304,7 @@ class Color extends BaseType {
304304
constructor(defaultValue, options) {
305305
super();
306306
options = options || {};
307-
this.defaultValue = defaultValue || "#ffffff";
307+
this.defaultValue = defaultValue || '#ffffff';
308308
this.nullable = options.nullable === true;
309309
}
310310
getTraitlet() {
@@ -319,7 +319,7 @@ class Color extends BaseType {
319319
class ColorArray extends BaseType {
320320
constructor(defaultValue) {
321321
super();
322-
this.defaultValue = defaultValue || ["#ffffff"];
322+
this.defaultValue = defaultValue || ['#ffffff'];
323323
}
324324
getTraitlet() {
325325
return `List(trait=Unicode(), default_value=${this.getPythonDefaultValue()}).tag(sync=True)`;
@@ -411,7 +411,7 @@ class Vector2 extends BaseType {
411411
this.defaultValue = [ x||0, y||0 ];
412412
}
413413
getTraitlet() {
414-
return 'Vector2(default=' + JSON.stringify(this.defaultValue) + ').tag(sync=True)';
414+
return 'Vector2(default_value=' + JSON.stringify(this.defaultValue) + ').tag(sync=True)';
415415
}
416416
getPropertyConverterFn() {
417417
return 'convertVector';
@@ -427,7 +427,7 @@ class Vector3 extends BaseType {
427427
this.defaultValue = [ x||0, y||0, z||0 ];
428428
}
429429
getTraitlet() {
430-
return 'Vector3(default=' + JSON.stringify(this.defaultValue) + ').tag(sync=True)';
430+
return 'Vector3(default_value=' + JSON.stringify(this.defaultValue) + ').tag(sync=True)';
431431
}
432432
getPropertyConverterFn() {
433433
return 'convertVector';
@@ -443,7 +443,7 @@ class Vector4 extends BaseType {
443443
this.defaultValue = [ x||0, y||0, z||0, w||0 ];
444444
}
445445
getTraitlet() {
446-
return 'Vector4(default=' + JSON.stringify(this.defaultValue) + ').tag(sync=True)';
446+
return 'Vector4(default_value=' + JSON.stringify(this.defaultValue) + ').tag(sync=True)';
447447
}
448448
getPropertyConverterFn() {
449449
return 'convertVector';
@@ -495,7 +495,7 @@ class Matrix3 extends BaseType {
495495
];
496496
}
497497
getTraitlet() {
498-
return 'Matrix3(default=' + JSON.stringify(this.defaultValue) + ').tag(sync=True)';
498+
return 'Matrix3(default_value=' + JSON.stringify(this.defaultValue) + ').tag(sync=True)';
499499
}
500500
getPropertyConverterFn() {
501501
return 'convertMatrix';
@@ -516,7 +516,7 @@ class Matrix4 extends BaseType {
516516
];
517517
}
518518
getTraitlet() {
519-
return 'Matrix4(default=' + JSON.stringify(this.defaultValue) + ').tag(sync=True)';
519+
return 'Matrix4(default_value=' + JSON.stringify(this.defaultValue) + ').tag(sync=True)';
520520
}
521521
getPropertyConverterFn() {
522522
return 'convertMatrix';
@@ -534,7 +534,7 @@ class Euler extends BaseType {
534534
}
535535

536536
getTraitlet() {
537-
return 'Euler(default=' + JSON.stringify(this.defaultValue) + ').tag(sync=True)';
537+
return 'Euler(default_value=' + JSON.stringify(this.defaultValue) + ').tag(sync=True)';
538538
}
539539
getPropertyConverterFn() {
540540
return 'convertEuler';

js/scripts/templates/js_index.mustache

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,6 @@
33
// Date: {{ now }}
44
//
55
{{#if top_level}}
6-
// Entry point for the notebook bundle containing custom model definitions.
7-
//
8-
// Setup notebook base URL
9-
//
10-
// Some static assets may be required by the custom widget javascript. The base
11-
// url for the notebook is not known at build time and is therefore computed
12-
// dynamically.
13-
__webpack_public_path__ = document.querySelector('body').getAttribute('data-base-url') + 'nbextensions/jupyter-threejs/';
146

157
// Export widget models and views, and the npm package version number.
168
module.exports['version'] = require('../package.json').version;

0 commit comments

Comments
 (0)