Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate pyodide repodata, add more mocks #27

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ jobs:
- name: Upload test config
uses: actions/upload-artifact@v3
with:
name: pyproject-toml
path: pyproject.toml
name: test-assets
path: |
pyproject.toml
examples
if-no-files-found: error

test:
Expand Down Expand Up @@ -145,7 +147,7 @@ jobs:
- uses: actions/download-artifact@v3
with:
name: pyproject-toml
name: test-assets

- name: Install test deps
run: |-
Expand All @@ -157,6 +159,8 @@ jobs:
jupyter labextension list 2>&1 | grep -ie "@jupyterlite/pyodide-kernel.*OK"
- name: Run the tests
env:
LITE_PYODIDE_KERNEL_DEMO: ./examples
run: pytest

- name: Upload reports
Expand Down
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ node_modules/
*.egg-info/
.ipynb_checkpoints
*.tsbuildinfo
jupyterlite_pyodide_kernel/labextension
src/jupyterlite_pyodide_kernel/labextension
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to move this folder in this PR? Are we expected more Python packages to be added to the repo later?

Would need to check how the releaser handles that. It probably breaks it without extra config.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to keep jupyterlite_pyodider_kernel to the top-level for now until we really need to move it down to a nested src folder or similar.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The src layout is widely used in a lot of packages, but i'll grant i haven't used it with the releaser.

This avoids the possibility of it shadowing the as-installed package in site-packages. For some of the coverage stuff to work, it took weird junk like deleting the source and forcing a non--e . install.

This layout is supported by the all the build backends at this point, and releaser probably needs to be updated, if it can't yet do that.

It is weird that PEP 621 doesn't have a canonical place that information, but that's the brave new world.

Copy link
Member

@jtpio jtpio Mar 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. For now it's probably just going to create more issues. Happy to reconsider it if we track that in another issue. So the releaser config can properly be handled.

But for now it would be nice to keep it at the top-level so we can continue making releases (also it's not really related to the main change of this PR).


# Created by https://www.gitignore.io/api/python
# Edit at https://www.gitignore.io/?templates=python
Expand Down Expand Up @@ -114,8 +114,8 @@ dmypy.json

# generated
packages/pyodide-kernel/pypi/
packages/pyodide-kernel/pypi/all.json
packages/pyodide-kernel/pypi/*.json
_pypi.ts
.jupyterlite.doit.db
_output
jupyterlite_pyodide_kernel/tests/fixtures/.pyodide*/
src/jupyterlite_pyodide_kernel/tests/fixtures/.pyodide*/
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ node_modules/
**/node_modules
**/lib
**/package.json
jupyterlite_pyodide_kernel/labextension/
src/jupyterlite_pyodide_kernel/labextension/
**/.pyodide/
.pytest_cache/
docs/
Expand All @@ -13,3 +13,4 @@ CHANGELOG.md
# generated
_pypi.ts
**/pypi/all.json
**/pypi/repodata.json
13 changes: 3 additions & 10 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,16 @@ build:
nodejs: '18'
apt_packages:
- libarchive-dev

jobs:
pre_build:
- python -m pip install -r requirements-dev.txt
- jlpm --frozen-lockfile
- jlpm build
- jlpm build:prod
- jlpm dev
- jlpm dist
# pre-build the lite site to isolate build errors
- jlpm docs:lite

python:
install:
- method: pip
path: .
extra_requirements:
- dev
- docs

sphinx:
builder: html
configuration: docs/conf.py
Expand Down
295 changes: 233 additions & 62 deletions examples/intro.ipynb
Original file line number Diff line number Diff line change
@@ -1,63 +1,234 @@
{
"metadata": {
"kernelspec": {
"name": "python",
"display_name": "Python (Pyodide)",
"language": "python"
},
"language_info": {
"codemirror_mode": {
"name": "python",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8"
}
},
"nbformat_minor": 5,
"nbformat": 4,
"cells": [
{
"cell_type": "markdown",
"source": "# Introduction to `jupyterlite-pyodide-kernel`\n\n`jupyterlite-pyodide-kernel` extends [JupyterLite](https://jupyterlite.rtfd.io) with a Python 3 kernel, powered by [Pyodide](https://pyodide.org/).",
"metadata": {},
"id": "ab1dc4ef-36ae-4893-8fb4-474440fabc8a"
},
{
"cell_type": "markdown",
"source": "## Visualizing data in a Notebook ✨\n\nBelow is an example of a code cell. We'll visualize some simple data using two popular\npackages in Python. We'll use [NumPy](https://numpy.org/) to create some random data,\nand [Matplotlib](https://matplotlib.org) to visualize it.\n\nNote how the code and the results of running the code are bundled together.",
"metadata": {},
"id": "a6372e17-bf46-48c5-90a3-bdd6236e376e"
},
{
"cell_type": "code",
"source": "from matplotlib import pyplot as plt\nimport numpy as np\n\n# Generate 100 random data points along 3 dimensions\nx, y, scale = np.random.randn(3, 100)\nfig, ax = plt.subplots()\n\n# Map each onto a scatterplot we'll create with Matplotlib\nax.scatter(x=x, y=y, c=scale, s=np.abs(scale) * 500)\nax.set(title=\"Some random data, created with JupyterLab!\")\nplt.show()",
"metadata": {
"trusted": true
},
"execution_count": null,
"outputs": [],
"id": "fe55883a-6887-43dd-9498-5333a51799e2"
},
{
"cell_type": "markdown",
"source": "## Interact with Widgets 🎛️\n\n[Jupyter Widgets](https://jupyter.org/widgets) power rich interactivity between users of Jupyter clients and Jupyter kernels. With `jupyterlab_widgets` installed, all of the [core widgets](https://ipywidgets.readthedocs.io/en/latest/examples/Widget%20List.html) will work in `jupyterlite-pyodide-kernel`, as do many third-party packages.",
"metadata": {},
"id": "61bd8fda-3e36-4910-b319-668e8843f322"
},
{
"cell_type": "code",
"source": "%pip install ipywidgets\nfrom ipywidgets import *\nslider = FloatSlider()\nreadout = FloatText()\njslink((slider, \"value\"), (readout, \"value\"))\nHBox([slider, readout])",
"metadata": {
"trusted": true
},
"execution_count": null,
"outputs": [],
"id": "b034c439-aea0-4880-9118-75f7a2b1092a"
}
]
}
"cells": [
{
"cell_type": "markdown",
"id": "ab1dc4ef-36ae-4893-8fb4-474440fabc8a",
"metadata": {},
"source": [
"# Introduction to `jupyterlite-pyodide-kernel`\n",
"\n",
"[`jupyterlite-pyodide-kernel`](https://github.com/jupyterlite/pyodide-kernel) extends [JupyterLite](https://jupyterlite.rtfd.io) with a Python 3 kernel, powered by [Pyodide](https://pyodide.org/) and [IPython](https://ipython.readthedocs.io).\n",
"\n",
"> _ℹ️ Use the ▸ button, or <kbd>shift+enter</kbd> to run cells below_"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "db046898-d539-444b-a1e2-e95b4b40d989",
"metadata": {},
"outputs": [],
"source": [
"import this"
]
},
{
"cell_type": "markdown",
"id": "edd8be2c-16a1-47c5-ae5d-7b70ff3938b2",
"metadata": {},
"source": [
"### Example: Interactive Widgets\n",
"\n",
"[Jupyter Widgets](https://jupyter.org/widgets) power rich interactivity between users of Jupyter clients and Jupyter kernels. With `jupyterlab_widgets` installed, all of the [core widgets](https://ipywidgets.readthedocs.io/en/latest/examples/Widget%20List.html) will work in `jupyterlite-pyodide-kernel`, as do many third-party packages.\n",
"\n",
"> ⚠️ _`ipywidgets` _and_ `jupyterlab_widgets` were included at **build time** of this site, and are **not** available by default when installing `jupyterlite-pyodide-kernel`._"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b034c439-aea0-4880-9118-75f7a2b1092a",
"metadata": {},
"outputs": [],
"source": [
"from ipywidgets import *\n",
"slider = FloatSlider()\n",
"readout = FloatText()\n",
"jslink((slider, \"value\"), (readout, \"value\"))\n",
"HBox([slider, readout])"
]
},
{
"cell_type": "markdown",
"id": "cd2f8599-4985-4db7-8f75-e447cb4801fc",
"metadata": {},
"source": [
"## What is JupyterLite?\n",
"\n",
"JupyterLite is a **limited** implementation of the [Jupyter architecture](https://jupyter.org).\n",
"\n",
"Like the tradtional JupyterLab client/server stack of **tools for interactive computing**, it provides:\n",
"- a subset of the [Jupyter **Server** API](https://jupyter-server.readthedocs.io/en/latest/developers/rest-api.html), implemented in JavaScript\n",
"- browser-based **kernels**, like JupyterLite Pyodide Kernel, which run entirely in the browser\n",
"- a Jupyter browser **client** based on [JupyterLab](https://jupyterlab.readthedocs.io) and many of its [extensions](https://pypi.org/search/?q=&o=&c=Framework+%3A%3A+Jupyter+%3A%3A+JupyterLab+%3A%3A+Extensions+%3A%3A+Prebuilt)\n",
"- the Jupyter [Notebook **format**](https://nbformat.readthedocs.io)"
]
},
{
"cell_type": "markdown",
"id": "b559d0e6-03bf-4706-b5f5-4fd1ef5c0a36",
"metadata": {},
"source": [
"## What is Pyodide?\n",
"\n",
"Pyodide is a distribution of [CPython](https://github.com/python/cpython), compiled to [WebAssembly](https://webassembly.org) with [Emscripten](https://emscripten.org) which runs entirely within the browser."
]
},
{
"cell_type": "markdown",
"id": "ddcc1b90-cbaf-422b-915e-448be20617cd",
"metadata": {},
"source": [
"## What _can't_ it do?\n",
"\n",
"While a very broad subset of the CPython standard library, and much of the open source, scientific Python ecosystem are available, there are some limitation.\n",
"\n",
"The best way to find out is to **try it out**! However, some known implementation-level limitations are listed below."
]
},
{
"cell_type": "markdown",
"id": "f2a6e1fc-589f-46f5-aef5-1878c476a213",
"metadata": {},
"source": [
"### Differences from CPython\n",
"\n",
"A number of aspects of the underlying Python implementation that don't work the same way as their upstream counterparts, if at all. Uses of these features will need to be updated, or put behind some check.\n",
"\n",
"- no threads\n",
"- no subprocesses\n",
"- no custom event asynchronous loops\n",
"- package `data_files` are not installed\n",
"- some blocking features are made asynchronous\n",
" - `input` must be `await`ed\n",
" - the `urllib` family of HTTP features don't work\n",
" - though [pyodide-http](https://github.com/koenvo/pyodide-http) can be explicitly installed, imported and used"
]
},
{
"cell_type": "markdown",
"id": "961bb18f-954b-4624-bf85-774d451addec",
"metadata": {},
"source": [
"### Differences from `IPython` and `ipykernel`\n",
"\n",
"`jupyterlite-pyodide-kernel` ships a _shim_ of `ipykernel`, and changes a number of features in `ipython`\n",
"\n",
"- many [magics](https://ipython.readthedocs.io/en/stable/interactive/magics.html) don't work"
]
},
{
"cell_type": "markdown",
"id": "896da1d0-f51b-4c76-a25a-c448455e4960",
"metadata": {},
"source": [
"### Differences from Pyodide\n",
"Because `jupyterlite-pyodide-kernel` runs inside a [WebWorker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers), a number of features don't work (yet).\n",
"\n",
"- no access to the browser's DOM\n",
" - in particular, the Pyodide [matplotlib](https://github.com/pyodide/matplotlib-pyodide) backend will not work"
]
},
{
"cell_type": "markdown",
"id": "75187813-fe26-47d6-84c2-eb5f4ac4bd91",
"metadata": {},
"source": [
"## Where are all the Pyodide packages?\n",
"\n",
"This site follows the pattern for an [offline site](https://jupyterlite.readthedocs.io/en/0.1.0-beta/howto/configure/advanced/offline.html) based on a minimal, but fully self-contained, distribution of Pyodide. \n",
"\n",
"This means:\n",
"- no additional resources are loaded from any other sites on the internet\n",
" - serving from a content delivery network (CDN) is often faster, but _could_ disappear or change in the future \n",
"- only the Python 3.10 standard library is available by default\n",
"\n",
"> ℹ️ For a more full-featured site with full Pyodide distributions, hosted from a CDN, see: \n",
">\n",
"> - the JupyterLite [documentation](https://jupyterlite.readthedocs.io) on [ReadTheDocs](https://jupyterlite.readthedocs.io/en/0.1.0-beta/reference/demo.html)\n",
"> - the JupyterLite [demo](https://jupyterlite.github.io/demo) on [GitHub Pages](https://jupyterlite.readthedocs.io/en/0.1.0-beta/quickstart/deploy.html)"
]
},
{
"cell_type": "markdown",
"id": "5aaff9a8-9dfa-4180-8c9f-a2930557b3b2",
"metadata": {},
"source": [
"## How do I use more Python packages?\n",
"\n",
"Simple python packages can be installed at runtime through one of the following methods.\n",
"\n",
"> ℹ️ Learn more on the [JupyterLite documentation](https://jupyterlite.readthedocs.io/en/latest/howto/python/packages.html), including how to make more packages available."
]
},
{
"cell_type": "markdown",
"id": "4a9ffff0-e38c-47cf-b991-40dd17359b0c",
"metadata": {},
"source": [
"### At runtime\n",
"\n",
"Packages not added (or known of) at build time can be imported with the [`%pip`](https://ipython.readthedocs.io/en/stable/interactive/magics.html#magic-pip) magic. This gives site visitors the freedom to explore beyond what a site builder even imagined at build time."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2154019e-bd81-4313-a88a-445c5cf673f9",
"metadata": {},
"outputs": [],
"source": [
"%pip install -q emoji"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "68b2607f-035c-48f9-ab21-316228085644",
"metadata": {},
"outputs": [],
"source": [
"import emoji\n",
"b, m, s = \":badger:\", \":mushroom:\", \":snake:\"\n",
"emoji.emojize(3 * (b * 12 + m * 2) + s * 3)"
]
},
{
"cell_type": "markdown",
"id": "58aa75f7-6f13-4c08-a83d-2b776116db7e",
"metadata": {},
"source": [
"## How do I use more client extension packages?\n",
"\n",
"Some python packages, like all Jupyter widgets, will require client extensions, and need to be available when the site loads for a site visitor.\n",
"\n",
"Any number of JupyterLab [extensions]() can be [added at **build time**](https://jupyterlite.readthedocs.io/en/latest/howto/configure/simple_extensions.html), but not all will be compatible:\n",
"\n",
"- some extensions require a [Jupyter Server extension](https://jupyter-server.readthedocs.io/en/latest/developers/extensions.html)\n",
" - it is _possible_ to [extend the JupyterLite server](https://jupyterlite.readthedocs.io/en/latest/howto/extensions/server.html)\n",
"- some extensions require a different version of JupyterLab than the one JupyterLite is based on"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.0"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading