Skip to content

Commit

Permalink
add jupyterlab
Browse files Browse the repository at this point in the history
  • Loading branch information
bmatthieu3 committed Nov 28, 2022
1 parent 562fb99 commit 858e233
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 21 deletions.
33 changes: 33 additions & 0 deletions ipyaladin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,40 @@

from .aladin_widget import *

def _jupyter_labextension_paths():
"""Called by Jupyter Lab Server to detect if it is a valid labextension and
to install the widget
Returns
=======
src: Source directory name to copy files from. Webpack outputs generated files
into this directory and Jupyter Lab copies from this directory during
widget installation
dest: Destination directory name to install widget files to. Jupyter Lab copies
from `src` directory into <jupyter path>/labextensions/<dest> directory
during widget installation
"""
return [{
'src': 'static',
'dest': 'ipyaladin',
}]


def _jupyter_nbextension_paths():
"""Called by Jupyter Notebook Server to detect if it is a valid nbextension and
to install the widget
Returns
=======
section: The section of the Jupyter Notebook Server to change.
Must be 'notebook' for widget extensions
src: Source directory name to copy files from. Webpack outputs generated files
into this directory and Jupyter Notebook copies from this directory during
widget installation
dest: Destination directory name to install widget files to. Jupyter Notebook copies
from `src` directory into <jupyter path>/nbextensions/<dest> directory
during widget installation
require: Path to importable AMD Javascript module inside the
<jupyter path>/nbextensions/<dest> directory
"""
return [{
'section': 'notebook',
'src': 'static',
Expand Down
10 changes: 10 additions & 0 deletions js/amd-public-path.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@


// In an AMD module, we set the public path using the magic requirejs 'module' dependency
// See https://github.com/requirejs/requirejs/wiki/Differences-between-the-simplified-CommonJS-wrapper-and-standard-AMD-define#module
// Since 'module' is a requirejs magic module, we must include 'module' in the webpack externals configuration.
import * as module from 'module';
const url = new URL(module.uri, document.location)
// Using lastIndexOf('/')+1 gives us the empty string if there is no '/', so pathname becomes '/'
url.pathname = url.pathname.slice(0,url.pathname.lastIndexOf('/')+1);
__webpack_public_path__ = `${url.origin}${url.pathname}`;
13 changes: 10 additions & 3 deletions js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,18 @@
"webpack-cli": "^4.10.0"
},
"dependencies": {
"@jupyter-widgets/base": "^6",
"jquery": "^3.0",
"@jupyter-widgets/base": "^1.1 || ^2 || ^3 || ^4 || ^6",
"jquery": "^3.6.1",
"underscore": "^1.8.3"
},
"jupyterlab": {
"extension": "src/jupyterlab-plugin.js"
"extension": "src/jupyterlab-plugin.js",
"outputDir": "../ipyaladin/labextension",
"sharedPackages": {
"@jupyter-widgets/base": {
"bundled": false,
"singleton": true
}
}
}
}
3 changes: 1 addition & 2 deletions js/src/embed.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@
// already be loaded by the notebook otherwise.

// Export widget models and views, and the npm package version number.
module.exports = require('./jupyter-aladin.js');
module.exports['version'] = require('../package.json').version;
export {ModelAladin, ViewAladin} from './jupyter-aladin';
4 changes: 3 additions & 1 deletion js/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@
//module.exports = require('./jupyter-aladin.js');
//module.exports['version'] = require('../package.json').version;

export {ModelAladin, ViewAladin} from './jupyter-aladin';
export {ModelAladin, ViewAladin} from './jupyter-aladin';

//export {version} from '../package.json';
24 changes: 11 additions & 13 deletions js/src/jupyterlab-plugin.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
var aladin = require('./index');
import {ModelAladin, ViewAladin} from './index.js';
import {IJupyterWidgetRegistry} from '@jupyter-widgets/base';

var base = require('@jupyter-widgets/base');

/**
* The widget manager provider.
*/
module.exports = {
id: 'ipyaladin',
requires: [base.IJupyterWidgetRegistry],
export const IPyAladinWidgetPlugin = {
id: 'ipyaladin:plugin',
requires: [IJupyterWidgetRegistry],
activate: function(app, widgets) {
widgets.registerWidget({
name: 'ipyaladin',
version: aladin.version,
exports: aladin
version: '0.1.10',
exports: { ModelAladin, ViewAladin }
});
},
},
autoStart: true
}
};

export default IPyAladinWidgetPlugin;
24 changes: 22 additions & 2 deletions js/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,36 @@ module.exports = (env, argv) => {
// custom widget.
// It must be an amd module
//
entry: './src/index.js',
entry: ['./amd-public-path.js', './src/index.js'],
output: {
filename: 'index.js',
path: path.resolve(__dirname, '..', 'ipyaladin', 'static'),
libraryTarget: 'amd',
publicPath: '',
},
devtool,
externals: ['@jupyter-widgets/base']
externals: ['@jupyter-widgets/base', 'module']
},
/*{// Embeddable aladin lite bundle
//
// This bundle is identical to the notebook bundle containing the custom
// widget views and models. The only difference is it is placed in the
// dist/ directory and shipped with the npm package for use from a CDN
// like jsdelivr.
//
// The target bundle is always `dist/index.js`, which is the path
// required by the custom widget embedder.
entry: ['./amd-public-path.js', './src/index.js'],
output: {
filename: 'index.js',
path: path.resolve(__dirname, '..', 'ipyaladin', 'dist'),
libraryTarget: 'amd',
publicPath: '', // Set in amd-public-path.js
},
devtool,
// 'module' is the magic requirejs dependency used to set the publicPath
externals: ['@jupyter-widgets/base', 'module']
}*/
/*{// Embeddable ipyaladin bundle
//
// This bundle is generally almost identical to the notebook bundle
Expand Down

0 comments on commit 858e233

Please sign in to comment.