From 6de43c9e19a292e58305a98621379824bcc437aa Mon Sep 17 00:00:00 2001 From: Roman Yurchak Date: Thu, 20 Sep 2018 11:07:45 +0200 Subject: [PATCH] Update Module.locateFile inside _loadPackage --- src/pyodide.js | 31 ++++++++++++++++--------------- test/conftest.py | 2 +- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/pyodide.js b/src/pyodide.js index 06f4318d7..99f76ee75 100644 --- a/src/pyodide.js +++ b/src/pyodide.js @@ -38,7 +38,6 @@ var languagePluginLoader = new Promise((resolve, reject) => { let loadedPackages = window.pyodide.loadedPackages; let queue = [].concat(names || []); let toLoad = new Array(); - window.pyodide._toLoadPackages = toLoad; while (queue.length) { let package_uri = queue.pop(); @@ -81,6 +80,20 @@ var languagePluginLoader = new Promise((resolve, reject) => { } } + console.log(`Trying to load ${Object.keys(toLoad)}`); + + window.pyodide._module.locateFile = (path) => { + // handle packages loaded from custom URLs + let package = path.replace(/\.data$/, ""); + if (package in toLoad) { + let package_uri = toLoad[package]; + if (package_uri != 'default channel') { + return package_uri.replace(/\.js$/, ".data"); + }; + }; + return baseURL + path; + }; + let promise = new Promise((resolve, reject) => { if (Object.keys(toLoad).length === 0) { resolve('No new packages to load'); @@ -162,6 +175,7 @@ var languagePluginLoader = new Promise((resolve, reject) => { // Rearrange namespace for public API let PUBLIC_API = [ 'loadPackage', + 'loadedPackages', 'pyimport', 'repr', 'runPython', @@ -197,20 +211,7 @@ var languagePluginLoader = new Promise((resolve, reject) => { return {}; }; - Module.locateFile = (path) => { - if ((window.hasOwnProperty('pyodide')) && - (window.pyodide.hasOwnProperty('_toLoadPackages'))) { - // handle packages loaded from custom URLs - let package = path.replace(/\.data$/, ""); - if (package in window.pyodide._toLoadPackages) { - let package_uri = window.pyodide._toLoadPackages[package]; - if (package_uri != 'default channel') { - return package_uri.replace(/\.js$/, ".data"); - }; - }; - }; - return baseURL + path; - }; + Module.locateFile = (path) => baseURL + path; var postRunPromise = new Promise((resolve, reject) => { Module.postRun = () => { delete window.Module; diff --git a/test/conftest.py b/test/conftest.py index c1c340ed5..090eec6b2 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -112,7 +112,7 @@ class SeleniumWrapper: except TimeoutException as exc: _display_driver_logs(self.browser, self.driver) print(self.logs) - raise TimeoutException() + raise TimeoutException('wait_until_packages_loaded timed out') @property def urls(self):