Skip to content

Warn when quarto render file.ipynb (with no --execute) finds empty ipynb output cells. #12460

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/changelog-1.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ All changes included in 1.7:

### `jupyter`

- ([#10575](https://github.com/quarto-dev/quarto-cli/issues/10575)): Warn when rendering .ipynb files with `execute: false` and code cells without output.
- ([#12114](https://github.com/quarto-dev/quarto-cli/issues/12114)): `JUPYTERCACHE` environment variable from [Jupyter cache CLI](https://jupyter-cache.readthedocs.io/en/latest/using/cli.html) is now respected by Quarto when `cache: true` is used. This environment variable allows to change the path of the cache directory.
- ([#12374](https://github.com/quarto-dev/quarto-cli/issues/12374)): Detect language properly in Jupyter notebooks that lack the `language` field in their `kernelspec`s.
- ([#12228](https://github.com/quarto-dev/quarto-cli/issues/12228)): `quarto render` will now fails if errors are detected at IPython display level. Setting `error: true` globally or at cell level will keep the error to show in output and not stop the rendering.
Expand Down
7 changes: 7 additions & 0 deletions src/execute/jupyter/jupyter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ import { runExternalPreviewServer } from "../../preview/preview-server.ts";
import { onCleanup } from "../../core/cleanup.ts";
import { projectOutputDir } from "../../project/project-shared.ts";
import { assert } from "testing/asserts";
import { warn } from "log";

export const jupyterEngine: ExecutionEngine = {
name: kJupyterEngine,
Expand Down Expand Up @@ -379,6 +380,12 @@ export const jupyterEngine: ExecutionEngine = {

const nb = jupyterFromJSON(nbContents);

if (!execute && nb.cells.some((cell) => cell.execution_count === null)) {
// warn users that the notebook was not executed
warn(
`${options.target.input} contains unexecuted code cells. Use 'execute: true' to execute the notebook.`,
);
}
// cells tagged 'shinylive' should be emmited as markdown
fixupShinyliveCodeCells(nb);

Expand Down
32 changes: 32 additions & 0 deletions tests/docs/jupyter/issue-10575.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"---\n",
"format: html\n",
"---"
]
},
{
"cell_type": "code",
"metadata": {},
"source": [
"print(\"Hello, world\")"
],
"execution_count": null,
"outputs": []
}
],
"metadata": {
"kernelspec": {
"name": "python3",
"language": "python",
"display_name": "Python 3 (ipykernel)",
"path": "/Users/cscheid/virtualenvs/homebrew-python3/share/jupyter/kernels/python3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
29 changes: 29 additions & 0 deletions tests/smoke/jupyter/issue-10575.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* issue-10575.test.ts
*
* https://github.com/quarto-dev/quarto-cli/issues/10575
*
* Copyright (C) 2023 Posit Software, PBC
*/

import { existsSync } from "../../../src/deno_ral/fs.ts";
import { quarto } from "../../../src/quarto.ts";
import { testQuartoCmd } from "../../test.ts";
import { printsMessage } from "../../verify.ts";

testQuartoCmd("render",
["docs/jupyter/issue-10575.ipynb"],
[
printsMessage({level: "WARN", regex: /contains unexecuted code cells/}),
],
{
teardown: async () => {
if (existsSync("docs/jupyter/issue-10575_files")) {
await Deno.remove("docs/jupyter/issue-10575_files", { recursive: true });
}
if (existsSync("docs/jupyter/issue-10575.html")) {
await Deno.remove("docs/jupyter/issue-10575.html");
}
},
},
);
Loading