quarto-dev / quarto-dev/quarto-cli

QUARTO_FIG_* environment variable are not updated when configuration values changes and kernel is opened.

Open
#11,713 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

I noticed that with figure value as our doc at https://quarto.org/docs/computations/execution-options.html#figure-options says

You can change the default sizes using the fig-width and fig-height options
(...)
For Python, these values are used to set the Matplotlib figure.figsize rcParam (you can of course manually override these defaults for any given plot).
(...)
If you are using another graphics library with Jupyter and want to utilize these values, you can read them from QUARTO_FIG_WIDTH and QUARTO_FIG_HEIGHT environment variables.

The problem seems to be that we do set env var for the kernel
And this is a problem for all values set
https://github.com/quarto-dev/quarto-cli/blob/83a3b5af86d5f43f5f611009b2af8e74e94ffad3/src/resources/jupyter/notebook.py#L106-L114

https://github.com/quarto-dev/quarto-cli/blob/83a3b5af86d5f43f5f611009b2af8e74e94ffad3/src/resources/jupyter/notebook.py#L181-L182

But we probably don't force a restart if the value change.

Run this once with Jupyter kernel not open
quarto render index.qmd --execute-daemon-restart

---
title: 'Fig size'
format: html
---

```{python}
import os
print(f'QUARTO_FIG_WIDTH: {os.environ["QUARTO_FIG_WIDTH"]}')
print(f'QUARTO_FIG_HEIGHT: {os.environ["QUARTO_FIG_HEIGHT"]}')
print(f'QUARTO_FIG_DPI: {os.environ["QUARTO_FIG_DPI"]}')
print(f'QUARTO_FIG_FORMAT: {os.environ["QUARTO_FIG_FORMAT"]}')
```

```{python}
# Get the value of figure.figsize
import matplotlib.pyplot as plt
print(f'Default figure size: {plt.rcParams["figure.figsize"]}')
print(f'Default figure size: {plt.rcParams["figure.dpi"]}')
```

Image

Now modify the YAML header and re-render with the keep-alive kernel

---
title: 'Fig size'
format:
  html: 
    fig-width: 1
    fig-height: 2
    fig-dpi: 450
    fig-format: svg
---

```{python}
import os
print(f'QUARTO_FIG_WIDTH: {os.environ["QUARTO_FIG_WIDTH"]}')
print(f'QUARTO_FIG_HEIGHT: {os.environ["QUARTO_FIG_HEIGHT"]}')
print(f'QUARTO_FIG_DPI: {os.environ["QUARTO_FIG_DPI"]}')
print(f'QUARTO_FIG_FORMAT: {os.environ["QUARTO_FIG_FORMAT"]}')
```

```{python}
# Get the value of figure.figsize
import matplotlib.pyplot as plt
print(f'Default figure size: {plt.rcParams["figure.figsize"]}')
print(f'Default figure size: {plt.rcParams["figure.dpi"]}')
```

Matplot lib config is updated, but not the environment variable
Image

As the environment variable are meant to be used by other graphic package in python not using matplotlib, I think they should be updated if possible, or the configuration change should trigger a restart of the kernel.

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/resources/jupyter/notebook.py at the referenced lines and reproduce the issue using quarto render index.qmd --execute-daemon-restart. Change the figure options in the YAML header while the keep-alive kernel remains open, then compare the QUARTO_FIG_* values with the updated Matplotlib configuration. Done means the environment variables reflect changed configuration values or the kernel is restarted when required.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.