Skip to content

Commit

Permalink
Capture and print warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
dragoncoder047 authored Jul 28, 2023
1 parent e31c6a0 commit f1cca78
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ <h2>More Information</h2>
var console = document.getElementById("console");
var source = document.getElementById("schemascii");
var style_elem = document.getElementById("custom-css");
var schemascii;
var schemascii_render;
async function main() {
try {
info("Loading Python... ");
Expand All @@ -80,7 +80,18 @@ <h2>More Information</h2>
info(`${ver}\nInstalling schemascii-${ver} ... `);
await pyodide.pyimport("micropip", { errorCallback: error, messageCallback: info })
.install(`https://dragoncoder047.github.io/schemascii/dist/schemascii-${ver}-py3-none-any.whl`);
schemascii = pyodide.pyimport("schemascii");
schemascii_render = await pyodide.runPythonAsync(`
import warnings
import schemascii
def foo(*args, **kwargs):
with warnings.catch_warnings(record=True) as captured_warnings:
out = schemascii.render(*args, **kwargs)
for warn in captured_warnings:
print("warning:", warn.message)
return out
foo
`);
await setup();
console.textContent = "ready\n";
} catch (e) {
Expand Down Expand Up @@ -108,7 +119,7 @@ <h2>More Information</h2>
console.textContent = "";
errors.textContent = "";
try {
output.innerHTML = await schemascii.render("playground", source.value);
output.innerHTML = await schemascii_render("playground", source.value);
} catch (e) {
error(`\n${e.stack}\n`);
output.innerHTML = "";
Expand Down

0 comments on commit f1cca78

Please sign in to comment.