Merge branch 'main' into 'live-code'

# Conflicts:
#   book/features/live_code.md
This commit is contained in:
Tom van Woudenberg 2024-03-11 09:34:24 +01:00
commit 41cff8359d
5 changed files with 9 additions and 13 deletions

View file

@ -10,8 +10,6 @@
"\n",
"A function has been made to check the value of a variable. As input values it takes the variable name, the expected value (correct answer) and how these values should be compared. You need to add this function to each page, including the imports, and add the `thebe-remove-input-init` tag to the cell.\n",
"```python\n",
"import micropip\n",
"await micropip.install(\"ipywidgets\")\n",
"import ipywidgets as widgets\n",
"from IPython.display import display\n",
"import operator\n",
@ -46,8 +44,6 @@
},
"outputs": [],
"source": [
"import micropip\n",
"await micropip.install(\"ipywidgets\")\n",
"import ipywidgets as widgets\n",
"from IPython.display import display\n",
"import operator\n",

View file

@ -11,7 +11,7 @@ You can install these using `pip`. Make sure these are also defined in the `requ
There are multiple Python kernels available that work in the browser. Two popular ones are [Pyodide] and [`Xeus-Python`]. The latter allows you to install packages from `conda-forge` during build time, making them immediately available on your website. In this example, `Xeus-Python` will be used.
When you have installed `jupyterlite-xeus-python`, the kernel will automatically be included in the build without any configuration. However, the default kernel only comes with `numpy`, and we want to make sophisticated interactive content, for example with `matplotlib` and `ipywidgets`. `Xeus-Python` can install these packages itself with `conda`. All we need to do is give it a list of the packages we want installed. To this end, we need to make a configuration file for `jupyterlite` containing settings that will be passed to `Xeus-Python`. The configuration file needs to be in JSON format, and needs to be placed in the root directory of your repository (where `requirements.txt` and `.gitlab-ci.yml` live). In this file, we can specify which packages need to be installed in the kernel as follows:
When you have installed `jupyterlite-xeus-python`, the kernel will automatically be included in the build without any configuration. However, the default kernel only comes with `numpy`, and we want to make sophisticated interactive content, for example with `matplotlib` and `ipywidgets`. `Xeus-Python` can install these packages itself with `conda`. All we need to do is give it a list of the packages we want installed. To this end, we need to make a configuration file for `jupyterlite` containing settings that will be passed to `Xeus-Python`. The configuration file needs to be in JSON format, and needs to be placed in the root directory of your book (where `_config.yml` lives). In this file, we can specify which packages need to be installed in the kernel as follows:
{
"XeusPythonEnv": {

View file

@ -8,25 +8,25 @@ To set up the Python live coding you need to add our [own sphinx-thebe extension
For `requirements.txt` add the following lines:
```
--extra-index-url https://gitlab.tudelft.nl/api/v4/projects/11239/packages/pypi/simple
sphinx-thebe == 0.2.1000
sphinx-thebe ~= 0.9.9
```
This will download the correct version of the sphinx extension when the book is build on the server (which loads the required packages from `requirements.txt`)
Afterwards, this sphinx extension needs to be enabled in your book. This can be done by adding the following lines to `_config.yml`:
```
launch_buttons:
thebe: true
sphinx:
html_js_files:
- https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js
thebe_config:
use_thebe_lite: true
exclude_patterns: ["**/_*.yml", "**/*.md", "**/*.ipynb"]
html_theme_options:
launch_buttons:
thebe: true
```
By `launch_buttons` you initiate the {fa}`rocket` --> {guilabel}`Live Code` on the top right corner of every page generated from a `.ipynb` file. The `html_js_files` link calls for some required javascript files. `use_thebe_lite` makes sure you initiate our adapted sphinx thebe extensions. The `exclude_patterns` makes sure you import all files so that they can be accessed from your code, except for the files matching the patterns shown.
The `html_js_files` link calls for some required javascript files. `use_thebe_lite` makes sure you initiate our adapted sphinx thebe extensions. The `exclude_patterns` makes sure you import all files so that they can be accessed from your code, except for the files matching the patterns shown. By `launch_buttons` you initiate the {fa}`rocket` --> {guilabel}`Live Code` on the top right corner of every page generated from a `.ipynb` file. As opposed to the jupyter book documentation, this button has to be specified from within `sphinx: html_theme_options` where you might also specify other buttons as well (ie. the [code repository button](https://jupyterbook.org/en/stable/basics/repository.html)).
## Instructions: local build

View file

@ -0,0 +1,10 @@
{
"XeusPythonEnv": {
"packages": [
"numpy",
"matplotlib",
"ipywidgets",
"scipy"
]
}
}