extrabacon / python-shell

Run Python scripts from Node.js with simple (but efficient) inter-process communication through stdio
2.12k stars 224 forks source link

checkSyntax function that doesn't write to a file #295

Open Almenon opened 1 year ago

Almenon commented 1 year ago

Is your feature request related to a problem? Please describe. If I call checkSyntax very frequently I'm going be writing a ton of temp files. Would be nice to avoid that overhead and just feed in the string through stdin.

Describe the solution you'd like checkSyntax using stdin

Describe alternatives you've considered overhead might not be a big deal?

Additional context Related to re-architecture work in https://github.com/Almenon/AREPL-vscode/issues/439. I'd like to throw away pythonGuiLibraryIsPresent and just check syntax all the time. Less code needed and much less hacky because one doesn't have to list out each GUI library.

Almenon commented 1 year ago

I did a bit of performance analysis:

startTime=Date.now();PythonShell.checkSyntax('f=1;f=2;f=3;f=4;f=5;f=6;f=7;f=1;f=2;f=3;f=4;f=5;f=6;f=7;f=1;f=2;f=3;f=4;f=5;f=6;f=7;f=1;f=2;f=3;f=4;f=5;f=6;f=7;f=1;f=2;f=3;f=4;f=5;f=6;f=7;f=1;f=2;f=3;f=4;f=5;f=6;f=7;f=1;f=2;f=3;f=4;f=5;f=6;f=7;f=1;f=2;f=3;f=4;f=5;f=6;f=7;f=1;f=2;f=3;f=4;f=5;f=6;f=7;f=1;f=2;f=3;f=4;f=5;f=6;f=7;f=1;f=2;f=3;f=4;f=5;f=6;f=7;f=1;f=2;f=3;f=4;f=5;f=6;f=7;f=1;f=2;f=3;f=4;f=5;f=6;f=7;f=1;f=2;f=3;f=4;f=5;f=6;f=7;f=1;f=2;f=3;f=4;f=5;f=6;f=7;f=1;f=2;f=3;f=4;f=5;f=6;f=7;f=1;f=2;f=3;f=4;f=5;f=6;f=7;f=1;f=2;f=3;f=4;f=5;f=6;f=7;f=1;f=2;f=3;f=4;f=5;f=6;f=7;f=1;f=2;f=3;f=4;f=5;f=6;f=7;f=1;f=2;f=3;f=4;f=5;f=6;f=7;').then(o=>{console.log(Date.now()-startTime)})

result stays around 120 ms

time python -c "compile('f=1;f=2;f=3;f=4;f=5;f=6;f=7;f=1;f=2;f=3;f=4;f=5;f=6;f=7;f=1;f=2;f=3;f=4;f=5;f=6;f=7;f=1;f=2;f=3;f=4;f=5;f=6;f=7;f=1;f=2;f=3;f=4;f=5;f=6;f=7;f=1;f=2;f=3;f=4;f=5;f=6;f=7;f=1;f=2;f=3;f=4;f=5;f=6;f=7;f=1;f=2;f=3;f=4;f=5;f=6;f=7;f=1;f=2;f=3;f=4;f=5;f=6;f=7;f=1;f=2;f=3;f=4;f=5;f=6;f=7;f=1;f=2;f=3;f=4;f=5;f=6;f=7;f=1;f=2;f=3;f=4;f=5;f=6;f=7;f=1;f=2;f=3;f=4;f=5;f=6;f=7;f=1;f=2;f=3;f=4;f=5;f=6;f=7;f=1;f=2;f=3;f=4;f=5;f=6;f=7;f=1;f=2;f=3;f=4;f=5;f=6;f=7;f=1;f=2;f=3;f=4;f=5;f=6;f=7;f=1;f=2;f=3;f=4;f=5;f=6;f=7;f=1;f=2;f=3;f=4;f=5;f=6;f=7;f=1;f=2;f=3;f=4;f=5;f=6;f=7;f=1;f=2;f=3;f=4;f=5;f=6;f=7;', '','exec')";

result started at 100ms then went down to a consistent 20ms

 time cat tictactoe.py | python -c "from sys import stdin;i=''.join([l for l in stdin]);compile(i,'','exec')";

was also around 20ms

Almenon commented 1 year ago

Another reason this would be a good change is windows doesn't clear the temp directory by default, so temporary syntax-checked python files will keep on piling up forever.

PlakxD commented 2 months ago

I would like to work on this issue, however I am new to contributing to Python Shell. Is there anywhere I can go to sign up for write access to non-master branches?

Almenon commented 2 months ago

@PlakxD I'm not the admin of this repo, so I can't give out write access, but you can fork the repo and then submit a PR.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork