From 4dd1dc28b18f571a489aad2e70a9385686d5f0da Mon Sep 17 00:00:00 2001
From: Madhur Tandon <20173739+madhur-tandon@users.noreply.github.com>
Date: Wed, 5 Oct 2022 01:13:34 +0530
Subject: [PATCH] move py-config between body tags (#827)
---
docs/_static/examples/what-is-pyscript.html | 14 ++++---
docs/tutorials/getting-started.md | 20 +++++-----
examples/altair.html | 14 +++----
examples/antigravity.html | 4 +-
examples/bokeh.html | 13 ++++---
examples/bokeh_interactive.html | 13 ++++---
examples/folium.html | 14 ++++---
examples/matplotlib.html | 12 +++---
examples/message_passing.html | 16 ++++----
examples/micrograd_ai.html | 17 ++++----
examples/numpy_canvas_fractals.html | 26 ++++++-------
examples/panel.html | 10 +++--
examples/panel_deckgl.html | 17 ++++----
examples/panel_kmeans.html | 19 ++++-----
examples/panel_stream.html | 17 ++++----
examples/repl.html | 10 ++---
examples/repl2.html | 20 +++++-----
examples/simple_clock.html | 10 ++---
examples/todo-pylist.html | 3 +-
examples/todo.html | 12 +++---
examples/toga/freedom.html | 18 +++++----
.../tests/integration/test_py_config.py | 39 +++++++++----------
22 files changed, 178 insertions(+), 160 deletions(-)
diff --git a/docs/_static/examples/what-is-pyscript.html b/docs/_static/examples/what-is-pyscript.html
index e469bf61..368cef20 100644
--- a/docs/_static/examples/what-is-pyscript.html
+++ b/docs/_static/examples/what-is-pyscript.html
@@ -16,12 +16,6 @@
}
}
-
- packages = [
- "numpy",
- "matplotlib"
- ]
-
@@ -31,6 +25,14 @@
❰py❱
+
+
+ packages = [
+ "numpy",
+ "matplotlib"
+ ]
+
+
import matplotlib.pyplot as plt
import numpy as np
diff --git a/docs/tutorials/getting-started.md b/docs/tutorials/getting-started.md
index 2c14b176..2b152c45 100644
--- a/docs/tutorials/getting-started.md
+++ b/docs/tutorials/getting-started.md
@@ -147,7 +147,7 @@ the `` tag to write to.
Use the `` tag to set and configure general metadata along with declaring dependencies for your PyScript application. The configuration has to be set in either TOML or JSON format. If you are unfamiliar with JSON, consider reading [freecodecamp's JSON for beginners](https://www.freecodecamp.org/news/what-is-json-a-json-file-example/) guide for more information. And for TOML, consider reading about it [here](https://learnxinyminutes.com/docs/toml/).
-The ideal place to use `` in between the `...` tags.
+The ideal place to use `` in between the `...` tags.
The `` tag can be used as follows:
@@ -269,16 +269,16 @@ as a shortcut, which takes the expression on the last line of the script and run
-
- {
- "packages": ["numpy", "matplotlib"]
- }
-
Let's plot random numbers
+
+ {
+ "packages": ["numpy", "matplotlib"]
+ }
+
import matplotlib.pyplot as plt
import numpy as np
@@ -315,15 +315,15 @@ In the HTML tag ``, paths to local modules are provided in the
-
- packages = ["numpy", "matplotlib"]
- paths = ["./data.py"]
-
Let's plot random numbers
+
+ packages = ["numpy", "matplotlib"]
+ paths = ["./data.py"]
+
import matplotlib.pyplot as plt
from data import make_x_and_y
diff --git a/examples/altair.html b/examples/altair.html
index 71fe3e3e..6a901e46 100644
--- a/examples/altair.html
+++ b/examples/altair.html
@@ -5,16 +5,16 @@
-
- packages = [
- "altair",
- "pandas",
- "vega_datasets"
- ]
-
+
+ packages = [
+ "altair",
+ "pandas",
+ "vega_datasets"
+ ]
+
import altair as alt
from vega_datasets import data
diff --git a/examples/antigravity.html b/examples/antigravity.html
index bf73bed9..fc0a4cf3 100644
--- a/examples/antigravity.html
+++ b/examples/antigravity.html
@@ -5,13 +5,13 @@
+
+
paths = [
"./antigravity.py"
]
-
-
Based on xkcd: antigravity https://xkcd.com/353/.
import antigravity
diff --git a/examples/bokeh.html b/examples/bokeh.html
index b7c41f5e..c4193b98 100644
--- a/examples/bokeh.html
+++ b/examples/bokeh.html
@@ -14,17 +14,18 @@
-
- packages = [
- "bokeh",
- "numpy"
- ]
-
Bokeh Example
+
+ packages = [
+ "bokeh",
+ "numpy"
+ ]
+
+
import json
import pyodide
diff --git a/examples/bokeh_interactive.html b/examples/bokeh_interactive.html
index 2b73e16f..ae9205a5 100644
--- a/examples/bokeh_interactive.html
+++ b/examples/bokeh_interactive.html
@@ -14,17 +14,18 @@
-
- packages = [
- "bokeh",
- "numpy"
- ]
-
Bokeh Example
+
+ packages = [
+ "bokeh",
+ "numpy"
+ ]
+
+
import asyncio
import json
diff --git a/examples/folium.html b/examples/folium.html
index d698e081..cb1d36b7 100644
--- a/examples/folium.html
+++ b/examples/folium.html
@@ -5,15 +5,17 @@
-
- packages = [
- "folium",
- "pandas"
- ]
-
+
+
+ packages = [
+ "folium",
+ "pandas"
+ ]
+
+
import folium
import json
diff --git a/examples/matplotlib.html b/examples/matplotlib.html
index bf363edf..a9abc63a 100644
--- a/examples/matplotlib.html
+++ b/examples/matplotlib.html
@@ -5,14 +5,16 @@
-
- packages = [
- "matplotlib"
- ]
-
+
+
+ packages = [
+ "matplotlib"
+ ]
+
+
import matplotlib.pyplot as plt
import matplotlib.tri as tri
diff --git a/examples/message_passing.html b/examples/message_passing.html
index d9aa6e30..9c3de342 100644
--- a/examples/message_passing.html
+++ b/examples/message_passing.html
@@ -4,16 +4,18 @@
-
- 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 1bc92c10..98bba1d9 100644
--- a/examples/micrograd_ai.html
+++ b/examples/micrograd_ai.html
@@ -9,19 +9,20 @@
-
- packages = [
- "micrograd",
- "numpy",
- "matplotlib"
- ]
-
-
Micrograd - A tiny Autograd engine (with a bite! :))
+
+
+ packages = [
+ "micrograd",
+ "numpy",
+ "matplotlib"
+ ]
+
+
Micrograd is a tiny Autograd engine created
diff --git a/examples/numpy_canvas_fractals.html b/examples/numpy_canvas_fractals.html
index 39c76658..ed0093a9 100644
--- a/examples/numpy_canvas_fractals.html
+++ b/examples/numpy_canvas_fractals.html
@@ -28,19 +28,6 @@
}
-
- {
- "packages": [
- "numpy",
- "sympy"
- ],
- "paths": [
- "./palettes.py",
- "./fractals.py"
- ]
- }
-
-
@@ -91,6 +78,19 @@
+
+ {
+ "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 d417fdf7..67415b01 100644
--- a/examples/panel.html
+++ b/examples/panel.html
@@ -9,6 +9,11 @@
+
+
+ Panel Example
+
+
packages = [
"bokeh",
@@ -16,10 +21,7 @@
"panel==0.13.1"
]
-
-
- Panel Example
-
+
import panel as pn
diff --git a/examples/panel_deckgl.html b/examples/panel_deckgl.html
index f7d5f87e..bcffe44c 100644
--- a/examples/panel_deckgl.html
+++ b/examples/panel_deckgl.html
@@ -40,14 +40,6 @@
-
- packages = [
- "bokeh",
- "numpy",
- "pandas",
- "panel==0.13.1"
- ]
-
@@ -77,6 +69,15 @@
+
+ packages = [
+ "bokeh",
+ "numpy",
+ "pandas",
+ "panel==0.13.1"
+ ]
+
+
import panel as pn
import pandas as pd
diff --git a/examples/panel_kmeans.html b/examples/panel_kmeans.html
index 4c06ab17..22a4598b 100644
--- a/examples/panel_kmeans.html
+++ b/examples/panel_kmeans.html
@@ -41,15 +41,6 @@
-
- packages = [
- "altair",
- "numpy",
- "pandas",
- "scikit-learn",
- "panel==0.13.1"
- ]
-
@@ -82,6 +73,16 @@
+
+ packages = [
+ "altair",
+ "numpy",
+ "pandas",
+ "scikit-learn",
+ "panel==0.13.1"
+ ]
+
+
import altair as alt
import panel as pn
diff --git a/examples/panel_stream.html b/examples/panel_stream.html
index 1bbda1d6..4883fadd 100644
--- a/examples/panel_stream.html
+++ b/examples/panel_stream.html
@@ -32,14 +32,6 @@
-
- packages = [
- "bokeh",
- "numpy",
- "pandas",
- "panel==0.13.1"
- ]
-
@@ -67,6 +59,15 @@
+
+ packages = [
+ "bokeh",
+ "numpy",
+ "pandas",
+ "panel==0.13.1"
+ ]
+
+
import panel as pn
import numpy as np
diff --git a/examples/repl.html b/examples/repl.html
index ba3979a9..33c5dfaa 100644
--- a/examples/repl.html
+++ b/examples/repl.html
@@ -9,17 +9,17 @@
-
- paths = [
- "./antigravity.py"
- ]
-
pyscript REPL
Tip: press Shift-ENTER to evaluate a cell
+
+ paths = [
+ "./antigravity.py"
+ ]
+
diff --git a/examples/repl2.html b/examples/repl2.html
index 91786c0e..1e632f43 100644
--- a/examples/repl2.html
+++ b/examples/repl2.html
@@ -11,20 +11,20 @@
-
- packages = [
- "bokeh",
- "numpy"
- ]
- paths = [
- "./utils.py",
- "./antigravity.py"
- ]
-
Custom REPL
+
+ packages = [
+ "bokeh",
+ "numpy"
+ ]
+ paths = [
+ "./utils.py",
+ "./antigravity.py"
+ ]
+
diff --git a/examples/simple_clock.html b/examples/simple_clock.html
index bc65f37c..e0686f54 100644
--- a/examples/simple_clock.html
+++ b/examples/simple_clock.html
@@ -10,17 +10,17 @@
-
- paths = [
- "./utils.py"
- ]
-
start time:
+
+ paths = [
+ "./utils.py"
+ ]
+
# demonstrates how use the global PyScript pyscript_loader
# to send operation log messages to it
diff --git a/examples/todo-pylist.html b/examples/todo-pylist.html
index 865b4633..5d15634f 100644
--- a/examples/todo-pylist.html
+++ b/examples/todo-pylist.html
@@ -9,12 +9,13 @@
+
+
paths = [
"./utils.py"
]
-
def add_task(*ags, **kws):
diff --git a/examples/todo.html b/examples/todo.html
index 7e47c390..32d50a20 100644
--- a/examples/todo.html
+++ b/examples/todo.html
@@ -10,15 +10,17 @@
-
- paths = [
- "./utils.py"
- ]
-
+
+
+ paths = [
+ "./utils.py"
+ ]
+
+
diff --git a/examples/toga/freedom.html b/examples/toga/freedom.html
index 2df84136..d2f41517 100644
--- a/examples/toga/freedom.html
+++ b/examples/toga/freedom.html
@@ -16,14 +16,6 @@
Loading...
-
- packages = [
- "./static/wheels/travertino-0.1.3-py3-none-any.whl",
- "./static/wheels/toga_core-0.3.0.dev33-py3-none-any.whl",
- "./static/wheels/toga_web-0.3.0.dev33-py3-none-any.whl",
- "./static/wheels/freedom-0.0.1-py3-none-any.whl"
- ]
-
Loading...
@@ -42,6 +34,16 @@
crossorigin="anonymous">
+
+
+ packages = [
+ "./static/wheels/travertino-0.1.3-py3-none-any.whl",
+ "./static/wheels/toga_core-0.3.0.dev33-py3-none-any.whl",
+ "./static/wheels/toga_web-0.3.0.dev33-py3-none-any.whl",
+ "./static/wheels/freedom-0.0.1-py3-none-any.whl"
+ ]
+
+
from toga_web.dom import handle as dom_handle
diff --git a/pyscriptjs/tests/integration/test_py_config.py b/pyscriptjs/tests/integration/test_py_config.py
index 7755025c..c8b773c6 100644
--- a/pyscriptjs/tests/integration/test_py_config.py
+++ b/pyscriptjs/tests/integration/test_py_config.py
@@ -80,15 +80,7 @@ class TestConfig(PyScriptTest):
)
self.pyscript_run(
- snippet="""
-
- import sys, js
- pyodide_version = sys.modules["pyodide"].__version__
- js.console.log("version", pyodide_version)
- pyodide_version
-
- """,
- extra_head="""
+ """
{
"runtimes": [{
@@ -98,6 +90,13 @@ class TestConfig(PyScriptTest):
}]
}
+
+
+ import sys, js
+ pyodide_version = sys.modules["pyodide"].__version__
+ js.console.log("version", pyodide_version)
+ pyodide_version
+
""",
)
@@ -108,12 +107,11 @@ class TestConfig(PyScriptTest):
def test_invalid_json_config(self):
with pytest.raises(JsError) as exc:
self.pyscript_run(
- snippet="",
- extra_head="""
-
- [[
-
- """,
+ snippet="""
+
+ [[
+
+ """
)
msg = str(exc.value)
@@ -122,12 +120,11 @@ class TestConfig(PyScriptTest):
def test_invalid_toml_config(self):
with pytest.raises(JsError) as exc:
self.pyscript_run(
- snippet="",
- extra_head="""
-
- [[
-
- """,
+ snippet="""
+
+ [[
+
+ """
)
msg = str(exc)
assert "