Skip to content

Commit a3148a5

Browse files
committed
Run xeus-cpp-lite-demo.ipynb in ci and test output for Safari, Chrome and Firefox
1 parent 6cad0a4 commit a3148a5

File tree

12 files changed

+618
-10
lines changed

12 files changed

+618
-10
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: 'Run kernel in notebook within Jupyter Lite'
2+
description: 'This action runs the chosen kernel in notebook within Jupyter Lite'
3+
4+
inputs:
5+
notebook:
6+
description: "The notebook to run the kernel in"
7+
required: true
8+
type: string
9+
kernel:
10+
description: "The kernel to use"
11+
required: true
12+
type: string
13+
14+
runs:
15+
using: composite
16+
steps:
17+
- name: Jupyter Lite integration test
18+
shell: bash -l {0}
19+
run: |
20+
set -e
21+
micromamba activate xeus-lite-host
22+
export INPUT_TEXT=""
23+
if [[ "${{ inputs.notebook }}" == "xeus-cpp-lite-demo.ipynb"* ]]; then
24+
export INPUT_TEXT="--stdin Smudge"
25+
fi
26+
echo "Running xeus-cpp in Jupter Lite in Chrome"
27+
python -u scripts/automated-notebook-run-script.py --driver chrome --notebook ${{ inputs.notebook }} --kernel ${{ inputs.kernel }} $INPUT_TEXT
28+
nbdiff notebooks/${{ inputs.notebook }} $HOME/Downloads/${{ inputs.notebook }} --ignore-id --ignore-metadata >> chrome_diff.txt
29+
export CHROME_TESTS_RETURN_VALUE=$( [ -s chrome_diff.txt ] && echo 1 || echo 0 )
30+
rm $HOME/Downloads/${{ inputs.notebook }}
31+
echo "Running xeus-cpp in Jupter Lite in Firefox"
32+
python -u scripts/automated-notebook-run-script.py --driver firefox --notebook ${{ inputs.notebook }} --kernel ${{ inputs.kernel }} $INPUT_TEXT
33+
nbdiff notebooks/${{ inputs.notebook }} $HOME/Downloads/${{ inputs.notebook }} --ignore-id --ignore-metadata >> firefox_diff.txt
34+
export FIREFOX_TESTS_RETURN_VALUE=$( [ -s firefox_diff.txt ] && echo 1 || echo 0 )
35+
rm $HOME/Downloads/${{ inputs.notebook }}
36+
export SAFARI_TESTS_RETURN_VALUE=0
37+
touch safari_diff.txt
38+
if [[ "${{ matrix.os }}" == "macos"* ]]; then
39+
echo "Running xeus-cpp in Jupter Lite in Safari"
40+
python -u scripts/automated-notebook-run-script.py --driver safari --notebook ${{ inputs.notebook }} --kernel ${{ inputs.kernel }} $INPUT_TEXT
41+
nbdiff notebooks/${{ inputs.notebook }} $HOME/Downloads/${{ inputs.notebook }} --ignore-id --ignore-metadata >> safari_diff.txt
42+
export SAFARI_TESTS_RETURN_VALUE=$( [ -s safari_diff.txt ] && echo 1 || echo 0 )
43+
rm $HOME/Downloads/${{ inputs.notebook }}
44+
fi
45+
if [[ $SAFARI_TESTS_RETURN_VALUE -ne 0 || $FIREFOX_TESTS_RETURN_VALUE -ne 0 || $CHROME_TESTS_RETURN_VALUE -ne 0 ]]; then
46+
if [[ "${{ matrix.os }}" == "macos"* ]]; then
47+
echo "Diff Safari (blank means no diff)"
48+
cat safari_diff.txt
49+
fi
50+
echo "Diff Firefox (blank means no diff)"
51+
cat firefox_diff.txt
52+
echo "Diff Chrome (blank means no diff)"
53+
cat chrome_diff.txt
54+
exit 1
55+
fi
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: 'This sets up our Jupyter Lite website, so we can run xeus-cpp in it'
2+
description: 'This action sets up our Jupyter Lite website, so we can run xeus-cpp in it'
3+
4+
runs:
5+
using: composite
6+
steps:
7+
- name: Jupyter Lite integration test
8+
shell: bash -l {0}
9+
run: |
10+
set -e
11+
micromamba create -n xeus-lite-host jupyterlite-core=0.6 jupyterlite-xeus -c conda-forge -y
12+
micromamba activate xeus-lite-host
13+
if [[ "${{ matrix.os }}" == "macos"* ]]; then
14+
brew install coreutils
15+
export PATH="$HOMEBREW_PREFIX/opt/coreutils/libexec/gnubin:$PATH"
16+
fi
17+
timeout 900 jupyter lite serve --settings-overrides=overrides.json --XeusAddon.prefix=${{ env.PREFIX }} \
18+
--XeusAddon.mounts="${{ env.PREFIX }}/share/xeus-cpp/tagfiles:/share/xeus-cpp/tagfiles" \
19+
--XeusAddon.mounts="${{ env.PREFIX }}/etc/xeus-cpp/tags.d:/etc/xeus-cpp/tags.d" \
20+
--contents README.md \
21+
--contents notebooks/xeus-cpp-lite-demo.ipynb \
22+
--contents notebooks/tinyraytracer.ipynb \
23+
--contents notebooks/images/marie.png \
24+
--contents notebooks/audio/audio.wav \
25+
--output-dir dist &
26+
# There is a bug in nbdime after 3.2.0 where it will show the filenames as if there was a diff
27+
# but there is no diff with the options chosen below (the latest doesn't show a diff, just the filenames with +++
28+
# and --- as if it was planning to show a diff. This only happens for xeus-cpp-lite-demo.ipynb.
29+
python -m pip install nbdime==3.2.0
30+
if [[ "${{ matrix.os }}" == "macos"* ]]; then
31+
python -m pip install PyAutoGUI
32+
python scripts/enable-downloads-safari-github-ci.py
33+
fi
34+
python -m pip install selenium
35+
# This sleep is to force enough time for the jupyter site to build before trying
36+
# to run notebooks in it. If you try to run the notebooks before the website is
37+
# ready the ci python script will crash saying ti cannot access the url
38+
sleep 10

.github/workflows/deploy-github-page.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ jobs:
150150
--XeusAddon.mounts="${{ env.PREFIX }}/etc/xeus-cpp/tags.d:/etc/xeus-cpp/tags.d" \
151151
--contents README.md \
152152
--contents notebooks/xeus-cpp-lite-demo.ipynb \
153+
--contents notebooks/tinyraytracer.ipynb \
153154
--contents notebooks/images/marie.png \
154155
--contents notebooks/audio/audio.wav \
155156
--output-dir dist

.github/workflows/main.yml

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -329,12 +329,29 @@ jobs:
329329
fi
330330
timeout-minutes: 4
331331

332-
- name: Jupyter Lite integration
333-
shell: bash -l {0}
334-
run: |
335-
micromamba create -n xeus-lite-host jupyterlite-core=0.6 jupyterlite-xeus -c conda-forge
336-
micromamba activate xeus-lite-host
337-
jupyter lite build --XeusAddon.prefix=${{ env.PREFIX }}
332+
- name: Serve Jupyter Lite website
333+
uses: ./.github/actions/Jupyter-serve
334+
335+
- name: Test C++17 kernel in xeus-cpp-lite-demo.ipynb
336+
uses: ./.github/actions/Emscripten-Notebook-Tests
337+
with:
338+
notebook: "xeus-cpp-lite-demo.ipynb"
339+
kernel: "C++17"
340+
timeout-minutes: 5
341+
342+
- name: Test C++20 kernel in xeus-cpp-lite-demo.ipynb
343+
uses: ./.github/actions/Emscripten-Notebook-Tests
344+
with:
345+
notebook: "xeus-cpp-lite-demo.ipynb"
346+
kernel: "C++20"
347+
timeout-minutes: 5
348+
349+
- name: Test C++23 kernel in xeus-cpp-lite-demo.ipynb
350+
uses: ./.github/actions/Emscripten-Notebook-Tests
351+
with:
352+
notebook: "xeus-cpp-lite-demo.ipynb"
353+
kernel: "C++23"
354+
timeout-minutes: 5
338355

339356
- name: Setup tmate session
340357
if: ${{ failure() && runner.debug }}

CONTRIBUTING.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,43 @@ jupyter lite serve --XeusAddon.prefix=$PREFIX \
163163
--contents notebooks/xeus-cpp-lite-demo.ipynb \
164164
--contents notebooks/images/marie.png \
165165
--contents notebooks/audio/audio.wav
166+
167+
### xeus-cpp Jupyter Lite tests
168+
169+
It is possible to run test the xeus-cpp in Jupyter Lite deployment, using a Selenium based script and the nbdiff Jupyter tool.
170+
In order to install these dependencies execute the following (you will need the Jupyter Lite website running in the background when
171+
executing the python script)
172+
173+
```bash
174+
python -m pip install nbdime==3.2.0 selenium
175+
```
176+
177+
Then to run the by executing (--run-browser-gui option exists if you want Chrome or Firefox to show a gui browser as they run)
178+
179+
```bash
180+
python -u scripts/automated-notebook-run-script.py --driver browser --notebook notebook --kernel kernel --stdin Test_Input --timeout timeout
181+
```
182+
183+
For example
184+
185+
```bash
186+
python -u scripts/automated-notebook-run-script.py --driver chrome --notebook xeus-cpp-lite-demo.ipynb --kernel C++20 --stdin Smudge --timeout 200
187+
```
188+
189+
will run the xeus-cpp-lite-demo.ipynb notebook in chrome, with the C++20 kernel, enter Test_Name in the standard input box in this notebook,
190+
and stop the script, if the notebook has finished running after 200 seconds. This works for Safari, Chrome and Firefox. It should be noted
191+
that in the case of Safari, safari driver must be enabled, and downloads must be enabled from 127.0.0.1 . Once the script has finished
192+
executing you can compare the notebook download from the one in the repo, to check the deployment works as expected, by executing
193+
(replace notebook_run with the notebook chosen for the Python script)
194+
195+
```bash
196+
nbdiff notebook_run $HOME/Downlaods/notebook_run --ignore-id --ignore-metadata
197+
```
198+
199+
For example after running the above test command, to test no changes have occurred, execute
200+
201+
```bash
202+
nbdiff xeus-cpp-lite-demo.ipynb $HOME/Downlaods/xeus-cpp-lite-demo.ipynb --ignore-id --ignore-metadata
203+
```
204+
166205
```

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,44 @@ jupyter lite serve --XeusAddon.prefix=$PREFIX \
180180
--contents notebooks/audio/audio.wav
181181
```
182182

183+
### xeus-cpp Jupyter Lite tests
184+
185+
It is possible to run test the xeus-cpp in Jupyter Lite deployment, using a Selenium based script and the nbdiff Jupyter tool.
186+
In order to install these dependencies execute the following (you will need the Jupyter Lite website running in the background when
187+
executing the python script)
188+
189+
```bash
190+
python -m pip install nbdime==3.2.0 selenium
191+
```
192+
193+
Then to run the by executing (--run-browser-gui option exists if you want Chrome or Firefox to show a gui browser as they run)
194+
195+
```bash
196+
python -u scripts/automated-notebook-run-script.py --driver browser --notebook notebook --kernel kernel --stdin Test_Input --timeout timeout
197+
```
198+
199+
For example
200+
201+
```bash
202+
python -u scripts/automated-notebook-run-script.py --driver chrome --notebook xeus-cpp-lite-demo.ipynb --kernel C++20 --stdin Smudge --timeout 200
203+
```
204+
205+
will run the xeus-cpp-lite-demo.ipynb notebook in chrome, with the C++20 kernel, enter Test_Name in the standard input box in this notebook,
206+
and stop the script, if the notebook has finished running after 200 seconds. This works for Safari, Chrome and Firefox. It should be noted
207+
that in the case of Safari, safari driver must be enabled, and downloads must be enabled from 127.0.0.1 . Once the script has finished
208+
executing you can compare the notebook download from the one in the repo, to check the deployment works as expected, by executing
209+
(replace notebook_run with the notebook chosen for the Python script)
210+
211+
```bash
212+
nbdiff notebook_run $HOME/Downlaods/notebook_run --ignore-id --ignore-metadata
213+
```
214+
215+
For example after running the above test command, to test no changes have occurred, execute
216+
217+
```bash
218+
nbdiff xeus-cpp-lite-demo.ipynb $HOME/Downlaods/xeus-cpp-lite-demo.ipynb --ignore-id --ignore-metadata
219+
```
220+
183221
## Trying it online
184222

185223
To try out xeus-cpp interactively in your web browser, just click on the binder link:

docs/source/InstallationAndUsage.rst

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,46 @@ To build and test Jupyter Lite with this kernel locally you can execute the foll
161161
--contents notebooks/images/marie.png \
162162
--contents notebooks/audio/audio.wav
163163
164+
xeus-cpp Jupyter Lite tests
165+
========================
166+
167+
It is possible to run test the xeus-cpp in Jupyter Lite deployment, using a Selenium based script and the nbdiff Jupyter tool.
168+
In order to install these dependencies execute the following (you will need the Jupyter Lite website running in the background when
169+
executing the python script)
170+
171+
.. code-block:: bash
172+
173+
python -m pip install nbdime==3.2.0 selenium
174+
175+
Then to run the by executing (--run-browser-gui option exists if you want Chrome or Firefox to show a gui browser as they run)
176+
177+
.. code-block:: bash
178+
179+
python -u scripts/automated-notebook-run-script.py --driver browser --notebook notebook --kernel kernel --stdin Test_Input --timeout timeout
180+
181+
For example
182+
183+
.. code-block:: bash
184+
185+
python -u scripts/automated-notebook-run-script.py --driver chrome --notebook xeus-cpp-lite-demo.ipynb --kernel C++20 --stdin Smudge --timeout 200
186+
187+
will run the xeus-cpp-lite-demo.ipynb notebook in chrome, with the C++20 kernel, enter Test_Name in the standard input box in this notebook,
188+
and stop the script, if the notebook has finished running after 200 seconds. This works for Safari, Chrome and Firefox. It should be noted
189+
that in the case of Safari, safari driver must be enabled, and downloads must be enabled from 127.0.0.1 . Once the script has finished
190+
executing you can compare the notebook download from the one in the repo, to check the deployment works as expected, by executing
191+
(replace notebook_run with the notebook chosen for the Python script)
192+
193+
.. code-block:: bash
194+
195+
nbdiff notebook_run $HOME/Downlaods/notebook_run --ignore-id --ignore-metadata
196+
197+
198+
For example after running the above test command, to test no changes have occurred, execute
199+
200+
.. code-block:: bash
201+
202+
nbdiff xeus-cpp-lite-demo.ipynb $HOME/Downlaods/xeus-cpp-lite-demo.ipynb --ignore-id --ignore-metadata
203+
164204
Installing from conda-forge
165205
===========================
166206

docs/source/conf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
micromamba create -n xeus-lite-host jupyterlite-core=0.6 jupyter_server jupyterlite-xeus -c conda-forge -y;
3838
micromamba activate xeus-lite-host;
3939
python -m pip install jupyterlite-xeus jupyter_server;
40-
jupyter lite build --XeusAddon.prefix=$PREFIX \\
40+
jupyter lite build --settings-overrides=overrides.json \\
41+
--XeusAddon.prefix=$PREFIX \\
4142
--XeusAddon.mounts="$PREFIX/share/xeus-cpp/tagfiles:/share/xeus-cpp/tagfiles" \
4243
--XeusAddon.mounts="$PREFIX/etc/xeus-cpp/tags.d:/etc/xeus-cpp/tags.d" \
4344
--contents notebooks/xeus-cpp-lite-demo.ipynb \\

notebooks/xeus-cpp-lite-demo.ipynb

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -585,8 +585,14 @@
585585
"metadata": {
586586
"trusted": true
587587
},
588-
"outputs": [],
589-
"execution_count": null
588+
"outputs": [
589+
{
590+
"output_type": "stream",
591+
"name": "stdin",
592+
"text": " Smudge\n"
593+
}
594+
],
595+
"execution_count": 29
590596
},
591597
{
592598
"id": "8ec65830-4cb5-4d01-a860-f6c46ac4f60f",
@@ -595,8 +601,24 @@
595601
"metadata": {
596602
"trusted": true
597603
},
604+
"outputs": [
605+
{
606+
"name": "stdout",
607+
"output_type": "stream",
608+
"text": "Your name is Smudge"
609+
}
610+
],
611+
"execution_count": 30
612+
},
613+
{
614+
"id": "e4ad61d7-092c-49f6-98a7-6449fd74d731",
615+
"cell_type": "code",
616+
"source": "",
617+
"metadata": {
618+
"trusted": true
619+
},
598620
"outputs": [],
599621
"execution_count": null
600622
}
601623
]
602-
}
624+
}

overrides.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"@jupyterlab/notebook-extension:panel": {
3+
"toolbar": [
4+
{
5+
"name": "download",
6+
"label": "Download",
7+
"args": {},
8+
"command": "docmanager:download",
9+
"icon": "ui-components:download",
10+
"rank": 50
11+
}
12+
]
13+
}
14+
}

0 commit comments

Comments
 (0)