Skip to content

Commit 0889eb1

Browse files
authored
Rename python module to streetscape_avs (#444)
1 parent 0415aa3 commit 0889eb1

34 files changed

+1551
-14
lines changed

bindings/python/.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*.py[cod]
2+
3+
# Cookiecutter
4+
output/
5+
bower_components

bindings/python/LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Uber Technologies, Inc.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

bindings/python/README.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# streetscape_avs
2+
3+
#### A Streetscape.gl module for Jupyter
4+
5+
Provides an ipywidget for viewing XVIZ data with Streetscape.gl in Jupyter
6+
7+
## What is streetscape_avs
8+
9+
With **streetscape_avs** you can view and interact with XVIZ data in the Jupyter
10+
environment.
11+
12+
## Usage
13+
14+
Install [streetscape_avs](https://github.com/uber/streetscape.gl):
15+
16+
$ pip install streetscape_avs

bindings/python/streetscape_avs.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"author_name": "Timothy Wojtaszek",
3+
"author_email": "[email protected]",
4+
"github_project_name": "uber/streetscape.gl",
5+
"github_organization_name": "uber",
6+
"python_package_name": "streetscape_avs",
7+
"npm_package_name": "streetscape-jupyter",
8+
"npm_package_version": "0.1.0",
9+
"project_short_description": "Streetscape XVIZ viewer for Jupyter"
10+
}
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
*.egg-info/
2+
.ipynb_checkpoints/
3+
dist/
4+
build/
5+
*.py[cod]
6+
node_modules/
7+
8+
# Compiled javascript
9+
streetscape_avs/static/
10+
11+
# OS X
12+
.DS_Store
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
recursive-include streetscape_avs/static *.*
2+
include streetscape_avs.
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
streetscape_avs
2+
===============
3+
4+
A Jupyter widget using streetscape.gl to view XVIZ data.
5+
6+
Installation
7+
------------
8+
9+
To install use pip:
10+
11+
$ pip install streetscape_avs
12+
$ jupyter nbextension enable --py --sys-prefix streetscape_avs
13+
14+
For a development installation (requires npm),
15+
16+
$ git clone https://github.com/uber/streetscape.gl.git
17+
$ cd streetscape.gl/bindings/python/streetscape_avs
18+
$ pip install -e .
19+
$ jupyter nbextension install --py --symlink --sys-prefix streetscape_avs
20+
$ jupyter nbextension enable --py --sys-prefix streetscape_avs
21+
22+
For jupyter lab development,
23+
24+
$ jupyter labextension install @jupyter-widgets/jupyterlab-manager --no-build
25+
$ jupyter labextension install js
26+
27+
When actively developing your extension, build Jupyter Lab with the command:
28+
29+
$ jupyter lab --watch
30+
31+
This take a minute or so to get started, but then allows you to hot-reload your javascript extension.
32+
To see a change, save your javascript, watch the terminal for an update.
33+
34+
Note on first `jupyter lab --watch`, you may need to touch a file to get Jupyter Lab to open.
35+
36+
Development
37+
-----------
38+
39+
Useful commands to remove the modules
40+
41+
$ jupyter nbextension disable streetscape_avs --py --sys-prefix
42+
$ jupyter nbextension uninstall --py --sys-prefix streetscape_avs
43+
$ pip uninstall streetscape_avs
44+
45+
For Jupyter Lab
46+
47+
$ jupyter labextension disable @streetscape/jupyter-widget
48+
$ jupyter labextension uninstall @streetscape/jupyter-widget
49+
$ jupyter lab clean && jupyter lab build
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# To release a new version of streetscape_avs on PyPI:
2+
3+
Update _version.py (set release version, remove 'dev')
4+
git add the _version.py file and git commit
5+
`python setup.py sdist upload`
6+
`python setup.py bdist_wheel upload`
7+
`git tag -a X.X.X -m 'comment'`
8+
Update _version.py (add 'dev' and increment minor)
9+
git add and git commit
10+
git push
11+
git push --tags
12+
13+
- To release a new version of @streetscape/jupyter-widget on NPM:
14+
15+
```
16+
# clean out the `dist` and `node_modules` directories
17+
git clean -fdx
18+
npm install
19+
npm publish
20+
```
21+
22+
23+
# clean out dist
24+
rm dist/*
25+
26+
# build widget (is this necessary?)
27+
cd js, yarn build
28+
verify dist/index.js
29+
j
30+
# build (dev pyenv) for this
31+
python setup.py sdist bdist_wheel
32+
33+
# test (separate pyenv for this)
34+
twine upload --repository-url https://test.pypi.org/legacy/ dist/*
35+
python3 -m pip uninstall xviz_avs
36+
python3 -m pip install -i https://test.pypi.org xviz_avs
37+
python3 -m pip install -i https://test.pypi.org/legacy xviz_avs
38+
python3 -m pip install -i https://test.pypi.org/simple/ "xviz-avs=0.1.0a3"
39+
python3 test-xviz.py
40+
41+
# upload
42+
twine upload dist/*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Streetscape.gl Jupyter widget for viewing XVIZ data
2+
3+
Package Install
4+
---------------
5+
6+
**Prerequisites**
7+
- [node](http://nodejs.org/)
8+
9+
```bash
10+
npm install --save @streetscape/jupyter-widget
11+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Entry point for the unpkg bundle containing custom model definitions.
2+
//
3+
// It differs from the notebook bundle in that it does not need to define a
4+
// dynamic baseURL for the static assets and may load some css that would
5+
// already be loaded by the notebook otherwise.
6+
7+
// Export widget models and views, and the npm package version number.
8+
module.exports = require('./widget.js');
9+
module.exports['version'] = require('../package.json').version;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// This file contains the javascript that is run when the notebook is loaded.
2+
// It contains some requirejs configuration and the `load_ipython_extension`
3+
// which is required for any notebook extension.
4+
//
5+
// Some static assets may be required by the custom widget javascript. The base
6+
// url for the notebook is not known at build time and is therefore computed
7+
// dynamically.
8+
__webpack_public_path__ =
9+
document.querySelector('body').getAttribute('data-base-url') + 'nbextensions/streetscape_avs';
10+
11+
// Configure requirejs
12+
if (window.require) {
13+
window.require.config({
14+
map: {
15+
'*': {
16+
'@streetscape/jupyter-widget': 'nbextensions/streetscape_avs/index'
17+
}
18+
}
19+
});
20+
}
21+
22+
// Export the required load_ipython_extension
23+
module.exports = {
24+
load_ipython_extension: function() {}
25+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Export widget models and views, and the npm package version number.
2+
module.exports = require('./widget.js');
3+
module.exports['version'] = require('../package.json').version;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
var plugin = require('../dist/lab');
2+
var base = require('@jupyter-widgets/base');
3+
4+
const EXTENSION_ID = 'streetscape_avs:plugin';
5+
6+
// name must match _model_module in python DOMWidget
7+
// version must match _model_module_version in python DOMWidget
8+
module.exports = {
9+
id: EXTENSION_ID,
10+
requires: [base.IJupyterWidgetRegistry],
11+
activate: function(app, widgets) {
12+
widgets.registerWidget({
13+
name: '@streetscape/jupyter-widget',
14+
version: '0.1.0',
15+
exports: plugin
16+
});
17+
},
18+
autoStart: true
19+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Copyright (c) 2019 Uber Technologies, Inc.
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a copy
4+
// of this software and associated documentation files (the "Software"), to deal
5+
// in the Software without restriction, including without limitation the rights
6+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
// copies of the Software, and to permit persons to whom the Software is
8+
// furnished to do so, subject to the following conditions:
9+
//
10+
// The above copyright notice and this permission notice shall be included in
11+
// all copies or substantial portions of the Software.
12+
//
13+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
// THE SOFTWARE.
20+
import React, {useEffect, useState, useRef} from 'react';
21+
import {StreetscapeJupyter} from './component';
22+
23+
export const STREETSCAPE_GL_JUPYTER_VERSION = '__PACKAGE_VERSION__';
24+
25+
function App(props) {
26+
const rootElm = useRef(null);
27+
const [windowDimension, setDimension] = useState({});
28+
29+
const handleResize = () => {
30+
if (!rootElm.current) {
31+
return;
32+
}
33+
34+
const width = rootElm.current.offsetWidth;
35+
const height = rootElm.current.offsetHeight;
36+
const dimensionToSet = {
37+
...(width && width !== windowDimension.width ? {width} : {}),
38+
...(height && height !== windowDimension.height ? {height} : {})
39+
};
40+
41+
setDimension(dimensionToSet);
42+
};
43+
44+
// in Jupyter Lab, parent component has transition when window resize.
45+
// need to delay call to get the final parent width,
46+
const resizeDelay = () => window.setTimeout(handleResize, 500);
47+
48+
useEffect(() => {
49+
window.addEventListener('resize', resizeDelay);
50+
return () => window.removeEventListener('resize', resizeDelay);
51+
}, []);
52+
53+
return (
54+
<div
55+
style={{width: '100%', height: `100%`}}
56+
ref={rootElm}
57+
className="streetscapegl-widget-container"
58+
>
59+
<StreetscapeJupyter />
60+
<div style={{position: 'absolute', top: 0, right: 0}}>
61+
Ver: {STREETSCAPE_GL_JUPYTER_VERSION}
62+
</div>
63+
</div>
64+
);
65+
}
66+
67+
export default App;

0 commit comments

Comments
 (0)