Skip to content

Commit ce3be27

Browse files
committed
feat: add provider/consumer example
1 parent f78f8c3 commit ce3be27

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+790
-61
lines changed

__provider_consumer__/README.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# JupyterLab Provider Consumer Extensions
2+
3+
```bash
4+
yarn install
5+
yarn build
6+
# cd provider && yarn dev && cd ..
7+
# cd consumer && yarn dev && cd ..
8+
yarn dev
9+
jupyter lab # Have a look at the browser console
10+
```
11+
12+
The following messages should be printed in the browser console.
13+
14+
```
15+
index.js:11 JupyterLab extension provider is activated!
16+
index.js:10 JupyterLab extension consumer is activated!
17+
index.js:11 Provider token is PROVIDER_STRING
18+
```
19+
20+
- TODO jupyterlab-extensions-example-2 separated repository consuming a plugin of this repository (once released).
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
BSD 3-Clause License
2+
3+
Copyright (c) 2020, MyName All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are met:
7+
8+
* Redistributions of source code must retain the above copyright notice, this
9+
list of conditions and the following disclaimer.
10+
11+
* Redistributions in binary form must reproduce the above copyright notice,
12+
this list of conditions and the following disclaimer in the documentation
13+
and/or other materials provided with the distribution.
14+
15+
* Neither the name of the copyright holder nor the names of its
16+
contributors may be used to endorse or promote products derived from
17+
this software without specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
include LICENSE
2+
include README.md
3+
include pyproject.toml
4+
include jupyter-config/consumer.json
5+
6+
include package.json
7+
include install.json
8+
include ts*.json
9+
10+
graft consumer/labextension
11+
12+
# Javascript files
13+
graft src
14+
graft style
15+
prune **/node_modules
16+
prune lib
17+
18+
# Patterns to exclude from any directory
19+
global-exclude *~
20+
global-exclude *.pyc
21+
global-exclude *.pyo
22+
global-exclude .git
23+
global-exclude .ipynb_checkpoints
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# JupyterLab Consumer Extension
2+
3+
A JupyterLab extension consuming a string from a provider.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
import json
3+
import os.path as osp
4+
5+
from ._version import __version__
6+
7+
HERE = osp.abspath(osp.dirname(__file__))
8+
9+
with open(osp.join(HERE, 'labextension', 'package.json')) as fid:
10+
data = json.load(fid)
11+
12+
def _jupyter_labextension_paths():
13+
return [{
14+
'src': 'labextension',
15+
'dest': data['name']
16+
}]
17+
18+
19+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# This file is auto-generated by Hatchling. As such, do not:
2+
# - modify
3+
# - track in version control e.g. be sure to add to .gitignore
4+
__version__ = VERSION = '0.1.0'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"packageManager": "python",
3+
"packageName": "consumer",
4+
"uninstallInstructions": "Use your Python package manager (pip, conda, etc.) to uninstall the package consumer"
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
{
2+
"name": "@datalayer-examples/ext-consumer",
3+
"version": "0.1.0",
4+
"description": "A lab extension consuming a string.",
5+
"keywords": [
6+
"jupyter",
7+
"jupyterlab",
8+
"jupyterlab-extension"
9+
],
10+
"homepage": "https://github.com/my_name/myextension",
11+
"bugs": {
12+
"url": "https://github.com/my_name/myextension/issues"
13+
},
14+
"license": "BSD-3-Clause",
15+
"author": {
16+
"name": "Eric Charles",
17+
"email": "[email protected]"
18+
},
19+
"files": [
20+
"lib/**/*.{d.ts,eot,gif,html,jpg,js,js.map,json,png,svg,woff2,ttf}",
21+
"style/**/*.{css,eot,gif,html,jpg,json,png,svg,woff2,ttf}"
22+
],
23+
"main": "lib/index.js",
24+
"types": "lib/index.d.ts",
25+
"style": "style/index.css",
26+
"repository": {
27+
"type": "git",
28+
"url": "https://github.com/my_name/myextension.git"
29+
},
30+
"scripts": {
31+
"build": "jlpm run build:lib && jlpm run build:labextension:dev",
32+
"build:prod": "jlpm run build:lib && jlpm run build:labextension",
33+
"build:labextension": "jupyter labextension build .",
34+
"build:labextension:dev": "jupyter labextension build --development True .",
35+
"build:lib": "tsc",
36+
"clean": "jlpm run clean:lib",
37+
"clean:lib": "rimraf lib tsconfig.tsbuildinfo",
38+
"clean:labextension": "rimraf consumer/labextension",
39+
"clean:all": "jlpm run clean:lib && jlpm run clean:labextension",
40+
"dev": "pip install -e . && jupyter labextension develop . --overwrite",
41+
"eslint": "eslint . --ext .ts,.tsx --fix",
42+
"eslint:check": "eslint . --ext .ts,.tsx",
43+
"install:extension": "jupyter labextension develop --overwrite .",
44+
"prepare": "jlpm run clean && jlpm run build:prod",
45+
"watch": "run-p watch:src watch:labextension",
46+
"watch:src": "tsc -w",
47+
"watch:labextension": "jupyter labextension watch ."
48+
},
49+
"dependencies": {
50+
"@jupyterlab/application": "4.0.0-alpha.18",
51+
"@lumino/coreutils": "2.0.0-beta.0",
52+
"@datalayer-examples/ext-provider": "0.1.0"
53+
},
54+
"devDependencies": {
55+
"@jupyterlab/builder": "4.0.0-alpha.18",
56+
"@types/react": "18.0.28",
57+
"@typescript-eslint/eslint-plugin": "^2.27.0",
58+
"@typescript-eslint/parser": "^2.27.0",
59+
"eslint": "^7.5.0",
60+
"eslint-config-prettier": "^6.10.1",
61+
"eslint-plugin-prettier": "^3.1.2",
62+
"npm-run-all": "^4.1.5",
63+
"prettier": "^1.19.0",
64+
"rimraf": "^3.0.2",
65+
"typescript": "~4.0.3"
66+
},
67+
"sideEffects": [
68+
"style/*.css"
69+
],
70+
"jupyterlab": {
71+
"extension": true,
72+
"outputDir": "consumer/labextension",
73+
"sharedPackages": {
74+
"provider": {"requiredVersion": "0.1.0", "bundled": false, "singleton": true}
75+
}
76+
},
77+
"publishConfig": {
78+
"registry": "http://localhost:4873"
79+
}
80+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
[build-system]
2+
requires = ["hatchling>=1.4.0", "jupyterlab==4.0.0a33", "hatch-nodejs-version"]
3+
build-backend = "hatchling.build"
4+
5+
[project]
6+
name = "consumer"
7+
readme = "README.md"
8+
license = { file = "LICENSE" }
9+
requires-python = ">=3.9"
10+
classifiers = [
11+
"Framework :: Jupyter",
12+
"Framework :: Jupyter :: JupyterLab",
13+
"Framework :: Jupyter :: JupyterLab :: 3",
14+
"Framework :: Jupyter :: JupyterLab :: Extensions",
15+
"Framework :: Jupyter :: JupyterLab :: Extensions :: Prebuilt",
16+
"License :: OSI Approved :: BSD License",
17+
"Programming Language :: Python",
18+
"Programming Language :: Python :: 3",
19+
"Programming Language :: Python :: 3.9",
20+
"Programming Language :: Python :: 3.10",
21+
"Programming Language :: Python :: 3.11",
22+
]
23+
dependencies = [
24+
"jupyter_server>=2.0,<3"
25+
]
26+
dynamic = ["version", "description", "authors", "urls", "keywords"]
27+
28+
[project.optional-dependencies]
29+
test = [
30+
"coverage",
31+
"pytest",
32+
"pytest-asyncio",
33+
"pytest-cov",
34+
"pytest-tornasync"
35+
]
36+
37+
[tool.hatch.version]
38+
source = "nodejs"
39+
40+
[tool.hatch.metadata.hooks.nodejs]
41+
fields = ["description", "authors", "urls"]
42+
43+
[tool.hatch.build.targets.sdist]
44+
artifacts = ["consumer/labextension"]
45+
exclude = [".github", "binder"]
46+
47+
[tool.hatch.build.targets.wheel.shared-data]
48+
"consumer/labextension" = "share/jupyter/labextensions/@datalayer-examples/ext-consumer"
49+
"install.json" = "share/jupyter/labextensions/@datalayer-examples/ext-consumer/install.json"
50+
"jupyter-config/server-config" = "etc/jupyter/jupyter_server_config.d"
51+
"jupyter-config/nb-config" = "etc/jupyter/jupyter_notebook_config.d"
52+
53+
[tool.hatch.build.hooks.version]
54+
path = "consumer/_version.py"
55+
56+
[tool.hatch.build.hooks.jupyter-builder]
57+
dependencies = ["hatch-jupyter-builder>=0.5"]
58+
build-function = "hatch_jupyter_builder.npm_builder"
59+
ensured-targets = [
60+
"consumer/labextension/static/style.js",
61+
"consumer/labextension/package.json",
62+
]
63+
skip-if-exists = ["consumer/labextension/static/style.js"]
64+
65+
[tool.hatch.build.hooks.jupyter-builder.build-kwargs]
66+
build_cmd = "build:prod"
67+
npm = ["jlpm"]
68+
69+
[tool.hatch.build.hooks.jupyter-builder.editable-build-kwargs]
70+
build_cmd = "install:extension"
71+
npm = ["jlpm"]
72+
source_dir = "src"
73+
build_dir = "consumer/labextension"
74+
75+
[tool.jupyter-releaser.options]
76+
version_cmd = "hatch version"
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__import__('setuptools').setup()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import {
2+
JupyterFrontEnd,
3+
JupyterFrontEndPlugin
4+
} from '@jupyterlab/application';
5+
6+
import { IProvider } from '@datalayer-examples/ext-provider';
7+
8+
/**
9+
* Initialization data for the consumer extension.
10+
*/
11+
const extension: JupyterFrontEndPlugin<void> = {
12+
id: 'consumer',
13+
autoStart: true,
14+
requires: [ IProvider ],
15+
activate: (app: JupyterFrontEnd, provider: IProvider) => {
16+
console.log('JupyterLab extension consumer is activated!');
17+
console.log(`Provider token is ${provider}`);
18+
}
19+
};
20+
21+
export default extension;

__provider_consumer__/consumer/style/index.css

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"compilerOptions": {
3+
"allowSyntheticDefaultImports": true,
4+
"composite": true,
5+
"declaration": true,
6+
"esModuleInterop": true,
7+
"incremental": true,
8+
"jsx": "react",
9+
"module": "esnext",
10+
"moduleResolution": "node",
11+
"noEmitOnError": true,
12+
"noImplicitAny": true,
13+
"noUnusedLocals": true,
14+
"preserveWatchOutput": true,
15+
"resolveJsonModule": true,
16+
"outDir": "lib",
17+
"rootDir": "src",
18+
"strict": true,
19+
"strictNullChecks": false,
20+
"target": "es2018",
21+
"types": []
22+
},
23+
"include": ["src/*"]
24+
}

__provider_consumer__/lerna.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"version": "0.0.6",
3+
"npmClient": "yarn",
4+
"useWorkspaces": true
5+
}

0 commit comments

Comments
 (0)