Skip to content

Commit

Permalink
fix: webworker buildscript update
Browse files Browse the repository at this point in the history
  • Loading branch information
akelch committed Aug 19, 2021
1 parent 72e5942 commit dd4bbf8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
28 changes: 19 additions & 9 deletions assets/js/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
// THIS IS THE DEFAULT PYODIDE WEBWORKER
importScripts("https://cdn.jsdelivr.net/pyodide/v0.18.0/full/pyodide.js");

async function loadScripts(scriptPath="../../../public/webworker") {
async function loadScripts(scriptPath="../../../webworker/",file="webworker_scripts.py") {
let promises = [];
let url = "webworker_scripts.py"

let path = ("/lib/python3.9/site-packages/scripts/" + url).split("/")
let path = ("/lib/python3.9/site-packages/scripts/" + file).split("/")

promises.push(
new Promise((resolve, reject) => {
//default workerScriptPath = "/app/s/flare/flare"
fetch(scriptPath+url, {}).then((response) => {
fetch(scriptPath+file, {}).then((response) => {
if (response.status === 200) {
response.text().then((code) => {
let lookup = "";
Expand Down Expand Up @@ -54,12 +51,25 @@ self.onmessage = async (event) => {
await pyodideReadyPromise;

const {python, ...context} = event.data;


let scriptsPath = "../../../webworker/"
if ("scriptPath" in context){
await loadScripts(context["scriptPath"]);
}else{
await loadScripts();
scriptsPath = context["scriptPath"]
}

const isCompiled = await (await fetch(scriptsPath+"webworker_scripts.pyc"))
console.log("---")
console.log(isCompiled)
console.log(scriptsPath)

let scriptFile = "webworker_scripts.py"
if (isCompiled.status === 200){
scriptFile = "webworker_scripts.pyc"
}

await loadScripts(scriptsPath,scriptFile);

for (const key of Object.keys(context)) {
self[key] = context[key];
}
Expand Down
8 changes: 6 additions & 2 deletions tools/flare.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def copySourcePy(source, target):
cleanSources(target)
copyflareAssets(source, target)
copypackageAssets(source, target)
copyWebworkerScripts(source,target)


def cleanSources(target):
Expand Down Expand Up @@ -93,7 +92,6 @@ def zipPy(target, packagename):

movingFlareBeforeZip(target, packagename)
movingPackagesBeforeZip(target, packagename)

os.system("rm -f files.zip") # remove old zip if exists
os.system(f"zip files.zip -r ./*") # zip this folder

Expand Down Expand Up @@ -237,6 +235,12 @@ def main():
if args.zip:
zipPy(args.target, args.name)

copyWebworkerScripts(args.source, args.target)
if args.minify:
minifyPy(os.path.join(args.target,"webworker"))
if args.compile:
compilePy(os.path.join(args.target,"webworker"))

copyAssets(args.source, args.target)

if args.watch:
Expand Down

0 comments on commit dd4bbf8

Please sign in to comment.