Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

{python} support #255

Merged
merged 2 commits into from
Feb 18, 2025
Merged

{python} support #255

merged 2 commits into from
Feb 18, 2025

Conversation

MichaelHatherly
Copy link
Collaborator

Adds support for evaluating {python} code by running it via PythonCall.jl.

Users must import PythonCall into their notebook for this feature to work. Supports Julia expression interpolation in a similar way to the {r} support that is backed by RCall.

With this we can run notebooks that contain Julia, R, and Python and send values between all three, below we use the iris dataset from R, and pass it to seaborn for plotting. There'll be room to improve the conversion of values between languages, but that can be improved at a later time.

image

Fixes #108. Replaces #185.

@MichaelHatherly MichaelHatherly force-pushed the mh/python branch 2 times, most recently from e67a5fb to cfdf061 Compare February 16, 2025 18:56
Copy link

codecov bot commented Feb 16, 2025

Codecov Report

Attention: Patch coverage is 9.35252% with 126 lines in your changes missing coverage. Please review.

Project coverage is 30.18%. Comparing base (a9fb2e9) to head (2542d54).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...ookWorker/ext/QuartoNotebookWorkerPythonCallExt.jl 0.00% 120 Missing ⚠️
src/QuartoNotebookWorker/src/render.jl 0.00% 4 Missing ⚠️
src/QuartoNotebookWorker/src/python.jl 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #255      +/-   ##
==========================================
- Coverage   31.42%   30.18%   -1.24%     
==========================================
  Files          55       57       +2     
  Lines        2457     2591     +134     
==========================================
+ Hits          772      782      +10     
- Misses       1685     1809     +124     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@MichaelHatherly MichaelHatherly force-pushed the mh/python branch 3 times, most recently from 0e4b43a to 5e1fac2 Compare February 16, 2025 21:09
Adds support for evaluating `{python}` code by running it via `PythonCall.jl`.

Users must import `PythonCall` into their notebook for this feature to work.
Supports Julia expression interpolation in a similar way to the `{r}` support
that is backed by `RCall`.
@MichaelHatherly
Copy link
Collaborator Author

I've yet to work out the "correct" way to output multiple plots from a cell, so that Quarto can then do layout (https://quarto.org/docs/authoring/article-layout.html). But what does actually just work is interpolating the display function from Julia... So you can already do

```{python}
p1 = plot(...)
$(display)(p1)

p2 = plot(...)
$(display)(p2)
```

and that'll hook into Julia's display system and correctly render plots, or tables (or whatever else).

@MichaelHatherly
Copy link
Collaborator Author

@felixcremer @tuncbkose fyi, this is the latest work towards supporting Python cells in this backend. You were both previously interested in this, so feel free to take this branch for a spin if you get the chance.

@MichaelHatherly
Copy link
Collaborator Author

Adjustments to the approach used to parse and compile the source prior to evaluation now means stacktraces from Python errors all point to the correct locations within the notebook. Additionally, support for a help mode, via prefixed ? like in Julia cells, has been added as well.

Screenshot 2025-02-18 at 06 41 06

@MichaelHatherly MichaelHatherly merged commit 6dc2dcb into main Feb 18, 2025
9 of 11 checks passed
@MichaelHatherly MichaelHatherly deleted the mh/python branch February 18, 2025 13:40
@MichaelHatherly MichaelHatherly mentioned this pull request Feb 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support Python cells
1 participant