Skip to content

Commit 77dce75

Browse files
committed
Support external extension
1 parent 9e0433c commit 77dce75

File tree

3 files changed

+34
-8
lines changed

3 files changed

+34
-8
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ npm start
3737
```bash
3838
python -m http.server 3344 -d jupyterlite/_output
3939
```
40+
4041
- Build JupyterLite and watch for code changes:
4142

4243
```bash
@@ -49,3 +50,14 @@ npm start:watch
4950
npm run clean # Clean build assets
5051
npm run start:bash # Open a bash shell in the container
5152
```
53+
54+
### Customize jupyterlite build
55+
56+
- All files located in `./jupyterlite` will be copied to the build directory in the container. So you can add your config file (`jupyter_lite_config.py|json`,...) to this directory.
57+
58+
- To add local JupyterLite extensions to the build, update `.env` file with path to your extensions and key prefixed by `JUPYTERLITE_EXTERNAL`
59+
60+
```bash
61+
#.env file
62+
JUPYTERLITE_EXTERNAL_MY_CUSTOM_EXTENSION=../demo/my-custom-ext
63+
```

script/build.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,18 @@ emmake make -j4
3030
emmake make install
3131
popd
3232

33+
echo "############## INSTALL EXTENSIONS ##############"
34+
for subdir in /home/$MAMBA_USER/extensions/*; do
35+
if [ -d "$subdir" ]; then
36+
echo "Running pip install -e $subdir"
37+
pip install -e "$subdir" -v --no-build-isolation
38+
fi
39+
done
40+
3341
echo "############## BUILDING JUPYTERLITE ##############"
3442
cd /home/$MAMBA_USER/xeus
43+
rm -fr tsconfig.tsbuildinfo
3544
python -m pip install -e . -v --no-build-isolation
3645
cd $LITE_DIR
37-
rm -fr *
46+
rm -fr _output .jupyterlite.doit.db
3847
jupyter lite build --XeusAddon.prefix=$PREFIX --XeusAddon.mounts=$PREFIX/lib/python3.11/site-packages/pyjs:/lib/python3.11/site-packages/pyjs

script/cmd.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,7 @@ function clean() {
5858

5959
function start(mode) {
6060
const outDir = `${ROOT}/jupyterlite`;
61-
if (mode !== "bash") {
62-
if (fs.existsSync(outDir)) {
63-
fs.rmSync(outDir, { recursive: true, force: true });
64-
}
61+
if (!fs.existsSync(path.join(outDir))) {
6562
fs.mkdirSync(outDir);
6663
}
6764
let cmd = "";
@@ -79,9 +76,17 @@ function start(mode) {
7976
const xeusPythonMount = `${XEUS_PYTHON_PATH}:${CONTAINER_ROOT}/xeus-python`;
8077
const empackMount = `${EMPACK_PATH}:${CONTAINER_ROOT}/empack`;
8178
const cacheMount = `${STORAGE_VOLUME}:/opt/conda/opt/emsdk`;
82-
83-
const mount = `-v ${jupyterliteMount} -v ${pyjsMount} -v ${xeusMount} -v ${xeusPythonMount} -v ${empackMount} -v ${cacheMount}`;
84-
79+
80+
let mount = `-v ${jupyterliteMount} -v ${pyjsMount} -v ${xeusMount} -v ${xeusPythonMount} -v ${empackMount} -v ${cacheMount}`;
81+
Object.entries(process.env).forEach(([key, val]) => {
82+
if (key.startsWith("JUPYTERLITE_EXTERNAL_")) {
83+
const mountString = ` -v ${path.resolve(
84+
val
85+
)}:${CONTAINER_ROOT}/extensions/${key}`;
86+
mount += mountString;
87+
}
88+
});
89+
8590
execSync(
8691
`docker run --name xeus-stack-container --rm -it ${mount} xeus-stack:latest ${cmd}`,
8792
{

0 commit comments

Comments
 (0)