From 29c5825fc7359581fd792dc947bd68ab4de01be4 Mon Sep 17 00:00:00 2001 From: almenon Date: Sat, 24 Jun 2023 11:21:03 -0700 Subject: [PATCH] changes so far --- package.json | 27 +---------------- src/PreviewManager.ts | 6 ++-- src/pyGuiLibraryIsPresent.ts | 17 ----------- src/toAREPLLogic.ts | 58 +++++++++++++----------------------- 4 files changed, 26 insertions(+), 82 deletions(-) delete mode 100644 src/pyGuiLibraryIsPresent.ts diff --git a/package.json b/package.json index 4cdccf1..dba09a5 100644 --- a/package.json +++ b/package.json @@ -76,39 +76,14 @@ }, "AREPL.delay": { "type": "number", - "default": 300, + "default": 350, "description": "delay in milliseconds before executing code after typing" }, - "AREPL.restartDelay": { - "type": "number", - "default": 300, - "description": "when restart mode is active we add this to delay to delay longer" - }, "AREPL.inlineResults": { "type": "boolean", "default": true, "description": "whether to show errors / results / prints inline. (Currently just error icons)" }, - "AREPL.pyGuiLibraries": { - "type": "array", - "default": [ - "matplotlib", - "tkinter", - "kivy", - "pyforms", - "PyQt4", - "PyQt5", - "wx", - "pyside", - "plotly", - "ggplot", - "bokeh", - "ppb", - "PySimpleGUI", - "pyglet" - ], - "description": "AREPL enters restart mode when one of these libraries are imported. Process is restarted at end of each run so GUI window is updated" - }, "AREPL.whenToExecute": { "type": "string", "enum": [ diff --git a/src/PreviewManager.ts b/src/PreviewManager.ts index 32b4670..b9c1c03 100644 --- a/src/PreviewManager.ts +++ b/src/PreviewManager.ts @@ -149,6 +149,7 @@ export default class PreviewManager { default_filter_types: settingsCached.get('defaultFilterTypes') } this.previewContainer.clearStoredData() + // refactor this to use last ran evaluator this.PythonEvaluator.execCode(data) this.runningStatus.show() @@ -220,12 +221,14 @@ export default class PreviewManager { // basically all this does is load a file.. why does it need to be async *sob* const env = await this.loadAndWatchEnvVars() + // start three evaluators and save them to dict by name this.PythonEvaluator = new PythonEvaluator({ pythonOptions, pythonPath, env, }) + // put below two in a loop for each evaluator try { console.log('Starting python with path ' + pythonPath) this.PythonEvaluator.start() @@ -255,6 +258,7 @@ export default class PreviewManager { this.reporter.sendError(err, err.errno, 'spawn') }) this.PythonEvaluator.pyshell.childProcess.on("exit", err => { + // might need to rethink this method now that i kill arepl on purpose... if(!err) return // normal exit console.debug('exit handler invoked w/ ' + err) this.previewContainer.displayProcessError(`err code: ${err}`); @@ -288,8 +292,6 @@ export default class PreviewManager { const cachedSettings = settings() if(cachedSettings.get("whenToExecute") == "afterDelay"){ let delay = cachedSettings.get("delay"); - const restartExtraDelay = cachedSettings.get("restartDelay"); - delay += this.toAREPLLogic.restartMode ? restartExtraDelay : 0 this.PythonEvaluator.debounce(this.onAnyDocChange.bind(this, e.document), delay) } }, this, this.subscriptions) diff --git a/src/pyGuiLibraryIsPresent.ts b/src/pyGuiLibraryIsPresent.ts deleted file mode 100644 index 2fc68a8..0000000 --- a/src/pyGuiLibraryIsPresent.ts +++ /dev/null @@ -1,17 +0,0 @@ -import {settings} from "./settings" - -export default function pythonGuiLibraryIsPresent(code: string){ - let pyGuiLibraries = settings().get("pyGuiLibraries") - pyGuiLibraries = pyGuiLibraries.filter(library => library.trim() != "") - if(pyGuiLibraries.length == 0){ - return false - } - - const pyGuiLibrariesImport = new RegExp("^import (" + pyGuiLibraries.join("|") + ")", "im") - const pyGuiLibrariesFromImport = new RegExp("^from (" + pyGuiLibraries.join("|") + ")", "im") - - if(code.match(pyGuiLibrariesImport) || code.match(pyGuiLibrariesFromImport)){ - return true - } - else return false -} \ No newline at end of file diff --git a/src/toAREPLLogic.ts b/src/toAREPLLogic.ts index 1a6f5ad..5158fdc 100644 --- a/src/toAREPLLogic.ts +++ b/src/toAREPLLogic.ts @@ -1,6 +1,5 @@ import {PythonEvaluator, ExecArgs} from "arepl-backend" import {PreviewContainer} from "./previewContainer" -import pyGuiLibraryIsPresent from "./pyGuiLibraryIsPresent" import {settings} from "./settings" /** @@ -9,8 +8,6 @@ import {settings} from "./settings" */ export class ToAREPLLogic{ - restartMode: boolean - restartedLastTime = false lastSavedSection = "" lastCodeSection = "" lastEndSection = "" @@ -80,36 +77,27 @@ export class ToAREPLLogic{ this.lastCodeSection = data.evalCode this.lastSavedSection = data.savedCode this.lastEndSection = endSection - - this.restartMode = pyGuiLibraryIsPresent(text) - - if(this.restartMode) { - this.checkSyntaxAndRestart(data) - } - else if(this.restartedLastTime){ // if GUI code is gone need one last restart to get rid of GUI - this.restartPython(data) - this.restartedLastTime = false; - } - else{ - this.PythonEvaluator.execCode(data) - } - - return true - } - - /** - * checks syntax before restarting - if syntax error it doesnt bother restarting but instead just shows syntax error - * This is useful because we want to restart as little as possible - */ - private checkSyntaxAndRestart(data: {evalCode: string, savedCode: string, filePath: string}){ let syntaxPromise: Promise<{}> - - // #22 it might be faster to use checkSyntaxFile but this is simpler + + // only execute code if syntax is correct + // this is because it's annoying to have GUI apps restart constantly + // while typing syntaxPromise = this.PythonEvaluator.checkSyntax(data.savedCode + data.evalCode) - syntaxPromise.then(() => { - this.restartPython(data) - this.restartedLastTime = true + // to check for free executor: + // freeEvaluator = evaluators.first(evaluator=>evaluator.free) + + // cancel setinterval + // restart all Executing or DirtyFree processes + // if no freshfree executor: + setInterval(()=>{ + // if free executor, send code + }, 60) + // else: send code to first free executor + // send code func: + // foo.execCode(data) + // set last ran executor + this.PythonEvaluator.execCode(data) }) .catch((error: NodeJS.ErrnoException|string) => { @@ -130,12 +118,8 @@ export class ToAREPLLogic{ } ) }) + + return true } - - private restartPython(data: {evalCode: string, savedCode: string, filePath: string}){ - this.previewContainer.clearStoredData() - this.PythonEvaluator.restart( - this.PythonEvaluator.execCode.bind(this.PythonEvaluator, data) - ); - } + }