Skip to content

Commit 3263430

Browse files
committed
Add another example. Fix the Jinja2 template to use TOML. Turn off mypy checking of examples.
1 parent b737956 commit 3263430

File tree

14 files changed

+83
-39
lines changed

14 files changed

+83
-39
lines changed

.flake8

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ docstring-convention = google
77
per-file-ignores =
88
tests/*:S101
99
src/psc/static/pyscript.py:D100,D101,D102,D103,D107,D200,D212,D415,N802,N806
10+
src/psc/gallery/examples/*: F821
1011
rst-roles = class,const,func,meth,mod,ref
1112
rst-directives = deprecated

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
A list of community contributed content that enriches PyScript's ecosystem.
44

5-
We strive to make people feel valued and valuable, and we hope to make lots of iterations with the help of the community to build a place that's inclusive and uplifting to all.
6-
Please check our [code of conduct](https://github.com/pyscript/governance/blob/main/CODE-OF-CONDUCT.md).
5+
We strive to make people feel valued and valuable, and we hope to make lots of iterations with the help of the community to build a place that's inclusive and uplifting to all.
6+
Please check our [code of conduct](https://github.com/pyscript/governance/blob/main/CODE-OF-CONDUCT.md).
77
If you're interested in contributing head over to our [how to contribute](CONTRIBUTING.MD) document.
88

99
## `awesome-pyscript`

TODO.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
## Eventually
66

7-
- Upgrade mypy
8-
- Remove type hints from examples
9-
- Add another example
107
- Get nox to work with downloaded pyodide/pyscript
118
- Get rid of Poetry
129

1310
## Done
1411

1512
- Add a build step for the downloader
1613
- Upgrade to latest PyScript
14+
- Upgrade mypy
15+
- Remove type hints from examples
16+
- Add another example

awesome-pyscript.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ Got something to list in Awesome PyScript?
2424

2525
Ongoing sources of articles, videos, and more.
2626

27-
- [Articles and demos](https://jeff.glass/tags/pyscript/) by [Jeff Glass](https://twitter.com/jeffersglass)
27+
- [Articles and demos](https://jeff.glass/tags/pyscript/) by [Jeff Glass](https://twitter.com/jeffersglass)
2828
- GIS and data science [PyScript tutorials](https://geo.rocks/categories/pyscript/) by [Dominik Weckmüller](https://twitter.com/domegis)
29-
- [PyScript in-depth articles](https://www.jhanley.com/blog/category/pyscript/) by [John Hanley](https://twitter.com/NeoPrimeAws).
29+
- [PyScript in-depth articles](https://www.jhanley.com/blog/category/pyscript/) by [John Hanley](https://twitter.com/NeoPrimeAws).
3030
John has many useful articles discussing using PyScript in an app, what happens under the hood, and more.
3131

32-
- [PyScript tutorial YouTube playlist](https://www.youtube.com/playlist?list=PLpdmBGJ6ELUJ2ujkBcMQ3n0D2J2exAVTs) multi-part video series by [@1littlecoder](https://twitter.com/1littlecoder)
32+
- [PyScript tutorial YouTube playlist](https://www.youtube.com/playlist?list=PLpdmBGJ6ELUJ2ujkBcMQ3n0D2J2exAVTs) multi-part video series by [@1littlecoder](https://twitter.com/1littlecoder)
3333

3434
## Talks, Videos, Podcasts
3535

@@ -38,7 +38,7 @@ Not a listing of everything -- only a few "first look" videos included.
3838

3939
- [Rethinking Data Visualization with PyScript](https://youtu.be/Xd-tmhdLJp0) by [Valerio Maggio](https://twitter.com/leriomaggio) (July 2022)
4040

41-
- [JupyterLite at EuroSciPy](https://twitter.com/sklearn_inria/status/1564524486057132032) ([repo](https://github.com/Vincent-Maladiere/scipy-demo)) by Vincent Maladiére and taught by
41+
- [JupyterLite at EuroSciPy](https://twitter.com/sklearn_inria/status/1564524486057132032) ([repo](https://github.com/Vincent-Maladiere/scipy-demo)) by Vincent Maladiére and taught by
4242
[@ogrisel](https://twitter.com/ogrisel) (Aug 2022)
4343

4444
- [Inside the PyScript Source](https://www.youtube.com/watch?v=SqNNLssFzm4) video by [Paul Everitt](https://twitter.com/paulweveritt/status) (May 2022)
@@ -59,9 +59,9 @@ Here are some of the recommended ones:
5959
- [PyScript - Deep Dive for Developer](https://www.youtube.com/watch?v=xAtoMtCfR3g) video by [Andrej Baranovskij](https://twitter.com/andrejusb) (May 2022)
6060

6161
- [Python In The Browser! PyScript First Look](https://www.youtube.com/watch?v=vxqBm6_0vyk) video by [Traversy Media](https://twitter.com/traversymedia) (May 2022)
62-
62+
6363
- [Python + pyscript + WebAssembly: Python Web Apps, Running Locally with pyscript](https://www.youtube.com/watch?v=lC2jUeDKv-s) video by [Michael Kennedy](https://twitter.com/mkennedy) (May 2022)
64-
64+
6565
- [PyScript First Impressions - Run Python in HTML Document](https://www.youtube.com/watch?v=yrn1OYu9q0E) long livestream by [Mariya Sha](https://www.pythonsimplified.org) (May 2022)
6666

6767
- [PyCon Keynote](https://www.youtube.com/watch?v=qKfkCY7cmBQ) by [Peter Wang](https://twitter.com/pwang) unveiling PyScript (Apr 2022)

poetry.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ flake8-docstrings = ">=1.6.0"
3636
flake8-rst-docstrings = ">=0.2.5"
3737
furo = ">=2021.11.12"
3838
isort = ">=5.10.1"
39-
mypy = ">=0.930"
39+
mypy = ">=0.981"
4040
pep8-naming = ">=0.12.1"
4141
pre-commit = ">=2.16.0"
4242
pre-commit-hooks = ">=4.1.0"
@@ -87,7 +87,7 @@ show_column_numbers = true
8787
show_error_codes = true
8888
show_error_context = true
8989
files = ["src/psc", "tests"]
90-
exclude = [".nox", "docs","static","pyodide"]
90+
exclude = [".nox", "docs","static","pyodide", "src/psc/gallery"]
9191
no_implicit_optional = true
9292

9393
[[tool.mypy.overrides]]

src/psc/__main__.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ def download(
3434
dry_run: bool = typer.Option(False, "--dry-run")
3535
) -> None: # pragma: no cover
3636
"""Download Pyodide and PyScript distributions into project dir."""
37+
http = PoolManager()
38+
3739
# Get Pyodide first
3840
pyodide_url_prefix = "https://github.com/pyodide/pyodide/releases/download"
3941
pyodide_url = f"{pyodide_url_prefix}/0.21.3/pyodide-build-0.21.3.tar.bz2"
40-
http = PoolManager()
4142
pyodide_request: HTTPResponse = http.request("GET", pyodide_url) # type: ignore
4243
with TemporaryDirectory() as tmp_dir_name:
4344
os.chdir(tmp_dir_name)
@@ -52,15 +53,19 @@ def download(
5253
print("Downloaded Pyodide")
5354

5455
# Next, PyScript
55-
pyscript_url = "https://pyscript.net/latest/pyscript.js"
56-
pyscript_request: HTTPResponse = http.request("GET", pyscript_url) # type: ignore
57-
if not dry_run:
58-
target = HERE / "pyscript"
56+
filenames = ("pyscript.js", "pyscript.js.map")
57+
for fn in filenames:
58+
pyscript_url = f"https://pyscript.net/latest/{fn}"
59+
pyscript_request: HTTPResponse = http.request(
60+
"GET", pyscript_url
61+
) # type: ignore
5962
if not dry_run:
60-
with open(target / "pyscript.js", "wb") as pyscript_output:
61-
pyscript_output.write(pyscript_request.data)
63+
target = HERE / "pyscript"
64+
if not dry_run:
65+
with open(target / fn, "wb") as pyscript_output:
66+
pyscript_output.write(pyscript_request.data)
6267

63-
print("Downloaded PyScript")
68+
print("Downloaded PyScript")
6469

6570

6671
@app.command()

src/psc/gallery/examples/hello_world/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
<meta charset="utf-8">
1010
<meta name="viewport" content="width=device-width,initial-scale=1">
1111

12-
<title>Hello World</title>
13-
<meta name="subtitle" content="The classic hello world, but in Python -- in a browser!">
12+
<title>Hello World Python</title>
13+
<meta name="subtitle" content="The hello world example, but in a .py file.">
1414

1515
<link rel="icon" type="image/png" href="../../../favicon.png">
1616
<script defer src="../../../pyscript/pyscript.js"></script>

src/psc/gallery/examples/hello_world/index.md

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
h1 {
2+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* Stuff here */
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"""Say Hello."""
2+
output = Element("output")
3+
output.write("From Python...")
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<!--
2+
contributor: example@contributor.me
3+
tags: example-tag, another-example
4+
-->
5+
6+
<!DOCTYPE html>
7+
<html lang="en">
8+
<head>
9+
<meta charset="utf-8">
10+
<meta name="viewport" content="width=device-width,initial-scale=1">
11+
12+
<title>Hello World</title>
13+
<meta name="subtitle" content="The classic hello world, but in Python -- in a browser!">
14+
15+
<link rel="icon" type="image/png" href="../../../favicon.png">
16+
<script defer src="../../../pyscript/pyscript.js"></script>
17+
<link rel="stylesheet" href="hello_world.css">
18+
<script defer src="hello_world.js"></script>
19+
</head>
20+
21+
<body>
22+
<py-config>
23+
autoclose_loader = true
24+
25+
[[runtimes]]
26+
src = "../../../pyodide/pyodide.js"
27+
</py-config>
28+
<main>
29+
<h1>Hello Python ...</h1>
30+
<div id="output"></div>
31+
<py-script src="./hello_world.py"></py-script>
32+
</main>
33+
</body>
34+
</html>

src/psc/templates/example.jinja2

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
{% extends "layout.jinja2" %}
22
{% block extra_head %}
3-
<meta name="subtitle" content="{{ subtitle }}" >
3+
<meta name="subtitle" content="{{ subtitle }}">
44
<script defer src="{{ root_path }}/pyscript/pyscript.js"></script>
55
{{ extra_head | safe }}{% endblock %}
66
{% block extra_body %}
7-
<py-config>
8-
autoclose_loader: true
9-
runtimes:
10-
- src: "{{ root_path }}/pyodide/pyodide.js"
11-
name: pyodide-0.20
12-
lang: python
13-
</py-config>
14-
{{ extra_pyscript | safe }}
7+
<py-config>
8+
autoclose_loader = true
9+
10+
[[runtimes]]
11+
src = "{{ root_path }}/pyodide/pyodide.js"
12+
</py-config>
13+
{{ extra_pyscript | safe }}
1514
{% endblock %}
1615
{% block main %}
17-
<main id="main_container" class="container">
18-
<h1 class="title">{{ title }}</h1>
19-
<h1 class="subtitle">{{ subtitle }}</h1>
20-
{{ main | safe }}
21-
</main>
16+
<main id="main_container" class="container">
17+
<h1 class="title">{{ title }}</h1>
18+
<h1 class="subtitle">{{ subtitle }}</h1>
19+
{{ main | safe }}
20+
</main>
2221
{% endblock %}

0 commit comments

Comments
 (0)