Skip to content
This repository was archived by the owner on Sep 21, 2023. It is now read-only.

Commit 813fafa

Browse files
committed
Minor tidy-ups.
1 parent 983975a commit 813fafa

File tree

3 files changed

+57
-26
lines changed

3 files changed

+57
-26
lines changed

Makefile

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
SHELL := /bin/bash
22

33
all:
4-
@echo "\nThere's no default Makefil target right now. Try\n\n"
4+
@echo "There's no default Makefile target right now. Try:"
5+
@echo ""
56
@echo "make setup - clone the required repositories."
67
@echo "make update - update the emsdk compiler."
7-
@echo "make refresh - re-compile MicroPython for WASM into build."
8+
@echo "make mp - compile MicroPython for WASM into the mpbuild directory."
9+
@echo "make serve - serve the project at: http://0.0.0.0:8000/"
810

911
setup:
1012
git clone https://github.com/emscripten-core/emsdk.git
1113
git clone https://github.com/micropython/micropython.git
12-
git clone https://github.com/python/cpython.git
1314

1415
update:
1516
cd emsdk && git pull && ./emsdk install latest && ./emsdk activate latest
@@ -20,11 +21,5 @@ mp:
2021
./emsdk/emsdk activate latest && source emsdk/emsdk_env.sh && $(MAKE) -C micropython/ports/webassembly
2122
cp -r micropython/ports/webassembly/build mpbuild
2223

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-
2924
serve:
3025
python -m http.server

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,22 @@ target WASM. Inspired by code in the "real" PyTest website.
1616
Complexity, edge cases, customization and mess is confined to plugins.
1717

1818
That is all.
19+
20+
## Developer Setup
21+
22+
In order to compile MicroPython you'll need to ensure you have the expected
23+
compiler tools described here:
24+
25+
https://docs.micropython.org/en/latest/develop/gettingstarted.html
26+
27+
Otherwise, common tasks are scripted by a Makefile (tested on Linux):
28+
29+
```
30+
$ make
31+
There's no default Makefile target right now. Try:
32+
33+
make setup - clone the required repositories.
34+
make update - update the emsdk compiler.
35+
make mp - compile MicroPython for WASM into the mpbuild directory.
36+
make serve - serve the project at: http://0.0.0.0:8000/
37+
```

pyscript.js

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class PyScriptTag extends Plugin {
123123
document.dispatchEvent(pyScriptRegistered);
124124
}
125125
}
126-
// Register it (thUs extracting the code from the page).
126+
// Register it (thus extracting the code from the page).
127127
customElements.define('py-script', PyScript);
128128
}
129129
}
@@ -173,11 +173,27 @@ class MicroPythonRuntime extends Runtime {
173173
}
174174
}
175175

176+
177+
class CPythonRuntime extends Runtime {
178+
/*
179+
The standard CPython version of Python compiled to WASM. For more
180+
information, see:
181+
182+
https://github.com/python/cpython/blob/main/Tools/wasm/README.md
183+
184+
TODO: Finish this.
185+
*/
186+
187+
static get url() {
188+
return "pybuild/python.js";
189+
}
190+
}
191+
176192
/******************************************************************************
177193
The core PyScript app definition.
178194
******************************************************************************/
179195

180-
function main() {
196+
const main = function() {
181197
// Really simple logging. Emoji 🐍 highlights PyScript app logs. ;-)
182198
const logger = function() {
183199
return Function.prototype.bind.call(console.log, console, "🐍 ", ...arguments);
@@ -197,10 +213,10 @@ function main() {
197213
const pendingScripts = [];
198214
// Details of runtimes.
199215
// Key: lowercase runtime name.
200-
// Value: path to load runtime.
216+
// Value: the class wrapping that version of the runtime.
201217
const runtimes = {
202218
"micropython": MicroPythonRuntime,
203-
"cpython": "pybuild/python.js"
219+
"cpython": CPythonRuntime
204220
}
205221
// Default to smallest/fastest runtime.
206222
runtimes["default"] = runtimes["micropython"]
@@ -356,7 +372,6 @@ function main() {
356372
evaluate each script in turn with the runtime.
357373
*/
358374
logger("Evaluating code. 🤖\n" + script.code);
359-
debugger;
360375
runtime.eval(script.code);
361376
},
362377
}
@@ -366,14 +381,8 @@ function main() {
366381
// steps.
367382
//
368383
// These functions are defined in the order they're roughly expected to
369-
// be called through the life-cycle of the page.
370-
371-
app["run"] = function() {
372-
/*
373-
Start everthing running.
374-
*/
375-
app.loadConfig();
376-
}
384+
// be called through the life-cycle of the page, although this cannot be
385+
// guaranteed for some of the functions.
377386

378387
function onPyConfigured(e) {
379388
/*
@@ -432,11 +441,19 @@ function main() {
432441
}
433442
document.addEventListener("py-eval-script", onEvalScript);
434443

435-
return app;
436-
}
444+
// Finally, return a function to start PyScript.
445+
446+
return function() {
447+
/*
448+
Start PyScript.
449+
*/
450+
// TODO: check test/debug flag.
451+
app.loadConfig();
452+
return app;
453+
}
454+
}();
437455

438456
/******************************************************************************
439457
Start PyScript.
440458
******************************************************************************/
441-
const _pyscriptApp = main();
442-
_pyscriptApp.run();
459+
main();

0 commit comments

Comments
 (0)