This repository was archived by the owner on Sep 21, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +91
-0
lines changed Expand file tree Collapse file tree 5 files changed +91
-0
lines changed Original file line number Diff line number Diff line change
1
+ mpbuild
2
+ pybuild
3
+ micropython
4
+ cpython
5
+ emsdk
Original file line number Diff line number Diff line change
1
+ SHELL := /bin/bash
2
+
3
+ all :
4
+ @echo " \nThere's no default Makefil target right now. Try\n\n"
5
+ @echo " make setup - clone the required repositories."
6
+ @echo " make update - update the emsdk compiler."
7
+ @echo " make refresh - re-compile MicroPython for WASM into build."
8
+
9
+ setup :
10
+ git clone https://github.com/emscripten-core/emsdk.git
11
+ git clone https://github.com/micropython/micropython.git
12
+ git clone https://github.com/python/cpython.git
13
+
14
+ update :
15
+ cd emsdk && git pull && ./emsdk install latest && ./emsdk activate latest
16
+
17
+ mp :
18
+ rm -rf mpbuild
19
+ $(MAKE ) -C micropython/mpy-cross
20
+ ./emsdk/emsdk activate latest && source emsdk/emsdk_env.sh && $(MAKE ) -C micropython/ports/webassembly
21
+ cp -r micropython/ports/webassembly/build mpbuild
22
+
23
+ py :
24
+ rm -rf pybuild
25
+ ./cpython/Tools/wasm/wasm_build.py build
26
+ ./emsdk/emsdk activate latest && source emsdk/emsdk_env.sh && ./cpython/Tools/wasm/wasm_build.py emscripten-browser
27
+ cp -r cpython/builddir/emscripten-browser pybuild
28
+
29
+ serve :
30
+ python -m http.server
Original file line number Diff line number Diff line change
1
+ # PyScript Lite
2
+
3
+ A small, simple kernel of PyScript, made for testing purposes.
4
+
5
+ This is the way:
6
+
7
+ * Obvious code.
8
+ * Simple is good.
9
+ * Build for change.
10
+ * No dependencies.
11
+ * Pluggable.
12
+
13
+ This is a solid foundation for lightweight testing of Python runtimes that
14
+ target WASM. Inspired by code in the "real" PyTest website.
15
+
16
+ Complexity, edge cases, customization and mess is confined to plugins.
17
+
18
+ That is all.
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < script src ="mpbuild/micropython.js "> </ script >
5
+ </ head >
6
+ < body >
7
+ < py-script >
8
+ def hello(name="World"):
9
+ return "Hello, " + name
10
+
11
+ print(hello())
12
+ </ py-script >
13
+ < pre > < code id ="mp_js_stdout "> </ code > </ pre >
14
+ </ body >
15
+ < script src ="pyscript.js " type ="module "> </ script >
16
+ </ html >
Original file line number Diff line number Diff line change
1
+ "use strict" ;
2
+
3
+ class PyScript extends HTMLElement {
4
+
5
+ connectedCallback ( ) {
6
+ var code = this . textContent ;
7
+ this . textContent = "" ;
8
+ // MicroPython things happen here...
9
+ mp_js_stdout . addEventListener ( 'print' , function ( e ) {
10
+ this . innerText = this . innerText + e . data ;
11
+ } , false ) ;
12
+ var mp_js_startup = Module [ 'onRuntimeInitialized' ] ;
13
+ Module [ "onRuntimeInitialized" ] = async function ( ) {
14
+ mp_js_startup ( ) ;
15
+ mp_js_init ( 64 * 1024 ) ;
16
+ mp_js_do_str ( code ) ;
17
+ }
18
+
19
+ }
20
+ }
21
+
22
+ customElements . define ( 'py-script' , PyScript ) ;
You can’t perform that action at this time.
0 commit comments