Skip to content

Commit ab51558

Browse files
authored
Merge pull request #282 from messense/pyodide-0.21
Update to Pyodide 0.21.0
2 parents 6d87a5b + 015fe5f commit ab51558

File tree

2 files changed

+73
-4
lines changed

2 files changed

+73
-4
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,10 +412,10 @@ jobs:
412412
with:
413413
node-version: 18
414414
- run: |
415-
PYODIDE_VERSION=0.21.0-alpha.3
415+
PYODIDE_VERSION=0.21.0
416416
417417
cd emscripten
418-
npm i [email protected]-alpha.3 prettier
418+
npm i [email protected] prettier
419419
cd node_modules/pyodide/
420420
node ../prettier/bin-prettier.js -w pyodide.asm.js
421421
EMSCRIPTEN_VERSION=$(node -p "require('./repodata.json').info.platform.split('_').slice(1).join('.')")

emscripten/runner.js

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,104 @@ const { loadPyodide } = require("pyodide");
44
async function findWheel(distDir) {
55
const dir = await opendir(distDir);
66
for await (const dirent of dir) {
7-
if (dirent.name.endsWith("whl")) {
7+
if (dirent.name.includes("emscripten") && dirent.name.endsWith("whl")) {
88
return dirent.name;
99
}
1010
}
1111
}
1212

13+
function make_tty_ops(stream){
14+
return {
15+
// get_char has 3 particular return values:
16+
// a.) the next character represented as an integer
17+
// b.) undefined to signal that no data is currently available
18+
// c.) null to signal an EOF
19+
get_char(tty) {
20+
if (!tty.input.length) {
21+
var result = null;
22+
var BUFSIZE = 256;
23+
var buf = Buffer.alloc(BUFSIZE);
24+
var bytesRead = fs.readSync(process.stdin.fd, buf, 0, BUFSIZE, -1);
25+
if (bytesRead === 0) {
26+
return null;
27+
}
28+
result = buf.slice(0, bytesRead);
29+
tty.input = Array.from(result);
30+
}
31+
return tty.input.shift();
32+
},
33+
put_char(tty, val) {
34+
try {
35+
if(val !== null){
36+
tty.output.push(val);
37+
}
38+
if (val === null || val === 10) {
39+
process.stdout.write(Buffer.from(tty.output));
40+
tty.output = [];
41+
}
42+
} catch(e){
43+
console.warn(e);
44+
}
45+
},
46+
flush(tty) {
47+
if (!tty.output || tty.output.length === 0) {
48+
return;
49+
}
50+
stream.write(Buffer.from(tty.output));
51+
tty.output = [];
52+
}
53+
};
54+
}
55+
56+
function setupStreams(FS, TTY){
57+
let mytty = FS.makedev(FS.createDevice.major++, 0);
58+
let myttyerr = FS.makedev(FS.createDevice.major++, 0);
59+
TTY.register(mytty, make_tty_ops(process.stdout))
60+
TTY.register(myttyerr, make_tty_ops(process.stderr))
61+
FS.mkdev('/dev/mytty', mytty);
62+
FS.mkdev('/dev/myttyerr', myttyerr);
63+
FS.unlink('/dev/stdin');
64+
FS.unlink('/dev/stdout');
65+
FS.unlink('/dev/stderr');
66+
FS.symlink('/dev/mytty', '/dev/stdin');
67+
FS.symlink('/dev/mytty', '/dev/stdout');
68+
FS.symlink('/dev/myttyerr', '/dev/stderr');
69+
FS.closeStream(0);
70+
FS.closeStream(1);
71+
FS.closeStream(2);
72+
var stdin = FS.open('/dev/stdin', 0);
73+
var stdout = FS.open('/dev/stdout', 1);
74+
var stderr = FS.open('/dev/stderr', 1);
75+
}
76+
77+
1378
const pkgDir = process.argv[2];
1479
const distDir = pkgDir + "/dist";
1580
const testDir = pkgDir + "/tests";
1681

1782
async function main() {
1883
const wheelName = await findWheel(distDir);
1984
const wheelURL = `file:${distDir}/${wheelName}`;
85+
let errcode = 1;
2086

2187
try {
2288
pyodide = await loadPyodide();
2389
const FS = pyodide.FS;
90+
setupStreams(FS, pyodide._module.TTY);
2491
const NODEFS = FS.filesystems.NODEFS;
2592
FS.mkdir("/test_dir");
2693
FS.mount(NODEFS, { root: testDir }, "/test_dir");
2794
await pyodide.loadPackage(["micropip", "pytest", "tomli"]);
2895
const micropip = pyodide.pyimport("micropip");
96+
await micropip.install("beautifulsoup4");
2997
await micropip.install(wheelURL);
3098
const pytest = pyodide.pyimport("pytest");
31-
errcode = pytest.main(pyodide.toPy(["/test_dir", "-vv"]));
99+
errcode = pytest.main(pyodide.toPy(["/test_dir"]));
32100
} catch (e) {
33101
console.error(e);
34102
process.exit(1);
35103
}
104+
process.exit(errcode);
36105
}
37106

38107
main();

0 commit comments

Comments
 (0)