From 7441d5250e8fc1df9019c7dc5dd840db0a732126 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Fri, 15 Mar 2019 12:51:22 -0400 Subject: [PATCH 1/5] Partially address #338: Provide simple method for interactive testing This adds a basic repl-like console webpage that can be used for testing of the local pyodide install. It removes the broken examples based on standalone iodide. --- Makefile | 25 +--- README.md | 13 +- src/console.html | 49 +++++++ src/matplotlib-sideload.html | 60 ++------ src/matplotlib.html | 209 --------------------------- src/python.html | 267 ----------------------------------- src/python_dev.html | 68 --------- 7 files changed, 72 insertions(+), 619 deletions(-) create mode 100644 src/console.html delete mode 100644 src/matplotlib.html delete mode 100644 src/python.html delete mode 100644 src/python_dev.html diff --git a/Makefile b/Makefile index d59e43601..5b6f7b1e9 100644 --- a/Makefile +++ b/Makefile @@ -50,10 +50,7 @@ all: build/pyodide.asm.js \ build/pyodide.asm.data \ build/pyodide.js \ build/pyodide_dev.js \ - build/python.html \ - build/python_dev.html \ - build/matplotlib.html \ - build/matplotlib-sideload.html \ + build/console.html \ build/renderedhtml.css \ build/test.data \ build/packages.json \ @@ -91,26 +88,14 @@ build/pyodide.js: src/pyodide.js sed -i -e "s#{{ABI}}#$(PYODIDE_PACKAGE_ABI)#g" $@ -build/python.html: src/python.html - cp $< $@ - - -build/python_dev.html: src/python_dev.html - cp $< $@ - - -build/matplotlib.html: src/matplotlib.html - cp $< $@ - - -build/matplotlib-sideload.html: src/matplotlib-sideload.html - cp $< $@ - - build/test.html: src/test.html cp $< $@ +build/console.html: src/console.html + cp $< $@ + + build/renderedhtml.css: src/renderedhtml.less lessc $< $@ diff --git a/README.md b/README.md index d23868c96..2737485f2 100644 --- a/README.md +++ b/README.md @@ -66,24 +66,27 @@ on your `PATH`. # Manual Testing -The port 8000 of the docker environment and the host system are automatically +The port 8000 of the docker environment and the host system are automatically binded when ``./run_docker`` is run. -This can be used to test the ``pyodide`` builds running within the docker +This can be used to test the ``pyodide`` builds running within the docker environment using external browser programs on the host system. To do this, simply run ``./bin/pyodide serve`` This serves the ``build`` directory of the ``pyodide`` project on port 8000. -* To serve a different directory, use the ``--build_dir`` argument followed by +* To serve a different directory, use the ``--build_dir`` argument followed by the path of the directory -* To serve on a different port, use the ``--port`` argument followed by the +* To serve on a different port, use the ``--port`` argument followed by the desired port number -Make sure that the port passed in ``--port`` argument is same as the one +Make sure that the port passed in ``--port`` argument is same as the one defined as ``DOCKER_PORT`` in the ``run_docker`` script. +Once the webserver is running, for simple interactive testing, visit the URL +[http://localhost:8000/console.html](http://localhost:8000/console.html) + # Benchmarking Install the same dependencies as for testing. diff --git a/src/console.html b/src/console.html new file mode 100644 index 000000000..fe50ec47c --- /dev/null +++ b/src/console.html @@ -0,0 +1,49 @@ + + + + + + + + + + + + + diff --git a/src/matplotlib-sideload.html b/src/matplotlib-sideload.html index 20821d279..30b8d165b 100644 --- a/src/matplotlib-sideload.html +++ b/src/matplotlib-sideload.html @@ -2,45 +2,9 @@ -Python - iodide - +Loading matplotlib example... - -
- - - diff --git a/src/python.html b/src/python.html deleted file mode 100644 index cf58601a6..000000000 --- a/src/python.html +++ /dev/null @@ -1,267 +0,0 @@ - - - - -Python - iodide - - - - -
- - - diff --git a/src/python_dev.html b/src/python_dev.html deleted file mode 100644 index 1db6f0219..000000000 --- a/src/python_dev.html +++ /dev/null @@ -1,68 +0,0 @@ - - - - -Python - iodide - - - - -
- - - From 0ceeff6588abe2b8c43f90ebe79edc12ce3953d2 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Tue, 19 Mar 2019 15:56:11 -0400 Subject: [PATCH 2/5] Improve console handling. Remove broken matplotlib-sideload --- src/console.html | 62 ++++++++++++++++++++++++++---------- src/matplotlib-sideload.html | 36 --------------------- 2 files changed, 46 insertions(+), 52 deletions(-) delete mode 100644 src/matplotlib-sideload.html diff --git a/src/console.html b/src/console.html index fe50ec47c..f797c59ae 100644 --- a/src/console.html +++ b/src/console.html @@ -5,14 +5,38 @@ + diff --git a/src/matplotlib-sideload.html b/src/matplotlib-sideload.html deleted file mode 100644 index 30b8d165b..000000000 --- a/src/matplotlib-sideload.html +++ /dev/null @@ -1,36 +0,0 @@ - - - - -Loading matplotlib example... - - - -
- - From c73c37e6ce55f67ec6572c976b30caf42db6ff7d Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Tue, 19 Mar 2019 16:52:54 -0400 Subject: [PATCH 3/5] Reset stdout/stderr buffers each time --- src/console.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/console.html b/src/console.html index f797c59ae..6f3d36c6d 100644 --- a/src/console.html +++ b/src/console.html @@ -26,11 +26,11 @@ window.term = term; pyodide.runPython( 'import io, code, sys\n' + - 'sys.stdout = io.StringIO()\n' + - 'sys.stderr = io.StringIO()\n' + 'from js import term, pyodide\n' + 'class Console(code.InteractiveConsole):\n' + ' def runcode(self, code):\n' + + ' sys.stdout = io.StringIO()\n' + + ' sys.stderr = io.StringIO()\n' + ' term.runPython("\\n".join(self.buffer))\n' + '_c = Console(locals=globals())' ) From 5a9f474717198ca4c37f175c4532ccd9d54e9b9d Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Thu, 21 Mar 2019 11:37:47 -0400 Subject: [PATCH 4/5] Only print console when done with a code chunk --- src/console.html | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/console.html b/src/console.html index 6f3d36c6d..b8c0f0952 100644 --- a/src/console.html +++ b/src/console.html @@ -42,14 +42,14 @@ term.set_prompt('[[;gray;]... ]') } else { term.set_prompt('[[;red;]>>> ]') - } - var stderr = pyodide.runPython("sys.stderr.getvalue()").trim() - if (stderr) { - term.echo(`[[;red;]${stderr}]`) - } else { - var stdout = pyodide.runPython("sys.stdout.getvalue()") - if (stdout) { - term.echo(stdout.trim()) + var stderr = pyodide.runPython("sys.stderr.getvalue()").trim() + if (stderr) { + term.echo(`[[;red;]${stderr}]`) + } else { + var stdout = pyodide.runPython("sys.stdout.getvalue()") + if (stdout) { + term.echo(stdout.trim()) + } } } } From 4e1ae73793794d5007e470ac33b164950a0e55d2 Mon Sep 17 00:00:00 2001 From: Marc Abramowitz Date: Thu, 21 Mar 2019 08:57:43 -0700 Subject: [PATCH 5/5] Use JS multi-line string for Python code so that the Python code looks nicer and is less error-prone to edit. --- src/console.html | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/console.html b/src/console.html index b8c0f0952..b5cecda7c 100644 --- a/src/console.html +++ b/src/console.html @@ -24,16 +24,17 @@ ); window.term = term; - pyodide.runPython( - 'import io, code, sys\n' + - 'from js import term, pyodide\n' + - 'class Console(code.InteractiveConsole):\n' + - ' def runcode(self, code):\n' + - ' sys.stdout = io.StringIO()\n' + - ' sys.stderr = io.StringIO()\n' + - ' term.runPython("\\n".join(self.buffer))\n' + - '_c = Console(locals=globals())' - ) + pyodide.runPython(` + import io, code, sys + from js import term, pyodide + + class Console(code.InteractiveConsole): + def runcode(self, code): + sys.stdout = io.StringIO() + sys.stderr = io.StringIO() + term.runPython("\\n".join(self.buffer)) + _c = Console(locals=globals()) + `) var c = pyodide.pyimport('_c')