Skip to content

Commit 800f1f1

Browse files
version 0.3.2 -> bug fix with no css
1 parent b44080f commit 800f1f1

File tree

7 files changed

+121
-63
lines changed

7 files changed

+121
-63
lines changed
45.8 KB
Binary file not shown.

dist/schemascii-0.3.2.tar.gz

55.7 KB
Binary file not shown.

index.html

+19-60
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,21 @@
2828
color: red;
2929
}
3030

31-
a, a:visited {
31+
a,
32+
a:visited {
3233
color: blue;
3334
}
3435

3536
@media screen and (prefers-color-scheme: dark) {
36-
body, textarea {
37+
38+
body,
39+
textarea {
3740
color: white;
3841
background: black;
3942
}
40-
a, a:visited {
43+
44+
a,
45+
a:visited {
4146
color: magenta;
4247
}
4348
}
@@ -47,7 +52,7 @@
4752

4853
<body>
4954
<h1>Schemascii Playground</h1>
50-
<h2 id="version">Loading version...</h2>
55+
<h2>using schemascii version <select id="version"></select></h2>
5156
<div class="flex row">
5257
<div class="flex column">
5358
<h2>Schemascii Source</h2><textarea id="schemascii" disabled></textarea>
@@ -63,46 +68,25 @@ <h2>Messages</h2>
6368
<h2>Errors</h2>
6469
<pre id="errors"></pre>
6570
<h2>More Information</h2>
66-
<p><a href="https://github.com/dragoncoder047/schemascii/" target="_blank">https://github.com/dragoncoder047/schemascii/</a></p>
71+
<p><a href="https://github.com/dragoncoder047/schemascii/"
72+
target="_blank">https://github.com/dragoncoder047/schemascii/</a></p>
6773
</body>
6874
<script>
69-
// cSpell:ignore pyodide pyproject pyimport
75+
// cSpell:ignore pyodide pyproject
7076
var pyodide;
71-
var output = document.getElementById("output");
72-
var css = document.getElementById("css");
7377
var console = document.getElementById("console");
74-
var source = document.getElementById("schemascii");
75-
var style_elem = document.getElementById("custom-css");
76-
var schemascii_render;
78+
var errors = document.getElementById("errors")
79+
7780
async function main() {
7881
try {
7982
info("Loading Python... ");
8083
pyodide = await loadPyodide({ stdout: info, stderr: error });
8184
info("done\nInstalling micropip...");
82-
await pyodide.loadPackage("micropip", { errorCallback: error, messageCallback: () => {} });
83-
info("done\nFetching current Schemascii version... ");
84-
var pyproject_toml = await fetch("pyproject.toml").then(x => x.text());
85-
var ver = /version = "([\d.]+)"/.exec(pyproject_toml)[1];
86-
document.getElementById("version").textContent = `using Schemascii version ${ver}`;
87-
info(`${ver}\nInstalling schemascii-${ver} ... `);
88-
await pyodide.pyimport("micropip", { errorCallback: error, messageCallback: info })
89-
.install(`https://dragoncoder047.github.io/schemascii/dist/schemascii-${ver}-py3-none-any.whl`);
90-
schemascii_render = await pyodide.runPythonAsync(`
91-
import warnings
92-
import schemascii
93-
def foo(*args, **kwargs):
94-
with warnings.catch_warnings(record=True) as captured_warnings:
95-
out = schemascii.render(*args, **kwargs)
96-
for warn in captured_warnings:
97-
print("warning:", warn.message)
98-
return out
99-
100-
foo
101-
`);
102-
await setup();
103-
console.textContent = "ready\n";
85+
await pyodide.loadPackage("micropip", { errorCallback: error, messageCallback: () => { } });
86+
info("done\n");
87+
await pyodide.runPythonAsync(await fetch("scripts/web_startup.py").then(r => r.text()));
10488
} catch (e) {
105-
error(`\n${e.stack}\n`);
89+
error(`\nFATAL ERROR:\n${e.stack}\n`);
10690
throw e;
10791
}
10892
}
@@ -112,32 +96,7 @@ <h2>More Information</h2>
11296
function error(text) {
11397
errors.textContent += text;
11498
}
115-
async function setup() {
116-
css.value = await fetch("schemascii_example.css").then(x => x.text());
117-
style_elem.innerHTML = css.value;
118-
css.addEventListener("input", () => {
119-
style_elem.innerHTML = css.value;
120-
});
121-
var timeout = null;
122-
source.addEventListener("input", () => {
123-
if (timeout) clearTimeout(timeout);
124-
// Debouncing
125-
timeout = setTimeout(async () => {
126-
console.textContent = "";
127-
errors.textContent = "";
128-
try {
129-
output.innerHTML = await schemascii_render("playground", source.value);
130-
} catch (e) {
131-
error(`\n${e.stack}\n`);
132-
output.innerHTML = "";
133-
throw e;
134-
}
135-
}, 100);
136-
});
137-
source.removeAttribute("disabled");
138-
css.removeAttribute("disabled");
139-
}
14099
main();
141100
</script>
142101

143-
</html>
102+
</html>

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "schemascii"
7-
version = "0.3.1"
7+
version = "0.3.2"
88
description = "Render ASCII-art schematics to SVG"
99
readme = "README.md"
1010
authors = [{ name = "dragoncoder047", email = "[email protected]" }]

schemascii/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from .utils import XML
99
from .errors import *
1010

11-
__version__ = "0.3.1"
11+
__version__ = "0.3.2"
1212

1313

1414
def render(filename: str, text: str = None, **options) -> str:

scripts/web_startup.py

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
from pyodide.http import pyfetch as fetch, open_url as get
2+
from pyodide.ffi import create_proxy as event_handler
3+
import asyncio
4+
import functools
5+
import sys
6+
import re
7+
import js
8+
import json
9+
from operator import itemgetter
10+
import warnings
11+
import micropip
12+
13+
14+
def debounced(fun):
15+
timeout = None
16+
17+
@functools.wraps(fun)
18+
def inner():
19+
nonlocal timeout
20+
if timeout:
21+
js.clearTimeout(timeout)
22+
timeout = js.setTimeout(fun, 100)
23+
24+
return inner
25+
26+
27+
def syncify(fun):
28+
@functools.wraps(fun)
29+
def inner(e):
30+
return asyncio.ensure_future(fun(e))
31+
return inner
32+
33+
34+
@event_handler
35+
@debounced
36+
def sync_css():
37+
style_elem.innerHTML = css_box.value
38+
39+
40+
@event_handler
41+
@debounced
42+
def render_catch_warnings(*args, **kwargs):
43+
import schemascii
44+
console.textContent = ""
45+
errors.textContent = ""
46+
with warnings.catch_warnings(record=True) as captured_warnings:
47+
out = schemascii.render(*args, **kwargs)
48+
for warn in captured_warnings:
49+
print("warning:", warn.message)
50+
return out
51+
52+
53+
@event_handler
54+
@syncify
55+
async def switch_version():
56+
if "schemascii" in sys.modules:
57+
del sys.modules["schemascii"] # Invalidate cache
58+
version = ver_switcher.value
59+
await micropip.install(versions_to_wheel_map[version])
60+
61+
output = js.document.getElementById("output")
62+
css_box = js.document.getElementById("css")
63+
console = js.document.getElementById("console")
64+
source = js.document.getElementById("schemascii")
65+
style_elem = js.document.getElementById("custom-css")
66+
errors = js.document.getElementById("errors")
67+
ver_switcher = js.document.getElementById("version")
68+
69+
70+
print("Loading all versions... ", end="")
71+
versions_all = json.load(
72+
get("https://api.github.com/repos/dragoncoder047/schemascii/contents/dist"))
73+
versions_to_wheel_map = dict(
74+
zip(map(itemgetter("name"), versions_all), map(itemgetter("path"), versions_all)))
75+
all_versions = list(versions_to_wheel_map.keys())
76+
all_versions.append("DEV")
77+
latest_version = re.search(
78+
r'''version = "([\d.]+)"''', get("pyproject.toml").read()).group(1)
79+
print(all_versions, "latest =", latest_version)
80+
81+
for ver in all_versions:
82+
opt = js.document.createElement("option")
83+
opt.value = opt.textContent = ver
84+
ver_switcher.append(opt)
85+
86+
ver_switcher.value = latest_version
87+
await micropip.install(versions_to_wheel_map[latest_version])
88+
89+
90+
css_source = get("schemascii_example.css").read()
91+
style_elem.textContent = css_source
92+
css_box.value = css_source
93+
94+
css_box.addEventListener("input", sync_css)
95+
source.addEventListener("input", render_catch_warnings)
96+
97+
source.removeAttribute("disabled")
98+
css_box.removeAttribute("disabled")
99+
console.textContent = "ready\n"

test_data/test_charge_pump.txt.svg

+1-1
Loading

0 commit comments

Comments
 (0)