Commit 4142ac0b authored by Michael Droettboom's avatar Michael Droettboom

Fix #291: Allow loading of arbitrary packages

parent b66c160d
......@@ -120,7 +120,6 @@ var languagePluginLoader = new Promise((resolve, reject) => {
});
} else {
console.error(`Unknown package '${package}'`);
return;
}
}
}
......@@ -176,7 +175,19 @@ var languagePluginLoader = new Promise((resolve, reject) => {
} else {
script.src = `${package_uri}`;
}
script.onerror = (e) => { reject(e); };
script.onerror = (e) => {
// If the package_uri fails to load, call monitorRunDependencies twice
// (so packageCounter will still hit 0 and finish loading), and remove
// the package from toLoad so we don't mark it as loaded.
console.log(`Couldn't load package from URL ${script.src}`)
let index = toLoad.indexOf(package);
if (index !== -1) {
toLoad.splice(index, 1);
}
for (let i = 0; i < 2; i++) {
window.pyodide._module.monitorRunDependencies();
}
};
document.body.appendChild(script);
}
......
import pytest
from pathlib import Path
import shutil
@pytest.mark.parametrize('active_server', ['main', 'secondary'])
def test_load_from_url(selenium_standalone, web_server_secondary,
......@@ -114,4 +117,33 @@ def test_load_handle_failure(selenium_standalone):
assert 'Loading pytz' in selenium.logs
assert 'Loading pytz2' in selenium.logs
assert "Unknown package 'pytz2'" in selenium.logs
assert "Couldn't load package from URL" in selenium.logs
assert 'Loading pyparsing' in selenium.logs # <- this fails
def test_load_package_unknown(selenium_standalone):
url = selenium_standalone.server_hostname
port = selenium_standalone.server_port
build_dir = Path(__file__).parent.parent / 'build'
shutil.copyfile(
build_dir / 'pyparsing.js',
build_dir / 'pyparsing-custom.js'
)
shutil.copyfile(
build_dir / 'pyparsing.data',
build_dir / 'pyparsing-custom.data'
)
try:
selenium_standalone.load_package(
f'http://{url}:{port}/pyparsing-custom.js'
)
finally:
(build_dir / 'pyparsing-custom.js').unlink()
(build_dir / 'pyparsing-custom.data').unlink()
assert selenium_standalone.run_js(
"return window.pyodide.loadedPackages."
"hasOwnProperty('pyparsing-custom')"
)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment