-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(sandbox): use custom pyodide dist with requirements preloaded fo…
…r smoother experience
- Loading branch information
1 parent
3f78e2f
commit 64325e2
Showing
143 changed files
with
1,528 additions
and
3,844 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../examples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+11.7 KB
...terlite-sandbox/pyodide/pyodide/MarkupSafe-2.1.1-cp310-cp310-emscripten_3_1_21_wasm32.whl
Binary file not shown.
Binary file added
BIN
+920 KB
jupyterlite-sandbox/pyodide/pyodide/PIL-9.1.1-cp310-cp310-emscripten_3_1_21_wasm32.whl
Binary file not shown.
Binary file added
BIN
+6.63 KB
jupyterlite-sandbox/pyodide/pyodide/atomicwrites-1.4.0-py2.py3-none-any.whl
Binary file not shown.
Binary file added
BIN
+59.1 KB
jupyterlite-sandbox/pyodide/pyodide/attrs-21.4.0-py2.py3-none-any.whl
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,234 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<script src="https://cdn.jsdelivr.net/npm/jquery"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/jquery.terminal@2.32.0/js/jquery.terminal.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/jquery.terminal@2.23.0/js/unix_formatting.min.js"></script> | ||
<link | ||
href="https://cdn.jsdelivr.net/npm/jquery.terminal@2.32.0/css/jquery.terminal.min.css" | ||
rel="stylesheet" | ||
/> | ||
<script src="./pyodide.js"></script> | ||
<style> | ||
.terminal { | ||
--size: 1.5; | ||
--color: rgba(255, 255, 255, 0.8); | ||
} | ||
.noblink { | ||
--animation: terminal-none; | ||
} | ||
body { | ||
background-color: black; | ||
} | ||
#jquery-terminal-logo { | ||
color: white; | ||
border-color: white; | ||
position: absolute; | ||
top: 7px; | ||
right: 18px; | ||
z-index: 2; | ||
} | ||
#jquery-terminal-logo a { | ||
color: gray; | ||
text-decoration: none; | ||
font-size: 0.7em; | ||
} | ||
#loading { | ||
display: inline-block; | ||
width: 50px; | ||
height: 50px; | ||
position: fixed; | ||
top: 50%; | ||
left: 50%; | ||
border: 3px solid rgba(172, 237, 255, 0.5); | ||
border-radius: 50%; | ||
border-top-color: #fff; | ||
animation: spin 1s ease-in-out infinite; | ||
-webkit-animation: spin 1s ease-in-out infinite; | ||
} | ||
|
||
@keyframes spin { | ||
to { | ||
-webkit-transform: rotate(360deg); | ||
} | ||
} | ||
@-webkit-keyframes spin { | ||
to { | ||
-webkit-transform: rotate(360deg); | ||
} | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div id="jquery-terminal-logo"> | ||
<a href="https://terminal.jcubic.pl/">jQuery Terminal</a> | ||
</div> | ||
<div id="loading"></div> | ||
<script> | ||
"use strict"; | ||
function sleep(s) { | ||
return new Promise((resolve) => setTimeout(resolve, s)); | ||
} | ||
|
||
async function main() { | ||
let term; | ||
globalThis.pyodide = await loadPyodide({ | ||
stdin: () => { | ||
let result = prompt(); | ||
echo(result); | ||
return result; | ||
}, | ||
}); | ||
let namespace = pyodide.globals.get("dict")(); | ||
pyodide.runPython( | ||
` | ||
import sys | ||
from pyodide.ffi import to_js | ||
from pyodide.console import PyodideConsole, repr_shorten, BANNER | ||
import __main__ | ||
BANNER = "Welcome to the Pyodide terminal emulator 🐍\\n" + BANNER | ||
pyconsole = PyodideConsole(__main__.__dict__) | ||
import builtins | ||
async def await_fut(fut): | ||
res = await fut | ||
if res is not None: | ||
builtins._ = res | ||
return to_js([res], depth=1) | ||
def clear_console(): | ||
pyconsole.buffer = [] | ||
`, | ||
{ globals: namespace }, | ||
); | ||
let repr_shorten = namespace.get("repr_shorten"); | ||
let banner = namespace.get("BANNER"); | ||
let await_fut = namespace.get("await_fut"); | ||
let pyconsole = namespace.get("pyconsole"); | ||
let clear_console = namespace.get("clear_console"); | ||
const echo = (msg, ...opts) => | ||
term.echo( | ||
msg | ||
.replaceAll("]]", "]]") | ||
.replaceAll("[[", "[["), | ||
...opts, | ||
); | ||
namespace.destroy(); | ||
|
||
let ps1 = ">>> ", | ||
ps2 = "... "; | ||
|
||
async function lock() { | ||
let resolve; | ||
let ready = term.ready; | ||
term.ready = new Promise((res) => (resolve = res)); | ||
await ready; | ||
return resolve; | ||
} | ||
|
||
async function interpreter(command) { | ||
let unlock = await lock(); | ||
term.pause(); | ||
// multiline should be split (useful when pasting) | ||
for (const c of command.split("\n")) { | ||
let fut = pyconsole.push(c); | ||
term.set_prompt(fut.syntax_check === "incomplete" ? ps2 : ps1); | ||
switch (fut.syntax_check) { | ||
case "syntax-error": | ||
term.error(fut.formatted_error.trimEnd()); | ||
continue; | ||
case "incomplete": | ||
continue; | ||
case "complete": | ||
break; | ||
default: | ||
throw new Error(`Unexpected type ${ty}`); | ||
} | ||
// In JavaScript, await automatically also awaits any results of | ||
// awaits, so if an async function returns a future, it will await | ||
// the inner future too. This is not what we want so we | ||
// temporarily put it into a list to protect it. | ||
let wrapped = await_fut(fut); | ||
// complete case, get result / error and print it. | ||
try { | ||
let [value] = await wrapped; | ||
if (value !== undefined) { | ||
echo( | ||
repr_shorten.callKwargs(value, { | ||
separator: "\n<long output truncated>\n", | ||
}), | ||
); | ||
} | ||
if (pyodide.isPyProxy(value)) { | ||
value.destroy(); | ||
} | ||
} catch (e) { | ||
if (e.constructor.name === "PythonError") { | ||
const message = fut.formatted_error || e.message; | ||
term.error(message.trimEnd()); | ||
} else { | ||
throw e; | ||
} | ||
} finally { | ||
fut.destroy(); | ||
wrapped.destroy(); | ||
} | ||
} | ||
term.resume(); | ||
await sleep(10); | ||
unlock(); | ||
} | ||
|
||
term = $("body").terminal(interpreter, { | ||
greetings: banner, | ||
prompt: ps1, | ||
completionEscape: false, | ||
completion: function (command, callback) { | ||
callback(pyconsole.complete(command).toJs()[0]); | ||
}, | ||
keymap: { | ||
"CTRL+C": async function (event, original) { | ||
clear_console(); | ||
term.enter(); | ||
echo("KeyboardInterrupt"); | ||
term.set_command(""); | ||
term.set_prompt(ps1); | ||
}, | ||
TAB: (event, original) => { | ||
const command = term.before_cursor(); | ||
// Disable completion for whitespaces. | ||
if (command.trim() === "") { | ||
term.insert("\t"); | ||
return false; | ||
} | ||
return original(event); | ||
}, | ||
}, | ||
}); | ||
window.term = term; | ||
pyconsole.stdout_callback = (s) => echo(s, { newline: false }); | ||
pyconsole.stderr_callback = (s) => { | ||
term.error(s.trimEnd()); | ||
}; | ||
term.ready = Promise.resolve(); | ||
pyodide._api.on_fatal = async (e) => { | ||
term.error( | ||
"Pyodide has suffered a fatal error. Please report this to the Pyodide maintainers.", | ||
); | ||
term.error("The cause of the fatal error was:"); | ||
term.error(e); | ||
term.error("Look in the browser console for more details."); | ||
await term.ready; | ||
term.pause(); | ||
await sleep(15); | ||
term.pause(); | ||
}; | ||
|
||
const searchParams = new URLSearchParams(window.location.search); | ||
if (searchParams.has("noblink")) { | ||
$(".cmd-cursor").addClass("noblink"); | ||
} | ||
} | ||
window.console_ready = main(); | ||
</script> | ||
</body> | ||
</html> |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+247 KB
jupyterlite-sandbox/pyodide/pyodide/fonts/DejaVuSansMono-BoldOblique.ttf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
Fonts are (c) Bitstream (see below). DejaVu changes are in public domain. | ||
Glyphs imported from Arev fonts are (c) Tavmjong Bah (see below) | ||
|
||
Bitstream Vera Fonts Copyright | ||
------------------------------ | ||
|
||
Copyright (c) 2003 by Bitstream, Inc. All Rights Reserved. Bitstream Vera is | ||
a trademark of Bitstream, Inc. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of the fonts accompanying this license ("Fonts") and associated | ||
documentation files (the "Font Software"), to reproduce and distribute the | ||
Font Software, including without limitation the rights to use, copy, merge, | ||
publish, distribute, and/or sell copies of the Font Software, and to permit | ||
persons to whom the Font Software is furnished to do so, subject to the | ||
following conditions: | ||
|
||
The above copyright and trademark notices and this permission notice shall | ||
be included in all copies of one or more of the Font Software typefaces. | ||
|
||
The Font Software may be modified, altered, or added to, and in particular | ||
the designs of glyphs or characters in the Fonts may be modified and | ||
additional glyphs or characters may be added to the Fonts, only if the fonts | ||
are renamed to names not containing either the words "Bitstream" or the word | ||
"Vera". | ||
|
||
This License becomes null and void to the extent applicable to Fonts or Font | ||
Software that has been modified and is distributed under the "Bitstream | ||
Vera" names. | ||
|
||
The Font Software may be sold as part of a larger software package but no | ||
copy of one or more of the Font Software typefaces may be sold by itself. | ||
|
||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, | ||
TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL BITSTREAM OR THE GNOME | ||
FOUNDATION BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING | ||
ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, | ||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF | ||
THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE | ||
FONT SOFTWARE. | ||
|
||
Except as contained in this notice, the names of Gnome, the Gnome | ||
Foundation, and Bitstream Inc., shall not be used in advertising or | ||
otherwise to promote the sale, use or other dealings in this Font Software | ||
without prior written authorization from the Gnome Foundation or Bitstream | ||
Inc., respectively. For further information, contact: fonts at gnome dot | ||
org. | ||
|
||
Arev Fonts Copyright | ||
------------------------------ | ||
|
||
Copyright (c) 2006 by Tavmjong Bah. All Rights Reserved. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of the fonts accompanying this license ("Fonts") and | ||
associated documentation files (the "Font Software"), to reproduce | ||
and distribute the modifications to the Bitstream Vera Font Software, | ||
including without limitation the rights to use, copy, merge, publish, | ||
distribute, and/or sell copies of the Font Software, and to permit | ||
persons to whom the Font Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright and trademark notices and this permission notice | ||
shall be included in all copies of one or more of the Font Software | ||
typefaces. | ||
|
||
The Font Software may be modified, altered, or added to, and in | ||
particular the designs of glyphs or characters in the Fonts may be | ||
modified and additional glyphs or characters may be added to the | ||
Fonts, only if the fonts are renamed to names not containing either | ||
the words "Tavmjong Bah" or the word "Arev". | ||
|
||
This License becomes null and void to the extent applicable to Fonts | ||
or Font Software that has been modified and is distributed under the | ||
"Tavmjong Bah Arev" names. | ||
|
||
The Font Software may be sold as part of a larger software package but | ||
no copy of one or more of the Font Software typefaces may be sold by | ||
itself. | ||
|
||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT | ||
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL | ||
TAVMJONG BAH BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL | ||
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM | ||
OTHER DEALINGS IN THE FONT SOFTWARE. | ||
|
||
Except as contained in this notice, the name of Tavmjong Bah shall not | ||
be used in advertising or otherwise to promote the sale, use or other | ||
dealings in this Font Software without prior written authorization | ||
from Tavmjong Bah. For further information, contact: tavmjong @ free | ||
. fr. | ||
|
||
$Id: LICENSE 2133 2007-11-28 02:46:28Z lechimp $ |
Oops, something went wrong.