-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 545a919
Showing
5 changed files
with
86 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.zip |
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,4 @@ | ||
print("Initializing hello world module") | ||
from .some_funcs import say_hello, repeat_string | ||
|
||
__all__ = ["say_hello", "repeat_string"] |
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,5 @@ | ||
def say_hello(x): | ||
print("hello", x) | ||
|
||
def repeat_string(x, n): | ||
return x * n |
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,22 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<script src="https://cdn.jsdelivr.net/pyodide/dev/full/pyodide.js"></script> | ||
</head> | ||
<body> | ||
Pyodide test page <br> | ||
Open your browser console to see Pyodide output | ||
<script type="text/javascript"> | ||
async function main(){ | ||
const pkgResponse = fetch("hello_world.zip").then(x => x.arrayBuffer()); | ||
window.pyodide = await loadPyodide({ | ||
indexURL : "https://cdn.jsdelivr.net/pyodide/dev/full/" | ||
}); | ||
const pkgdata = await pkgResponse; | ||
pyodide.unpackArchive(pkgdata, "zip"); | ||
window.pkg = pyodide.pyimport("hello_world"); | ||
} | ||
main(); | ||
</script> | ||
</body> | ||
</html> |
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,54 @@ | ||
import argparse | ||
from contextlib import contextmanager | ||
import http.server | ||
from pathlib import Path | ||
import shutil | ||
import socketserver | ||
|
||
|
||
class Handler(http.server.SimpleHTTPRequestHandler): | ||
def end_headers(self): | ||
self.send_header("Access-Control-Allow-Origin", "*") | ||
super().end_headers() | ||
|
||
def send_head(self): | ||
if self.path.endswith(".zip"): | ||
path = Path(self.path) | ||
if str(path).startswith("/"): | ||
path = Path("." + str(path)).resolve() | ||
|
||
shutil.make_archive(path.with_suffix(""), "zip", root_dir=path.parent) | ||
|
||
return super().send_head() | ||
|
||
|
||
|
||
def make_parser(parser): | ||
parser.description = "Start a server" | ||
parser.add_argument( | ||
"--port", action="store", type=int, default=8000, help="choose the port" | ||
) | ||
return parser | ||
|
||
|
||
@contextmanager | ||
def server(port): | ||
httpd = socketserver.TCPServer(("", port), Handler) | ||
try: | ||
yield httpd | ||
finally: | ||
httpd.shutdown() | ||
|
||
|
||
def main(args): | ||
build_dir = args.build_dir | ||
port = args.port | ||
with server(port) as httpd: | ||
print(f"serving from {build_dir} at http://localhost:{port}") | ||
httpd.serve_forever() | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = make_parser(argparse.ArgumentParser()) | ||
args = parser.parse_args() | ||
main(args) |