add tests for runtime config inside py-config and remove usage of indexURL (#734)

* add integration test for py-config

* fix bug

* fix test

* remove indexURL altogether

* make jest happy

* fix create_proxy import

* check that py-config loads an older version

* add unit test

* suggested changes

* don't use /tmp because of bandit
This commit is contained in:
Madhur Tandon
2022-09-01 01:02:43 +05:30
committed by GitHub
parent eddde7c94c
commit e31e03afde
7 changed files with 130 additions and 17 deletions

View File

@@ -1,7 +1,6 @@
import { Runtime, RuntimeConfig } from './runtime';
import { getLastPath, inJest } from './utils';
import { getLastPath } from './utils';
import type { PyodideInterface } from 'pyodide';
import { loadPyodide } from 'pyodide';
// eslint-disable-next-line
// @ts-ignore
import pyscript from './python/pyscript.py';
@@ -30,17 +29,30 @@ export class PyodideRuntime extends Runtime {
this.lang = lang;
}
/**
* Although `loadPyodide` is used below,
* notice that it is not imported i.e.
* import { loadPyodide } from 'pyodide';
* is not used at the top of this file.
*
* This is because, if it's used, loadPyodide
* behaves mischievously i.e. it tries to load
* `pyodide.asm.js` and `pyodide_py.tar` but
* with paths that are wrong such as:
*
* http://127.0.0.1:8080/build/pyodide_py.tar
* which results in a 404 since `build` doesn't
* contain these files and is clearly the wrong
* path.
*/
async loadInterpreter(): Promise<void> {
console.log('creating pyodide runtime');
let indexURL: string = this.src.substring(0, this.src.length - '/pyodide.js'.length);
if (typeof process === 'object' && inJest()) {
indexURL = [process.cwd(), 'node_modules', 'pyodide'].join('/');
}
// eslint-disable-next-line
// @ts-ignore
this.interpreter = await loadPyodide({
stdout: console.log,
stderr: console.log,
fullStdLib: false,
indexURL,
});
this.globals = this.interpreter.globals;

View File

@@ -84,11 +84,4 @@ function handleFetchError(e: Error, singleFile: string) {
showError(errorContent);
}
/**
* determines if the process is running inside the testing suite i.e. jest
*/
function inJest(): boolean {
return process.env.JEST_WORKER_ID !== undefined;
}
export { addClasses, removeClasses, getLastPath, ltrim, htmlDecode, guidGenerator, showError, handleFetchError, inJest };
export { addClasses, removeClasses, getLastPath, ltrim, htmlDecode, guidGenerator, showError, handleFetchError };