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

WIP: Support Pyodide in Jyve #12

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Experimental, unsafe Jupyter Kernels in the Browser... from anywhere.
- [Brython](./notebooks/Brython.ipynb)
- [TypeScript](./notebooks/TypeScript.ipynb)
- [P5](./notebooks/P5.ipynb)
- [Pyodide](./notebooks/Pyodide.ipynb)

## Convenience wrappers
- [PhosphorJS](./notebooks/Phosphor Playground.ipynb)
Expand Down Expand Up @@ -46,6 +47,7 @@ jupyter labextension install @deathbeds/jyve-js-unsafe-extension
jupyter labextension install @deathbeds/jyve-brython-unsafe-extension
jupyter labextension install @deathbeds/jyve-coffee-unsafe-extension
jupyter labextension install @deathbeds/jyve-p5-unsafe-extension
jupyter labextension install @deathbeds/jyve-pyodide-unsafe-extension
jupyter labextension install @deathbeds/jyve-typescript-unsafe-extension
# extra packages, wrapped for convenience in jyve kernels
jupyter labextension install @deathbeds/jyve-lyb-d3
Expand All @@ -61,6 +63,7 @@ jupyter labextension install \
@deathbeds/jyve-js-unsafe-extension \
@deathbeds/jyve-lyb-d3 \
@deathbeds/jyve-lyb-phosphor \
@deathbeds/jyve-pyodide-unsafe-extension \
@deathbeds/jyve-p5-unsafe-extension \
@deathbeds/jyve-typescript-unsafe-extension \
&& jupyter labextension list
Expand Down
3 changes: 2 additions & 1 deletion index.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
"- [CoffeeScript](./notebooks/CoffeeScript.ipynb)\n",
"- [TypeScript](./notebooks/TypeScript.ipynb)\n",
"- [Brython](./notebooks/Brython.ipynb)\n",
"- [P5](./nodebooks/P5.ipynb)"
"- [P5](./notebooks/P5.ipynb)\n",
"- [Pyodide](./notebooks/Pyodide.ipynb)\n"
]
},
{
Expand Down
282 changes: 282 additions & 0 deletions notebooks/Pyodide.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,282 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Pyodide\n",
"[Pyodide](https://www.pyodide.info/) is a port of the standard CPython implementation along with Numpy and Pandas to WebAssembly."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"text/plain": [
"\n"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"text/plain": []
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"print(1 + 1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"The Zen of Python, by Tim Peters\n",
"\n",
"Beautiful is better than ugly.\n",
"Explicit is better than implicit.\n",
"Simple is better than complex.\n",
"Complex is better than complicated.\n",
"Flat is better than nested.\n",
"Sparse is better than dense.\n",
"Readability counts.\n",
"Special cases aren't special enough to break the rules.\n",
"Although practicality beats purity.\n",
"Errors should never pass silently.\n",
"Unless explicitly silenced.\n",
"In the face of ambiguity, refuse the temptation to guess.\n",
"There should be one-- and preferably only one --obvious way to do it.\n",
"Although that way may not be obvious at first unless you're Dutch.\n",
"Now is better than never.\n",
"Although never is often better than *right* now.\n",
"If the implementation is hard to explain, it's a bad idea.\n",
"If the implementation is easy to explain, it may be a good idea.\n",
"Namespaces are one honking great idea -- let's do more of those!"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"text/plain": [
"\n"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"text/plain": []
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import this"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{0: '0', 1: '1', 2: '2', 3: '3', 4: '4', 5: '5', 6: '6', 7: '7', 8: '8', 9: '9'}"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"text/plain": [
"\n"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"text/plain": []
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"print({i: str(i) for i in range(10)})"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Pyodide can access the Web API by importing from the special module, `js`."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": []
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from js import window"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": []
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"window.document.write(\"Hi there!\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Numpy support\n",
"\n",
"Numpy is here."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import numpy\n",
"numpy.zeros((16, 16))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
Copy link
Contributor

Choose a reason for hiding this comment

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

I freaked out a little when i read this on my phone

"array([[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],\n",
" [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],\n",
" [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],\n",
" [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],\n",
" [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],\n",
" [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],\n",
" [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],\n",
" [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],\n",
" [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],\n",
" [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],\n",
" [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],\n",
" [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],\n",
" [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],\n",
" [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],\n",
" [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],\n",
" [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]])"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"repr(numpy.zeros((16, 16)))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Pyodide (unsafe) — Jyve",
"language": "python",
"name": "jyve-pyodide-unsafe"
},
"language_info": {
"codemirror_mode": {
"name": "python",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "python3",
"version": "ES2015"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
},
"scripts": {
"bootstrap": "jlpm && jlpm lerna bootstrap && jlpm clean && jlpm build && jlpm lab:link",
"build": "jlpm build:core && jlpm build:js && jlpm build:coffee && jlpm build:typescript && jlpm build:brython && jlpm build:p5 && jlpm build:ext && jlpm build:lyb",
"build": "jlpm build:core && jlpm build:js && jlpm build:coffee && jlpm build:typescript && jlpm build:brython && jlpm build:p5 && jlpm build:pyodide && jlpm build:ext && jlpm build:lyb",
Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, sorry, through no fault of yours this is getting bad... i think A Great Renaming must come, when we can use lerna scopes a bit to make this bad

"build:brython": "lerna run build --scope '@deathbeds/jyve-brython-unsafe'",
"build:coffee": "lerna run build --scope '@deathbeds/jyve-coffee-unsafe'",
"build:core": "lerna run build --scope '@deathbeds/jyve'",
Expand All @@ -44,6 +44,7 @@
"build:lyb": "lerna run build --scope '@deathbeds/jyve-lyb-*'",
"build:p5": "lerna run build --scope '@deathbeds/jyve-p5-unsafe'",
"build:typescript": "lerna run build --scope '@deathbeds/jyve-typescript-unsafe'",
"build:pyodide": "lerna run build --scope '@deathbeds/jyve-pyodide-unsafe'",
"clean": "lerna run --parallel clean",
"lab:build": "cd $CONDA_PREFIX/share/jupyter/lab/staging && jlpm build",
"lab:clean": "cd $CONDA_PREFIX/share/jupyter/lab/staging/build && rm `ls | grep -v index | grep -v error`",
Expand Down
22 changes: 22 additions & 0 deletions packages/jyve-pyodide-unsafe-extension/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

# @deathbeds/jyve-pyodide-unsafe-extension
> An extension for a totally unsafe browser pyodide kernel

## Before
```bash
conda install -c conda-forge jupyterlab nodejs
```
or
```
# get nodejs somehow ¯\_(ツ)_/¯
pip install jupyterlab
```

## Install
```bash
jupyter labextension install @deathbeds/jyve-pyodide-unsafe-extension
```


## Development
`@deathbeds/jyve-pyodide-unsafe-extension` is built as part of [Jyve](https://github.com/deathbeds/jyve).
Loading