1
0
mirror of https://github.com/pyscript/pyscript.git synced 2022-05-01 19:47:48 +03:00

fix enviroment promise loading bug on pyenv

This commit is contained in:
Fabio Pliger
2022-04-28 15:59:35 -06:00
parent 0124aa0acd
commit 788af88422
2 changed files with 17 additions and 5 deletions

View File

@@ -14,12 +14,15 @@
const initializePyodide = async () => {
pyodideReadyPromise = loadInterpreter();
const pyodide = await pyodideReadyPromise;
let newEnv = {
id: 'a',
promise: pyodideReadyPromise,
runtime: pyodide,
state: 'loading',
};
pyodideLoaded.set(pyodideReadyPromise);
pyodideLoaded.set(pyodide);
loadedEnvironments.update((value: any): any => {
value[newEnv['id']] = newEnv;
});

View File

@@ -5,12 +5,21 @@ import { loadPackage, loadFromFile } from '../interpreter';
// Premise used to connect to the first available pyodide interpreter
let pyodideReadyPromise;
let runtime;
pyodideLoaded.subscribe(value => {
runtime = value;
console.log("RUNTIME READY")
});
export class PyEnv extends HTMLElement {
shadow: ShadowRoot;
wrapper: HTMLElement;
code: string;
environment: any;
runtime: any;
env: string[];
paths: string[];
constructor() {
super();
@@ -40,20 +49,20 @@ export class PyEnv extends HTMLElement {
}
async function loadEnv() {
const pyodide = await pyodideReadyPromise;
await loadPackage(env, pyodide);
await loadPackage(env, runtime);
console.log('enviroment loaded');
}
async function loadPaths() {
const pyodide = await pyodideReadyPromise;
for (const singleFile of paths) {
await loadFromFile(singleFile, pyodide);
await loadFromFile(singleFile, runtime);
}
console.log('paths loaded');
}
addInitializer(loadEnv);
addInitializer(loadPaths);
console.log('enviroment loading...', env);
console.log('enviroment loading...', this.env);
}
}