Skip to content

Commit aca81c5

Browse files
authored
Merge pull request #11262 from quarto-dev/bugfix/10097
2 parents 9286ded + 19e4532 commit aca81c5

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

news/changelog-1.6.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ All changes included in 1.6:
125125
### `jupyter`
126126

127127
- ([#9134](https://github.com/quarto-dev/quarto-cli/issues/9134)): Add proper fix for `multiprocessing` in notebooks with the Python kernel.
128+
- ([#10097](https://github.com/quarto-dev/quarto-cli/issues/10097)): Ensure papermill parameterization works when default values are set in a cell with labels.
128129

129130
## Chromium support
130131

src/resources/jupyter/notebook.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from pathlib import Path
1414

1515
from yaml import safe_load as parse_string
16+
from yaml import safe_dump
1617

1718
from log import trace
1819
import nbformat
@@ -641,6 +642,20 @@ def nb_parameterize(nb, params):
641642

642643
# prepend options
643644
if len(params_cell_yaml):
645+
# https://github.com/quarto-dev/quarto-cli/issues/10097
646+
# We need to find and drop `label: ` from the yaml options
647+
# to avoid label duplication
648+
# The only way to do this robustly is to parse the yaml
649+
# and then re-encode it
650+
try:
651+
params_cell_yaml = parse_string("\n".join(params_cell_yaml))
652+
del params_cell_yaml['label']
653+
params_cell_yaml = safe_dump(params_cell_yaml).strip().splitlines()
654+
except Exception as e:
655+
sys.stderr.write("\nWARNING: Invalid YAML option format in cell:\n" + "\n".join(params_cell_yaml) + "\n")
656+
sys.stderr.flush()
657+
params_cell_yaml = []
658+
644659
comment_chars = nb_language_comment_chars(language)
645660
option_prefix = comment_chars[0] + "| "
646661
option_suffix = comment_chars[1] if len(comment_chars) > 1 else None
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
format: html
3+
engine: jupyter
4+
keep-ipynb: true
5+
---
6+
7+
```{python}
8+
#| label: test
9+
#| tags: [parameters]
10+
datapath = None
11+
```
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* parameter-label-duplication.test.ts
3+
*
4+
* https://github.com/quarto-dev/quarto-cli/issues/10097
5+
*
6+
* Copyright (C) 2023 Posit Software, PBC
7+
*/
8+
9+
import { quarto } from "../../../src/quarto.ts";
10+
import { test } from "../../test.ts";
11+
import { assertEquals } from "testing/asserts";
12+
import { noErrors } from "../../verify.ts";
13+
14+
test({
15+
name: "jupyter:parameter:label-duplication",
16+
context: {},
17+
execute: async () => {
18+
// https://github.com/quarto-dev/quarto-cli/issues/10097
19+
await quarto(["render",
20+
"docs/jupyter/parameters/issue-10097.qmd",
21+
"--execute-param", 'datapath:"weird"',
22+
"--no-execute-daemon", "--execute"]);
23+
},
24+
verify: [noErrors],
25+
type: "smoke",
26+
});

0 commit comments

Comments
 (0)