Skip to content

Commit 0e627b9

Browse files
committed
do not duplicate label when creating new parameter cell
1 parent aa98c3d commit 0e627b9

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

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

0 commit comments

Comments
 (0)