Played around with the ast module to try and fix the problems of https://github.com/PumasAI/QuartoNotebookRunner.jl/pull/180, mainly that the "Python" code there actually had to be valid Julia syntax, too, and that it wouldn't work with multiple expressions or any more complex thing.
Python only allows eval to be called on certain expressions and we can use ast to analyze whether we got those. Otherwise we call exec. One more special case is assignments, where we first exec and then eval the variable out.
I got this working so far:
---
engine: julia
execute:
error: true
---
```{julia}
using PythonCall
Played around with the
ast
module to try and fix the problems of https://github.com/PumasAI/QuartoNotebookRunner.jl/pull/180, mainly that the "Python" code there actually had to be valid Julia syntax, too, and that it wouldn't work with multiple expressions or any more complex thing.Python only allows
eval
to be called on certain expressions and we can useast
to analyze whether we got those. Otherwise we callexec
. One more special case is assignments, where we firstexec
and theneval
the variable out.I got this working so far: