Skip to content

Commit 3c9ca4a

Browse files
committed
Support creating a local JupyterLite deployment with git2cpp built from the local repo
1 parent 857a898 commit 3c9ca4a

File tree

8 files changed

+191
-0
lines changed

8 files changed

+191
-0
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,11 @@ The CLI is tested using `python`. From the top-level directory:
2525
```bash
2626
pytest -v
2727
```
28+
29+
# JupyterLite deployment
30+
31+
The `lite-deploy` directory contains everything needed to build the local `git2cpp` source code as
32+
an [Emscripten-forge](https://emscripten-forge.org/) package and create a local JupyterLite
33+
deployment that can run it in a [terminal](https://github.com/jupyterlite/terminal).
34+
35+
See the `README.md` in the `lite-deploy` directory for further details.

lite-deploy/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.cockle_temp/
2+
.jupyterlite.doit.db
3+
cockle-config.json
4+
cockle_wasm_env/
5+
dist/
6+
em-forge-recipes/

lite-deploy/Makefile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
default: all
2+
.PHONY: all build-deployment build-recipe clean clean-deployment clean-package modify-recipe rebuild serve
3+
4+
EM_FORGE_RECIPES_DIR = em-forge-recipes
5+
GIT2CPP_RECIPE_DIR = recipes/recipes_emscripten/git2cpp
6+
BUILT_PACKAGE_DIR = $(EM_FORGE_RECIPES_DIR)/output
7+
8+
# Note removing the .git directory otherwise `git clean -fxd` will not remove the directory.
9+
$(EM_FORGE_RECIPES_DIR):
10+
git clone https://github.com/emscripten-forge/recipes --depth 1 $@
11+
rm -rf $@/.git
12+
13+
modify-recipe: $(EM_FORGE_RECIPES_DIR)
14+
python modify-recipe.py $(EM_FORGE_RECIPES_DIR)/$(GIT2CPP_RECIPE_DIR)
15+
16+
build-recipe: modify-recipe
17+
cd $(EM_FORGE_RECIPES_DIR) && pixi run build-emscripten-wasm32-pkg $(GIT2CPP_RECIPE_DIR)
18+
19+
build-deployment: build-recipe
20+
jupyter lite --version
21+
COCKLE_WASM_EXTRA_CHANNEL=./$(BUILT_PACKAGE_DIR) jupyter lite build --output-dir dist
22+
23+
all: build-deployment
24+
25+
# Rebuild package and deployment after changing git2cpp source code.
26+
rebuild: clean-package all
27+
28+
# Run `make` before this.
29+
serve:
30+
npx static-handler dist
31+
32+
clean: clean-deployment
33+
rm -rf $(EM_FORGE_RECIPES_DIR)
34+
35+
clean-package:
36+
rm -rf $(BUILT_PACKAGE_DIR) cockle_wasm_env/
37+
38+
# Clean the deployment without removing the built package.
39+
clean-deployment:
40+
rm -rf .cockle_temp/ .jupyterlite.doit.db cockle-config.json cockle_wasm_env/ dist/

lite-deploy/README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# JupyterLite deployment
2+
3+
This directory contains everything needed to build the local `git2cpp` source code as an
4+
[Emscripten-forge](https://emscripten-forge.org/) package and create a local JupyterLite deployment
5+
that can run it in a [terminal](https://github.com/jupyterlite/terminal).
6+
7+
It works on Linux and macOS but not Windows.
8+
9+
It uses a separate `micromamba` environment defined in `deploy-environment.yml`. To set this up use:
10+
```bash
11+
micromamba create -f deploy-environment.yml
12+
micromamba activate git2cpp-deploy
13+
```
14+
15+
Then to build `git2cpp` and create the JupyterLite deployment use:
16+
```bash
17+
make
18+
```
19+
20+
This performs the following steps:
21+
22+
1. Clones the `emscripten-forge/recipes` repository.
23+
2. Modifies the `git2cpp` recipe (using `modify_recipe.py`) to build from the local `git2cpp` source code in `../src/`.
24+
3. Builds the package from the recipe using `pixi`.
25+
4. Builds the JupyterLite deployment in the `dist/` directory using the locally-built package.
26+
27+
The built package will be in the `em-forge-recipes/output/emscripten-wasm32` directory with a name
28+
something like `git2cpp-0.0.3-h2072262_3.tar.bz2`. If you compare this with the latest
29+
Emscripten-forge package on `https://prefix.dev/channels/emscripten-forge-dev/packages/git2cpp`,
30+
the local package should have the same version number and the build number should be one higher.
31+
32+
To serve the JupyterLite deployment use:
33+
```bash
34+
make serve
35+
```
36+
and open a web browser at the URL http://localhost:8080/. Start a terminal and run the
37+
`cockle-config` command (typing `coc`, then the tab key then enter should suffice). Amongst the
38+
displayed information should be the `git2cpp` package showing that it is from a local directory
39+
such as `file:///something-or-other/git2cpp/lite-deploy/em-forge-recipes/output` rather than from
40+
`prefix.dev` such as `https://repo.prefix.dev/emscripten-forge-dev`.
41+
42+
After making changes to `git2cpp` source code, to rebuild the package and deployment use:
43+
```bash
44+
make rebuild
45+
```
46+
and then re-serve using:
47+
```bash
48+
make serve
49+
```

lite-deploy/cockle-config-in.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"packages": {
3+
"git2cpp": {},
4+
"nano": {},
5+
"tree": {},
6+
"vim": {}
7+
},
8+
"aliases": {
9+
"git": "git2cpp",
10+
"vi": "vim"
11+
},
12+
"environment": {
13+
"GIT_CORS_PROXY": "https://corsproxy.io/?url=",
14+
"GIT_AUTHOR_NAME": "Jane Doe",
15+
"GIT_AUTHOR_EMAIL": "jane.doe@blabla.com",
16+
"GIT_COMMITTER_NAME": "Jane Doe",
17+
"GIT_COMMITTER_EMAIL": "jane.doe@blabla.com"
18+
}
19+
}

lite-deploy/deploy-environment.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: git2cpp-deploy
2+
channels:
3+
- conda-forge
4+
dependencies:
5+
# To modify emscripten-forge recipe
6+
- python
7+
- pyyaml
8+
# To build emscripten-forge recipe
9+
- pixi
10+
- rattler-build
11+
# For JupyterLite deployment
12+
- jupyter_server
13+
- jupyterlite-terminal
14+
- nodejs

lite-deploy/jupyter-lite.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"jupyter-lite-schema-version": 0,
3+
"jupyter-config-data": {
4+
"terminalsAvailable": true
5+
}
6+
}

lite-deploy/modify-recipe.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Modify the git2cpp emscripten-forge recipe to build from the local repo.
2+
# This can be called repeatedly and will produce the same output.
3+
4+
from pathlib import Path
5+
import shutil
6+
import sys
7+
import yaml
8+
9+
10+
def quit(msg):
11+
print(msg)
12+
exit(1)
13+
14+
if len(sys.argv) < 2:
15+
quit(f'Usage: {sys.argv[0]} <recipe directory containing yaml file to modify>')
16+
17+
input_dir = Path(sys.argv[1])
18+
if not input_dir.is_dir():
19+
quit(f'{input_dir} should exist and be a directory')
20+
21+
input_filename = input_dir / 'recipe.yaml'
22+
if not input_filename.is_file():
23+
quit(f'{input_filename} should exist and be a file')
24+
25+
# If backup does not exist create it.
26+
input_backup = input_dir / 'recipe_original.yaml'
27+
backup_exists = input_backup.exists()
28+
if not backup_exists:
29+
shutil.copy(input_filename, input_backup)
30+
31+
# Read and parse input backup file which is the original recipe file.
32+
with open(input_backup) as f:
33+
recipe = yaml.safe_load(f)
34+
35+
build_number = recipe['build']['number']
36+
print(f' Changing build number from {build_number} to {build_number+1}')
37+
recipe['build']['number'] = build_number+1
38+
39+
source = recipe['source']
40+
if not ('sha256' in source and 'url' in source):
41+
raise RuntimeError('Expected recipe to have both a source sha256 and url')
42+
del source['sha256']
43+
del source['url']
44+
print(' Changing source to point to local git2cpp repo')
45+
source['path'] = '../../../../../'
46+
47+
# Overwrite recipe file.
48+
with open(input_filename, 'w') as f:
49+
yaml.dump(recipe, f)

0 commit comments

Comments
 (0)