From 9ec8e298170a078ddee391b870f10ba78fab64a4 Mon Sep 17 00:00:00 2001 From: messense Date: Thu, 11 Aug 2022 14:08:12 +0800 Subject: [PATCH 1/4] Update Pyodide to 0.21.0 --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b2068b1a..7559d9ec 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -412,10 +412,10 @@ jobs: with: node-version: 18 - run: | - PYODIDE_VERSION=0.21.0-alpha.3 + PYODIDE_VERSION=0.21.0 cd emscripten - npm i pyodide@0.21.0-alpha.3 prettier + npm i pyodide@0.21.0 prettier cd node_modules/pyodide/ node ../prettier/bin-prettier.js -w pyodide.asm.js EMSCRIPTEN_VERSION=$(node -p "require('./repodata.json').info.platform.split('_').slice(1).join('.')") From e3fab07a13946e0e1238abbb08e949c38fe2916e Mon Sep 17 00:00:00 2001 From: messense Date: Thu, 11 Aug 2022 14:09:36 +0800 Subject: [PATCH 2/4] Fix writing to stdout in emscripten tests --- emscripten/runner.js | 68 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/emscripten/runner.js b/emscripten/runner.js index 654893d5..cd235aa8 100644 --- a/emscripten/runner.js +++ b/emscripten/runner.js @@ -4,12 +4,77 @@ const { loadPyodide } = require("pyodide"); async function findWheel(distDir) { const dir = await opendir(distDir); for await (const dirent of dir) { - if (dirent.name.endsWith("whl")) { + if (dirent.name.includes("emscripten") && dirent.name.endsWith("whl")) { return dirent.name; } } } +function make_tty_ops(stream){ + return { + // get_char has 3 particular return values: + // a.) the next character represented as an integer + // b.) undefined to signal that no data is currently available + // c.) null to signal an EOF + get_char(tty) { + if (!tty.input.length) { + var result = null; + var BUFSIZE = 256; + var buf = Buffer.alloc(BUFSIZE); + var bytesRead = fs.readSync(process.stdin.fd, buf, 0, BUFSIZE, -1); + if (bytesRead === 0) { + return null; + } + result = buf.slice(0, bytesRead); + tty.input = Array.from(result); + } + return tty.input.shift(); + }, + put_char(tty, val) { + try { + if(val !== null){ + tty.output.push(val); + } + if (val === null || val === 10) { + process.stdout.write(Buffer.from(tty.output)); + tty.output = []; + } + } catch(e){ + console.warn(e); + } + }, + flush(tty) { + if (!tty.output || tty.output.length === 0) { + return; + } + stream.write(Buffer.from(tty.output)); + tty.output = []; + } + }; +} + +function setupStreams(FS, TTY){ + let mytty = FS.makedev(FS.createDevice.major++, 0); + let myttyerr = FS.makedev(FS.createDevice.major++, 0); + TTY.register(mytty, make_tty_ops(process.stdout)) + TTY.register(myttyerr, make_tty_ops(process.stderr)) + FS.mkdev('/dev/mytty', mytty); + FS.mkdev('/dev/myttyerr', myttyerr); + FS.unlink('/dev/stdin'); + FS.unlink('/dev/stdout'); + FS.unlink('/dev/stderr'); + FS.symlink('/dev/mytty', '/dev/stdin'); + FS.symlink('/dev/mytty', '/dev/stdout'); + FS.symlink('/dev/myttyerr', '/dev/stderr'); + FS.closeStream(0); + FS.closeStream(1); + FS.closeStream(2); + var stdin = FS.open('/dev/stdin', 0); + var stdout = FS.open('/dev/stdout', 1); + var stderr = FS.open('/dev/stderr', 1); +} + + const pkgDir = process.argv[2]; const distDir = pkgDir + "/dist"; const testDir = pkgDir + "/tests"; @@ -21,6 +86,7 @@ async function main() { try { pyodide = await loadPyodide(); const FS = pyodide.FS; + setupStreams(FS, pyodide._module.TTY); const NODEFS = FS.filesystems.NODEFS; FS.mkdir("/test_dir"); FS.mount(NODEFS, { root: testDir }, "/test_dir"); From d7fa39bf1a50ed125f343ad47f607f4a636bdc20 Mon Sep 17 00:00:00 2001 From: messense Date: Thu, 11 Aug 2022 14:27:55 +0800 Subject: [PATCH 3/4] Fix emscripten runner process exit code --- emscripten/runner.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/emscripten/runner.js b/emscripten/runner.js index cd235aa8..df929330 100644 --- a/emscripten/runner.js +++ b/emscripten/runner.js @@ -82,6 +82,7 @@ const testDir = pkgDir + "/tests"; async function main() { const wheelName = await findWheel(distDir); const wheelURL = `file:${distDir}/${wheelName}`; + let errcode = 1; try { pyodide = await loadPyodide(); @@ -94,11 +95,12 @@ async function main() { const micropip = pyodide.pyimport("micropip"); await micropip.install(wheelURL); const pytest = pyodide.pyimport("pytest"); - errcode = pytest.main(pyodide.toPy(["/test_dir", "-vv"])); + errcode = pytest.main(pyodide.toPy(["/test_dir"])); } catch (e) { console.error(e); process.exit(1); } + process.exit(errcode); } main(); From 015fe5f003a4a0ac0cbfc19e8ce48222610c8fba Mon Sep 17 00:00:00 2001 From: messense Date: Thu, 11 Aug 2022 14:44:33 +0800 Subject: [PATCH 4/4] micropip install beautifulsoup4 --- emscripten/runner.js | 1 + 1 file changed, 1 insertion(+) diff --git a/emscripten/runner.js b/emscripten/runner.js index df929330..68bf0ea1 100644 --- a/emscripten/runner.js +++ b/emscripten/runner.js @@ -93,6 +93,7 @@ async function main() { FS.mount(NODEFS, { root: testDir }, "/test_dir"); await pyodide.loadPackage(["micropip", "pytest", "tomli"]); const micropip = pyodide.pyimport("micropip"); + await micropip.install("beautifulsoup4"); await micropip.install(wheelURL); const pytest = pyodide.pyimport("pytest"); errcode = pytest.main(pyodide.toPy(["/test_dir"]));