PumasAI / QuartoNotebookRunner.jl

MIT License
63 stars 10 forks source link

Add ability to render Python with PythonCall #180

Closed tuncbkose closed 2 months ago

tuncbkose commented 2 months ago

Hi, I saw #108 and thought "I may use that" so tried adding it myself. I'm not sure if this is acceptable for a merge (it is not even fully ready yet), but I thought I may put it here in case it would be useful to someone.

Be warned that both this package and PythonCall are new to me, but I replicated the r code closely. One thing to note is that the extension file is basically empty right now, because I am not 100% clear on everything that is happening in the r version.

Todos

jkrumbiegel commented 2 months ago

I don't think the @py macro is quite the right tool here, because as far as I understand, it tries to convert python-style code to Julia function calls on a best-effort basis. We'd need direct execution of python code, so that any code is supported. I had a discussion about that with the PythonCall maintainer here https://github.com/JuliaPy/PythonCall.jl/discussions/551

Looks like one needs to analyze if the last statement should be evaled, I would assume that IPython notebook kernels do the same thing. Not every code fragment in Python results in a value, which is different from Julia, and also different from R I think.

tuncbkose commented 2 months ago

Oh oops, it worked well enough for my one-line code examples in different languages but I guess the general case is a lot more complicated instead of just a bit more.

I'll close this PR as this works good enough for me for now.