Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
hoodmane committed Dec 27, 2021
1 parent 545a919 commit 248f0a1
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 8 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Pyodide Project

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Pyodide Examples

Use the `./server.py` to serve the files. If you request "some_directory.zip" it
the server will zip the directory on the fly and serve it. This is useful for
developing Python packages for use with Pyodide.
22 changes: 16 additions & 6 deletions hello-world/index.html
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/pyodide/dev/full/pyodide.js"></script>
<script src="https://cdn.jsdelivr.net/pyodide/dev/full/pyodide.js"></script>
</head>
<body>
Pyodide test page <br>
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());
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/"
indexURL: "https://cdn.jsdelivr.net/pyodide/dev/full/",
});
const pkgdata = await pkgResponse;
console.log("Unpacking package");
pyodide.unpackArchive(pkgdata, "zip");
console.log("Importing hello world");
window.pkg = pyodide.pyimport("hello_world");
console.log(`pkg.say_hello("John!"):`);
pkg.say_hello("John!");
console.log(
`pkg.repeat_string("John!", 4):`,
pkg.repeat_string("John!", 4)
);
}
main();
</script>
</body>
</html>
</html>
5 changes: 3 additions & 2 deletions server.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/python3

import argparse
from contextlib import contextmanager
import http.server
Expand Down Expand Up @@ -41,10 +43,9 @@ def server(port):


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}")
print(f"serving from {Path(__file__).resolve().parent} at http://localhost:{port}")
httpd.serve_forever()


Expand Down

0 comments on commit 248f0a1

Please sign in to comment.