Skip to content
Permalink
Browse files

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.
  • Loading branch information...
mdboom committed Mar 15, 2019
1 parent 89eca5f commit 7441d5250e8fc1df9019c7dc5dd840db0a732126
Showing with 70 additions and 617 deletions.
  1. +3 −18 Makefile
  2. +8 −5 README.md
  3. +49 −0 src/console.html
  4. +10 −50 src/matplotlib-sideload.html
  5. +0 −209 src/matplotlib.html
  6. +0 −267 src/python.html
  7. +0 −68 src/python_dev.html
@@ -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,23 +88,11 @@ 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
build/test.html: src/test.html
cp $< $@


build/test.html: src/test.html
build/console.html: src/console.html
cp $< $@


@@ -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.
@@ -0,0 +1,49 @@
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<script src="https://code.jquery.com/jquery-latest.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jquery.terminal/js/jquery.terminal.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/jquery.terminal/css/jquery.terminal.min.css" rel="stylesheet"/>
<script src="./pyodide_dev.js"></script>
</head>
<body>
<script>
languagePluginLoader.then(() => {
pyodide.runPython('import io, code, sys');
pyodide.runPython('_c = code.InteractiveConsole(locals=globals())')
var c = pyodide.pyimport('_c')
function handleResult(result) {
if (result) {
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()")
term.echo(stdout.trim())
}
}
function pushCode(line) {
pyodide.runPython('sys.stdout = io.StringIO()')
pyodide.runPython('sys.stderr = io.StringIO()')
if (line.startsWith('import ')) {
pyodide.runPythonAsync(line).then(handleResult)
} else {
handleResult(c.push(line))
}
}
var term = $('body').terminal(
pushCode,
{
greetings: "Welcome to the Pyodide terminal emulator 🐍",
prompt: "[[;red;]>>> ]"
}
);
});
</script>
</body>
</html>
@@ -2,70 +2,30 @@
<html>
<head>
<meta charset="UTF-8">
<title>Python - iodide</title>
<link rel="stylesheet" type="text/css" href="https://iodide.io/dist/iodide.pyodide-20180623.css">
<title>Loading matplotlib example...</title>
</head>
<body>
<script id="jsmd" type="text/jsmd">
%% meta
{
"title": "Python",
"languages": {
"js": {
"pluginType": "language",
"languageId": "js",
"displayName": "Javascript",
"codeMirrorMode": "javascript",
"module": "window",
"evaluator": "eval",
"keybinding": "j",
"url": ""
},
"py": {
"languageId": "py",
"displayName": "python",
"codeMirrorMode": "python",
"keybinding": "p",
"url": "https://iodide.io/pyodide-demo/pyodide.js",
"module": "pyodide",
"evaluator": "runPython",
"pluginType": "language"
}
},
"lastExport": "2018-05-04T17:13:00.489Z"
}
%% md
Press Shift+Enter on the cell below to display the plot.
%% code {"language":"py"}
</script>
<script>
var blackout = document.createElement('div');
blackout.setAttribute('style', 'width: 100%; height: 100%; position: absolute; left: 0; top: 0; background-color: #00000066; z-index: 10');
document.body.appendChild(blackout);
var url_string = window.location;
var url = new URL(url_string);
var content = url.searchParams.get("sideload");
var content = url.searchParams.get("example");
fetch(content).then((response) => response.text())
.then((text) => {
let jsmd = document.getElementById('jsmd');
jsmd.innerHTML = jsmd.innerHTML + text;
let script = document.createElement('script');
script.src = 'https://iodide.io/dist/iodide.pyodide-20180623.js';
script.onload = () => {
let pyodide = document.createElement('script');
pyodide.src = 'https://iodide.io/pyodide-demo/pyodide.js';
pyodide.onload = () => {
languagePluginLoader.then(() => {
window.pyodide.loadPackage('matplotlib').then(() => {
window.pyodide.runPython('__name__ = "__main__"');
blackout.parentNode.removeChild(blackout);
});
let pyodide = document.createElement('script');
pyodide.src = 'pyodide_dev.js';
pyodide.onload = () => {
languagePluginLoader.then(() => {
window.pyodide.loadPackage('matplotlib').then(() => {
window.pyodide.runPython('__name__ = "__main__"');
blackout.parentNode.removeChild(blackout);
});
};
});
document.body.appendChild(pyodide);
}
document.body.appendChild(script);
Oops, something went wrong.

0 comments on commit 7441d52

Please sign in to comment.
You can’t perform that action at this time.