quarto-dev / quarto-dev/quarto-cli

Embed for a Jupyter Percent script

Open
#10,385 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

embed engines-jupyter enhancement
Dominant language
JavaScript
Stars
6k
Forks
458
Avg merge
1d 9h
Merged PRs (30d)
41

Description

Quarto supports now expressing notebook as Jupyter percent script and will render it using usual Jupyter engine pipeline

# %% [markdown]
# ---
# title: Palmer Penguins
# author: Norah Jones
# date: 3/12/23
# ---

# %%
#| echo: false
import pandas as pd
df = pd.read_csv("palmer-penguins.csv")

# %% [markdown]
"""
## Exploring the data

See @fig-bill-sizes for an exploration of bill sizes by species.
"""

# %% 
#| label: fig-bill-sizes
#| fig-cap: Bill Sizes by Species
                                          
import matplotlib.pyplot as plt           
import seaborn as sns

g = sns.FacetGrid(df, hue="species", height=3, aspect=3.5/1.5)
g.map(plt.scatter, "bill_length_mm", "bill_depth_mm").add_legend()

Howerver for now, this is seen as unsupported embed

ERROR: Unable to embed content from script.py - embedding content is not supported for this file type.

Stack trace:
    at unsupportedEmbed (file:///C:/Users/chris/DOCUME~1/DEV_R/QUARTO~2/src/core/jupyter/jupyter-embed.ts:149:11)
    at parseNotebookAddress (file:///C:/Users/chris/DOCUME~1/DEV_R/QUARTO~2/src/core/jupyter/jupyter-embed.ts:115:7)
    at Object.handle (file:///C:/Users/chris/DOCUME~1/DEV_R/QUARTO~2/src/core/handlers/embed.ts:46:31)
    at Object.directive (file:///C:/Users/chris/DOCUME~1/DEV_R/QUARTO~2/src/core/handlers/embed.ts:101:36)
    at handleLanguageCells (file:///C:/Users/chris/DOCUME~1/DEV_R/QUARTO~2/src/core/handlers/base.ts:511:38)
    at eventLoopTick (ext:core/01_core.js:153:7)
    at async file:///C:/Users/chris/DOCUME~1/DEV_R/QUARTO~2/src/command/render/render-files.ts:631:41
    at async withTimingAsync (file:///C:/Users/chris/DOCUME~1/DEV_R/QUARTO~2/src/core/timing.ts:50:20)
    at async renderFileInternal (file:///C:/Users/chris/DOCUME~1/DEV_R/QUARTO~2/src/command/render/render-files.ts:629:9)
    at async renderFiles (file:///C:/Users/chris/DOCUME~1/DEV_R/QUARTO~2/src/command/render/render-files.ts:325:9)

Maybe it would be ok to support this ?

---
title: "test"
format: html
---

{{< embed script.py#fig-bill-sizes >}}     

Following discussion in https://github.com/quarto-dev/quarto-cli/issues/10366#issuecomment-2252163412

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/core/jupyter/jupyter-embed.ts and the embed handling paths in src/core/handlers/embed.ts and src/core/handlers/base.ts, using the reported unsupportedEmbed stack trace as the entry point. Verify the behavior with the issue's script.py#fig-bill-sizes example; done means that embed syntax can resolve a figure from a Jupyter percent script through the usual Jupyter pipeline.

Written by the indexing model from the issue text.

Assessment

Tech stack
jupyter, python
Domain
cli
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.