From c70e12107821145224ad4a34b5bc8fe4ecff9a8b Mon Sep 17 00:00:00 2001 From: Madhur Tandon <20173739+madhur-tandon@users.noreply.github.com> Date: Tue, 4 Oct 2022 19:00:39 +0530 Subject: [PATCH] eliminate py-env altogether (#775) * examples use toml now * use 0.21.2 for now * change config in docs * fix pre-commit --- docs/_static/examples/what-is-pyscript.html | 10 +- docs/tutorials/getting-started.md | 103 +-------------- examples/altair.html | 10 +- examples/antigravity.html | 10 +- examples/bokeh.html | 13 +- examples/bokeh_interactive.html | 13 +- examples/folium.html | 8 +- examples/matplotlib.html | 6 +- examples/message_passing.html | 14 +- examples/micrograd_ai.html | 10 +- examples/numpy_canvas_fractals.html | 26 ++-- examples/panel.html | 14 +- examples/panel_deckgl.html | 17 ++- examples/panel_kmeans.html | 19 ++- examples/panel_stream.html | 17 ++- examples/repl.html | 11 +- examples/repl2.html | 21 ++- examples/simple_clock.html | 6 +- examples/todo-pylist.html | 6 +- examples/todo.html | 6 +- examples/toga/freedom.html | 16 +-- pyscriptjs/package-lock.json | 134 +++++++++----------- pyscriptjs/package.json | 2 - pyscriptjs/src/components/pyenv.ts | 82 ------------ pyscriptjs/src/main.ts | 2 - pyscriptjs/src/pyodide.ts | 2 +- pyscriptjs/src/utils.ts | 2 +- 27 files changed, 193 insertions(+), 387 deletions(-) delete mode 100644 pyscriptjs/src/components/pyenv.ts diff --git a/docs/_static/examples/what-is-pyscript.html b/docs/_static/examples/what-is-pyscript.html index d4264d22..e469bf61 100644 --- a/docs/_static/examples/what-is-pyscript.html +++ b/docs/_static/examples/what-is-pyscript.html @@ -16,10 +16,12 @@ } } - - - numpy - - matplotlib - + + packages = [ + "numpy", + "matplotlib" + ] + diff --git a/docs/tutorials/getting-started.md b/docs/tutorials/getting-started.md index c281b487..2c14b176 100644 --- a/docs/tutorials/getting-started.md +++ b/docs/tutorials/getting-started.md @@ -258,9 +258,12 @@ OR in JSON like ``` If your `.whl` is not a pure Python wheel, then open a PR or issue with [pyodide](https://github.com/pyodide/pyodide) to get it added [here](https://github.com/pyodide/pyodide/tree/main/packages). + If there's enough popular demand, the pyodide team will likely work on supporting your package. Regardless, things will likely move faster if you make the PR and consult with the team to get unblocked. + For example, NumPy and Matplotlib are available. Notice here we're using `` as a shortcut, which takes the expression on the last line of the script and runs `pyscript.write('plot', fig)`. + ```html @@ -290,9 +293,11 @@ as a shortcut, which takes the expression on the last line of the script and run ``` ### Local modules + In addition to packages, you can declare local Python modules that will be imported in the `` tag. For example, we can place the random number generation steps in a function in the file `data.py`. + ```python # data.py import numpy as np @@ -377,104 +382,6 @@ OR in JSON like If this `"magic"` key is present in config supplied via `src` and also present in config supplied via `inline`, then the value in the inline config is given priority i.e. the overriding process also works for custom keys. -## The py-env tag (Deprecated) - -**The tag is deprecated as of `2022.09.1` release but you can still use the functionality explained below. It will be removed in the next release. To specify packages in the recommended way, please see the section.** - -In addition to the [Python Standard Library](https://docs.python.org/3/library/) and -the `pyscript` module, many 3rd-party OSS packages will work out-of-the-box with PyScript. - -In order to use them, you will need to declare the dependencies using the `` tag in the -HTML head. You can also link to `.whl` files directly on disk like in our [toga example](https://github.com/pyscript/pyscript/blob/main/examples/toga/freedom.html). - -``` - -- './static/wheels/travertino-0.1.3-py3-none-any.whl' - -``` - -If your `.whl` is not a pure Python wheel, then open a PR or issue with [pyodide](https://github.com/pyodide/pyodide) to get it added [here](https://github.com/pyodide/pyodide/tree/main/packages). -If there's enough popular demand, the pyodide team will likely work on supporting your package. Regardless, things will likely move faster if you make the PR and consult with the team to get unblocked. - -For example, NumPy and Matplotlib are available. Notice here we're using `` -as a shortcut, which takes the expression on the last line of the script and runs `pyscript.write('plot', fig)`. - -```html - - - - - - - numpy - - matplotlib - - - - -

Let's plot random numbers

-
- - import matplotlib.pyplot as plt - import numpy as np - - x = np.random.randn(1000) - y = np.random.randn(1000) - - fig, ax = plt.subplots() - ax.scatter(x, y) - fig - - - -``` - -### Local modules with py-env (Deprecated) - -**The tag is deprecated as of `2022.09.1` release but you can still use the functionality explained below. It will be removed in the next release. To specify local modules in the recommended way, please see the section.** - -In addition to packages, you can declare local Python modules that will -be imported in the `` tag. For example, we can place the random -number generation steps in a function in the file `data.py`. -```python -# data.py -import numpy as np -def make_x_and_y(n): - x = np.random.randn(n) - y = np.random.randn(n) - return x, y -``` - -In the HTML tag ``, paths to local modules are provided in the -`paths:` key. - -```html - - - - - - - numpy - - matplotlib - - paths: - - ./data.py - - - - -

Let's plot random numbers

-
- - import matplotlib.pyplot as plt - from data import make_x_and_y - x, y = make_x_and_y(n=1000) - fig, ax = plt.subplots() - ax.scatter(x, y) - fig - - - -``` - ## The py-repl tag The `` tag creates a REPL component that is rendered to the page as a code editor, allowing you to write executable code inline. diff --git a/examples/altair.html b/examples/altair.html index 68b3b490..71fe3e3e 100644 --- a/examples/altair.html +++ b/examples/altair.html @@ -6,11 +6,11 @@ -packages = [ - "altair", - "pandas", - "vega_datasets" -] + packages = [ + "altair", + "pandas", + "vega_datasets" + ] diff --git a/examples/antigravity.html b/examples/antigravity.html index 611f6ea6..bf73bed9 100644 --- a/examples/antigravity.html +++ b/examples/antigravity.html @@ -5,12 +5,12 @@ + + paths = [ + "./antigravity.py" + ] + - -paths = [ - "./antigravity.py" -] - Based on xkcd: antigravity https://xkcd.com/353/. diff --git a/examples/bokeh.html b/examples/bokeh.html index 44380afa..b7c41f5e 100644 --- a/examples/bokeh.html +++ b/examples/bokeh.html @@ -14,15 +14,14 @@ - + + packages = [ + "bokeh", + "numpy" + ] + - -packages = [ - "bokeh", - "numpy" -] -

Bokeh Example

diff --git a/examples/bokeh_interactive.html b/examples/bokeh_interactive.html index 7eb2fc60..2b73e16f 100644 --- a/examples/bokeh_interactive.html +++ b/examples/bokeh_interactive.html @@ -14,15 +14,14 @@ - + + packages = [ + "bokeh", + "numpy" + ] + - -packages = [ - "bokeh", - "numpy" -] -

Bokeh Example

diff --git a/examples/folium.html b/examples/folium.html index a3aeb4c2..d698e081 100644 --- a/examples/folium.html +++ b/examples/folium.html @@ -6,10 +6,10 @@ -packages = [ - "folium", - "pandas" -] + packages = [ + "folium", + "pandas" + ] diff --git a/examples/matplotlib.html b/examples/matplotlib.html index 205efa14..bf363edf 100644 --- a/examples/matplotlib.html +++ b/examples/matplotlib.html @@ -6,9 +6,9 @@ -packages = [ - "matplotlib" -] + packages = [ + "matplotlib" + ] diff --git a/examples/message_passing.html b/examples/message_passing.html index 329810d6..d9aa6e30 100644 --- a/examples/message_passing.html +++ b/examples/message_passing.html @@ -4,16 +4,16 @@ + + packages = [ + "numpy", + "networkx", + "matplotlib" + ] + - -packages = [ - "numpy", - "networkx", - "matplotlib" -] - import numpy as np import networkx as nx diff --git a/examples/micrograd_ai.html b/examples/micrograd_ai.html index a31a272b..1bc92c10 100644 --- a/examples/micrograd_ai.html +++ b/examples/micrograd_ai.html @@ -10,11 +10,11 @@ -packages = [ - "micrograd", - "numpy", - "matplotlib" -] + packages = [ + "micrograd", + "numpy", + "matplotlib" + ] diff --git a/examples/numpy_canvas_fractals.html b/examples/numpy_canvas_fractals.html index 98588f1f..39c76658 100644 --- a/examples/numpy_canvas_fractals.html +++ b/examples/numpy_canvas_fractals.html @@ -28,6 +28,19 @@ } + + { + "packages": [ + "numpy", + "sympy" + ], + "paths": [ + "./palettes.py", + "./fractals.py" + ] + } + + @@ -78,19 +91,6 @@ - -{ - "packages": [ - "numpy", - "sympy" - ], - "paths": [ - "./palettes.py", - "./fractals.py" - ] -} - - from pyodide.ffi import to_js, create_proxy diff --git a/examples/panel.html b/examples/panel.html index 78dedf76..d417fdf7 100644 --- a/examples/panel.html +++ b/examples/panel.html @@ -9,14 +9,14 @@ + + packages = [ + "bokeh", + "numpy", + "panel==0.13.1" + ] + - -packages = [ - "bokeh", - "numpy", - "panel==0.13.1" -] -

Panel Example

diff --git a/examples/panel_deckgl.html b/examples/panel_deckgl.html index c387d3bb..f7d5f87e 100644 --- a/examples/panel_deckgl.html +++ b/examples/panel_deckgl.html @@ -40,17 +40,16 @@ + + packages = [ + "bokeh", + "numpy", + "pandas", + "panel==0.13.1" + ] + - -packages = [ - "bokeh", - "numpy", - "pandas", - "panel==0.13.1" -] - -