Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Get Importable Zip from the server and set for the Client #22

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/extensions/scriptor/ScriptorRunner.vue
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ const messagewrapper = ref(null)
function startScriptor(){
state.opened = true
scriptorAction.value.executeScript()

}

watch(
Expand Down
15 changes: 13 additions & 2 deletions src/extensions/scriptor/public/webworker.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ let manager = {
}
}

async function loadPyodideAndPackages(id, pyoPackages, packages, initCode, transformCode) {
async function loadPyodideAndPackages(id, pyoPackages, packages, initCode, transformCode, importable) {
installLog(id, 1, "Loading python runtime")
self.pyodide = await loadPyodide({
stdout: stdout,
Expand All @@ -74,6 +74,11 @@ async function loadPyodideAndPackages(id, pyoPackages, packages, initCode, trans
`);

installLog(id, 4, `Initializing environment`);
if (importable !== undefined) {
await self.pyodide.unpackArchive(importable, "zip");
self.pyodide.pyimport("importable");
}

self.parray = undefined;
const src = `from pyodide.code import eval_code_async
from pyodide.ffi import to_js
Expand Down Expand Up @@ -145,7 +150,13 @@ self.onmessageerror = e => {
self.onmessage = async (event) => {
const { id, python, ...context } = event.data;
if (id === "_pyinstaller") {
await loadPyodideAndPackages(id, context.pyoPackages, context.packages, context.initCode, context.transformCode);
await loadPyodideAndPackages(
id,
context.pyoPackages,
context.packages,
context.initCode,
context.transformCode,
context.importable);
run_end(id)
}
else if (id === "_write")
Expand Down
14 changes: 13 additions & 1 deletion src/extensions/scriptor/store/scriptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {computed, reactive} from "vue"
import {defineStore} from "pinia"
import {useBrowserLocation, useWebWorker, useUrlSearchParams} from "@vueuse/core"
import {useContextStore} from "../../../stores/context";
import {Request} from "@viur/vue-utils";

export const useScriptorStore = defineStore("scriptorStore", () => {
const instanceTemplate = {
Expand Down Expand Up @@ -94,6 +95,16 @@ export const useScriptorStore = defineStore("scriptorStore", () => {


initCode = `with open("config.py", "w") as f:\n\tf.write("BASE_URL='${state.apiUrl}'")` + initCode
let importable = undefined
try {
const response = await Request.get("/json/script/get_importable");
if (response.status === 200) {
importable = await response.arrayBuffer();
}
}catch (e){}




if (state.workerObject) {
return new Promise((resolve) => {
Expand All @@ -105,7 +116,8 @@ export const useScriptorStore = defineStore("scriptorStore", () => {
pyoPackages: pyoPackages,
packages: packages,
initCode: initCode,
transformCode: "" //usage?
transformCode: "", //usage?
importable: importable,
})
})
}
Expand Down