Fix #2246 - Override builtins.input to avoid duplicating it (#2254)

This commit is contained in:
Andrea Giammarchi
2024-11-25 14:17:30 +01:00
committed by GitHub
parent 0a1d3bb678
commit 796373cfa6
6 changed files with 28 additions and 4 deletions

View File

@@ -1,12 +1,12 @@
{
"name": "@pyscript/core",
"version": "0.6.19",
"version": "0.6.20",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@pyscript/core",
"version": "0.6.19",
"version": "0.6.20",
"license": "APACHE-2.0",
"dependencies": {
"@ungap/with-resolvers": "^0.1.0",

View File

@@ -1,6 +1,6 @@
{
"name": "@pyscript/core",
"version": "0.6.19",
"version": "0.6.20",
"type": "module",
"description": "PyScript",
"module": "./index.js",

View File

@@ -137,6 +137,18 @@ export default async (element) => {
// setup remote thread JS/Python code for whenever the
// worker is ready to become a terminal
hooks.worker.onReady.add(workerReady);
// @see https://github.com/pyscript/pyscript/issues/2246
const patchInput = [
"import builtins as _b",
"from pyscript import sync as _s",
"_b.input = _s.pyterminal_read",
"del _b",
"del _s",
].join("\n");
hooks.worker.codeBeforeRun.add(patchInput);
hooks.worker.codeBeforeRunAsync.add(patchInput);
} else {
// in the main case, just bootstrap XTerm without
// allowing any input as that's not possible / awkward

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,11 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<script type="module" src="../../../dist/core.js"></script>
</head>
<body>
<script type="py" src="./main.py" terminal worker></script>
</body>
</html>

View File

@@ -0,0 +1 @@
print(input("What food would you like me to get from the shop? "))