add pyenv and allow to load packages to the loaded pyodide runtime

This commit is contained in:
Fabio Pliger
2022-04-06 14:45:34 -05:00
parent 1484aadb7a
commit 9d64a9f126
5 changed files with 63 additions and 15 deletions

View File

@@ -0,0 +1,49 @@
import * as jsyaml from 'js-yaml';
import { pyodideLoaded, loadedEnvironments, mode, addPostInitializer } from '../stores';
import { loadPackage } from '../interpreter';
// Premise used to connect to the first available pyodide interpreter
let pyodideReadyPromise;
let environments;
let currentMode;
pyodideLoaded.subscribe(value => {
pyodideReadyPromise = value;
});
loadedEnvironments.subscribe(value => {
environments = value;
});
mode.subscribe(value => {
currentMode = value;
});
export class PyEnv extends HTMLElement {
shadow: ShadowRoot;
wrapper: HTMLElement;
code: string;
environment: any;
constructor() {
super();
// attach shadow so we can preserve the element original innerHtml content
this.shadow = this.attachShadow({ mode: 'open'});
this.wrapper = document.createElement('slot');
}
connectedCallback() {
this.code = this.innerHTML;
this.innerHTML = '';
let env = this.environment = jsyaml.load(this.code);
async function loadEnv(){
let pyodide = await pyodideReadyPromise;
loadPackage(env, pyodide);
console.log("enviroment loaded")
}
addPostInitializer(loadEnv);
console.log("enviroment loading...")
}
}