Skip to content

Commit 617d487

Browse files
committed
Run xeus-cpp-lite-demo.ipynb in ci and test output for Safari, Chrome and Firefox
1 parent 778e639 commit 617d487

File tree

12 files changed

+640
-25
lines changed

12 files changed

+640
-25
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: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -139,21 +139,29 @@ jobs:
139139
fi
140140
timeout-minutes: 4
141141

142-
- name: Jupyter Lite integration
143-
shell: bash -l {0}
144-
run: |
145-
micromamba create -n xeus-lite-host jupyterlite-core=0.6 jupyter_server jupyterlite-xeus -c conda-forge
146-
micromamba activate xeus-lite-host
147-
jupyter lite build \
148-
--XeusAddon.prefix=${{ env.PREFIX }} \
149-
--XeusAddon.mounts="${{ env.PREFIX }}/share/xeus-cpp/tagfiles:/share/xeus-cpp/tagfiles" \
150-
--XeusAddon.mounts="${{ env.PREFIX }}/etc/xeus-cpp/tags.d:/etc/xeus-cpp/tags.d" \
151-
--contents README.md \
152-
--contents notebooks/xeus-cpp-lite-demo.ipynb \
153-
--contents notebooks/tinyraytracer.ipynb \
154-
--contents notebooks/images/marie.png \
155-
--contents notebooks/audio/audio.wav \
156-
--output-dir dist
142+
- name: Serve Jupyter Lite website
143+
uses: ./.github/actions/Jupyter-serve
144+
145+
- name: Test C++17 kernel in xeus-cpp-lite-demo.ipynb
146+
uses: ./.github/actions/Emscripten-Notebook-Tests
147+
with:
148+
notebook: "xeus-cpp-lite-demo.ipynb"
149+
kernel: "C++17"
150+
timeout-minutes: 5
151+
152+
- name: Test C++20 kernel in xeus-cpp-lite-demo.ipynb
153+
uses: ./.github/actions/Emscripten-Notebook-Tests
154+
with:
155+
notebook: "xeus-cpp-lite-demo.ipynb"
156+
kernel: "C++20"
157+
timeout-minutes: 5
158+
159+
- name: Test C++23 kernel in xeus-cpp-lite-demo.ipynb
160+
uses: ./.github/actions/Emscripten-Notebook-Tests
161+
with:
162+
notebook: "xeus-cpp-lite-demo.ipynb"
163+
kernel: "C++23"
164+
timeout-minutes: 5
157165

158166
- name: Upload artifact
159167
uses: actions/upload-pages-artifact@v3

.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
@@ -164,4 +164,43 @@ jupyter lite serve --XeusAddon.prefix=$PREFIX \
164164
--contents notebooks/tinyraytracer.ipynb \
165165
--contents notebooks/images/marie.png \
166166
--contents notebooks/audio/audio.wav
167+
168+
### xeus-cpp Jupyter Lite tests
169+
170+
It is possible to run test the xeus-cpp in Jupyter Lite deployment, using a Selenium based script and the nbdiff Jupyter tool.
171+
In order to install these dependencies execute the following (you will need the Jupyter Lite website running in the background when
172+
executing the python script)
173+
174+
```bash
175+
python -m pip install nbdime==3.2.0 selenium
176+
```
177+
178+
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)
179+
180+
```bash
181+
python -u scripts/automated-notebook-run-script.py --driver browser --notebook notebook --kernel kernel --stdin Test_Input --timeout timeout
182+
```
183+
184+
For example
185+
186+
```bash
187+
python -u scripts/automated-notebook-run-script.py --driver chrome --notebook xeus-cpp-lite-demo.ipynb --kernel C++20 --stdin Smudge --timeout 200
188+
```
189+
190+
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,
191+
and stop the script, if the notebook has finished running after 200 seconds. This works for Safari, Chrome and Firefox. It should be noted
192+
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
193+
executing you can compare the notebook download from the one in the repo, to check the deployment works as expected, by executing
194+
(replace notebook_run with the notebook chosen for the Python script)
195+
196+
```bash
197+
nbdiff notebook_run $HOME/Downlaods/notebook_run --ignore-id --ignore-metadata
198+
```
199+
200+
For example after running the above test command, to test no changes have occurred, execute
201+
202+
```bash
203+
nbdiff xeus-cpp-lite-demo.ipynb $HOME/Downlaods/xeus-cpp-lite-demo.ipynb --ignore-id --ignore-metadata
204+
```
205+
167206
```

README.md

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

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

186224
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
@@ -162,6 +162,46 @@ To build and test Jupyter Lite with this kernel locally you can execute the foll
162162
--contents notebooks/images/marie.png \
163163
--contents notebooks/audio/audio.wav
164164
165+
xeus-cpp Jupyter Lite tests
166+
========================
167+
168+
It is possible to run test the xeus-cpp in Jupyter Lite deployment, using a Selenium based script and the nbdiff Jupyter tool.
169+
In order to install these dependencies execute the following (you will need the Jupyter Lite website running in the background when
170+
executing the python script)
171+
172+
.. code-block:: bash
173+
174+
python -m pip install nbdime==3.2.0 selenium
175+
176+
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)
177+
178+
.. code-block:: bash
179+
180+
python -u scripts/automated-notebook-run-script.py --driver browser --notebook notebook --kernel kernel --stdin Test_Input --timeout timeout
181+
182+
For example
183+
184+
.. code-block:: bash
185+
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+
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,
189+
and stop the script, if the notebook has finished running after 200 seconds. This works for Safari, Chrome and Firefox. It should be noted
190+
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
191+
executing you can compare the notebook download from the one in the repo, to check the deployment works as expected, by executing
192+
(replace notebook_run with the notebook chosen for the Python script)
193+
194+
.. code-block:: bash
195+
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+
.. code-block:: bash
202+
203+
nbdiff xeus-cpp-lite-demo.ipynb $HOME/Downlaods/xeus-cpp-lite-demo.ipynb --ignore-id --ignore-metadata
204+
165205
Installing from conda-forge
166206
===========================
167207

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)