-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbuild_mkdocs.sh
executable file
·204 lines (143 loc) · 4.92 KB
/
build_mkdocs.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#!/bin/bash
set -e
# dir of this script
THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
WASM_ENV_NAME=pyjs-wasm-dev
WASM_ENV_PREFIX=$MAMBA_ROOT_PREFIX/envs/$WASM_ENV_NAME
EMSDK_DIR=$WASM_ENV_PREFIX/opt/emsdk
EMSDK_VERSION=$1
PYTHON_VERSION=$2
PYJS_PROBE_FILE=$WASM_ENV_PREFIX/lib_js/pyjs/pyjs_runtime_browser.js
if [ ! -d "$WASM_ENV_PREFIX" ]; then
echo "Creating wasm env $WASM_ENV_NAME"
micromamba create -n $WASM_ENV_NAME \
--platform=emscripten-wasm32 \
-c https://repo.mamba.pm/emscripten-forge \
-c https://repo.mamba.pm/conda-forge \
--yes \
python=$PYTHON_VERSION "pybind11" nlohmann_json pybind11_json numpy \
bzip2 sqlite zlib zstd libffi exceptiongroup\
"xeus" "xeus-lite" xeus-python "xeus-javascript" xtl "ipython=8.22.2=py311had7285e_1" "traitlets>=5.14.2"
else
echo "Wasm env $WASM_ENV_NAME already exists"
fi
if true; then
echo "Building pyjs"
cd $THIS_DIR
mkdir -p build
cd build
export PREFIX=$WASM_ENV_PREFIX
export CMAKE_PREFIX_PATH=$PREFIX
export CMAKE_SYSTEM_PREFIX_PATH=$PREFIX
emcmake cmake \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
-DBUILD_RUNTIME_BROWSER=ON \
-DBUILD_RUNTIME_NODE=OFF \
-DCMAKE_INSTALL_PREFIX=$PREFIX \
..
emmake make -j2
emmake make install
else
echo "Skipping build pyjs"
fi
# if there is no xeus-python dir, clone it
if [ ! -d "$THIS_DIR/xeus-python" ]; then
cd $THIS_DIR
git clone https://github.com/jupyter-xeus/xeus-python/
else
echo "xeus-python dir already exists"
fi
if true; then
echo "Building xeus-python"
cd $THIS_DIR
# source $EMSDK_DIR/emsdk_env.sh
cd xeus-python
export PREFIX=$WASM_ENV_PREFIX
export CMAKE_PREFIX_PATH=$PREFIX
export CMAKE_SYSTEM_PREFIX_PATH=$PREFIX
# remove the fake python
rm -rf $PREFIX/bin/python*
rm -rf $PREFIX/bin/pip*
mkdir -p build_wasm
cd build_wasm
# # this is stupid
# cp -r $WASM_ENV_PREFIX/include/python3.11/ $WASM_ENV_PREFIX/include/
emcmake cmake .. \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
-DCMAKE_INSTALL_PREFIX=$PREFIX \
-DXPYT_EMSCRIPTEN_WASM_BUILD=ON \
-DCMAKE_INCLUDE_PATH=$WASM_ENV_PREFIX/include/python3.11
emmake make -j8 install
if [ -d "$WASM_ENV_PREFIX/share/jupyter/kernels/xpython-raw" ]; then
rm -rf $WASM_ENV_PREFIX/share/jupyter/kernels/xpython-raw
fi
else
echo "Skipping build xeus-python"
fi
if false; then
echo "Building xeus-javascript"
cd $THIS_DIR
# source $EMSDK_DIR/emsdk_env.sh
cd ~/src/xeus-javascript
mkdir -p build_wasm
cd build_wasm
export PREFIX=$WASM_ENV_PREFIX
export CMAKE_PREFIX_PATH=$PREFIX
export CMAKE_SYSTEM_PREFIX_PATH=$PREFIX
emcmake cmake .. \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON \
-DCMAKE_INSTALL_PREFIX=$PREFIX \
-DXPYT_EMSCRIPTEN_WASM_BUILD=ON\
emmake make -j8 install
else
echo "Skipping build xeus-javascript"
fi
if true ; then
rm -rf $THIS_DIR/docs_build
mkdir -p $THIS_DIR/docs_build
# convert *.py to *.ipynb using jupytext
NOTEBOOK_OUTPUT_DIR=$THIS_DIR/docs_build/notebooks
rm -rf $NOTEBOOK_OUTPUT_DIR
mkdir -p $NOTEBOOK_OUTPUT_DIR
for f in $THIS_DIR/examples/*.py; do
# get the filename without the extension and path
filename=$(basename -- "$f")
jupytext $f --to ipynb --output $NOTEBOOK_OUTPUT_DIR/${filename%.*}.ipynb --update-metadata '{"kernelspec": {"name": "xpython"}}'
done
for f in $THIS_DIR/examples/*.js; do
# get the filename without the extension and path
filename=$(basename -- "$f")
jupytext $f --to ipynb --output $NOTEBOOK_OUTPUT_DIR/${filename%.*}.ipynb --update-metadata '{"kernelspec": {"name": "xjavascript"}}'
done
# lite
if true; then
cd $THIS_DIR
rm -rf docs_build/_output
rm -rf docs_build/.jupyterlite.doit.db
mkdir -p docs_build
cd docs_build
jupyter lite build \
--contents=$NOTEBOOK_OUTPUT_DIR \
--XeusAddon.prefix=$WASM_ENV_PREFIX \
--XeusAddon.mounts=$THIS_DIR/module/pyjs:/lib/python3.11/site-packages/pyjs
fi
fi
# the docs itself
if true ; then
export PREFIX=$MAMBA_ROOT_PREFIX/envs/pyjs-wasm
echo "Building docs"
cd $THIS_DIR
mkdir -p docs_build/mkdocs
export PYTHONPATH=$PYTHONPATH:$THIS_DIR/stubs
export PYTHONPATH=$PYTHONPATH:$THIS_DIR/module
mkdocs build --site-dir=docs_build/mkdocs
fi
if true ; then
# # copy lite _output to docs_build
cp -r $THIS_DIR/docs_build/_output $THIS_DIR/docs_build/mkdocs/lite
# copy pyjs binary to docs_build
cp $WASM_ENV_PREFIX/lib_js/pyjs/* $THIS_DIR/docs_build/mkdocs/lite/xeus/bin/
fi