Fix #1840 - Do not bootstrap interactive shell (#1846)

This commit is contained in:
Andrea Giammarchi
2023-11-07 19:22:08 +01:00
committed by GitHub
parent f1a46be738
commit 2d50ca86a6
5 changed files with 21 additions and 27 deletions

View File

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

View File

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

View File

@@ -98,12 +98,6 @@ const pyTerminal = async () => {
});
};
// at the end of the code, make the terminal interactive
const codeAfter = `
import code as _code
_code.interact()
`;
// add a hook on the main thread to setup all sync helpers
// also bootstrapping the XTerm target on main
hooks.main.onWorker.add(function worker(_, xworker) {
@@ -118,14 +112,12 @@ const pyTerminal = async () => {
// allow a worker to drop main thread hooks ASAP
xworker.sync.pyterminal_drop_hooks = () => {
hooks.worker.onReady.delete(workerReady);
hooks.worker.codeAfterRun.delete(codeAfter);
};
});
// setup remote thread JS/Python code for whenever the
// worker is ready to become a terminal
hooks.worker.onReady.add(workerReady);
hooks.worker.codeAfterRun.add(codeAfter);
} else {
// in the main case, just bootstrap XTerm without
// allowing any input as that's not possible / awkward

View File

@@ -15,13 +15,14 @@
</script>
<py-script worker terminal>
import sys
from pyscript import display
from pyscript import display, document
display("Hello", "PyScript Next - PyTerminal", append=False)
print("this should go to the terminal")
print("another line")
# this works as expected
print("this goes to stderr", file=sys.stderr)
document.addEventListener('click', lambda event: print(event.type));
</py-script>
<button id="my-button" py-click="greetings">Click me</button>
</body>

View File

@@ -24,21 +24,22 @@ class TestPyTerminal(PyScriptTest):
with pytest.raises(PageErrors, match="You can use at most 1 terminal"):
self.check_js_errors()
@only_worker
def test_py_terminal_input(self):
"""
Only worker py-terminal accepts an input
"""
self.pyscript_run(
"""
<script type="py" terminal></script>
""",
wait_for_pyscript=False,
)
self.page.get_by_text(">>> ", exact=True).wait_for()
self.page.keyboard.type("'the answer is ' + str(6 * 7)")
self.page.keyboard.press("Enter")
self.page.get_by_text("the answer is 42").wait_for()
# TODO: interactive shell still unclear
# @only_worker
# def test_py_terminal_input(self):
# """
# Only worker py-terminal accepts an input
# """
# self.pyscript_run(
# """
# <script type="py" terminal></script>
# """,
# wait_for_pyscript=False,
# )
# self.page.get_by_text(">>> ", exact=True).wait_for()
# self.page.keyboard.type("'the answer is ' + str(6 * 7)")
# self.page.keyboard.press("Enter")
# self.page.get_by_text("the answer is 42").wait_for()
@only_worker
def test_py_terminal_os_write(self):