Skip to content

Commit cd10e11

Browse files
committed
properly escape json and yaml on nbdev_new
1 parent d336eeb commit cd10e11

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

nbdev/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
from urllib.error import HTTPError
2929
from contextlib import redirect_stdout
30-
import os, tarfile, sys
30+
import os, tarfile, sys, json
3131

3232
# %% auto 0
3333
__all__ = ['mapping', 'nbdev_filter', 'extract_tgz', 'nbdev_new', 'nbdev_update_license', 'nb_export_cli', 'watch_export',
@@ -66,7 +66,7 @@ def _render_nb(fn, cfg):
6666
"Render templated values like `{{lib_name}}` in notebook at `fn` from `cfg`"
6767
txt = fn.read_text()
6868
txt = txt.replace('from your_lib.core', f'from {cfg.lib_path}.core') # for compatibility with old templates
69-
for k,v in cfg.d.items(): txt = txt.replace('{{'+k+'}}', v)
69+
for k,v in cfg.d.items(): txt = txt.replace('{{'+k+'}}', json.dumps(v)[1:-1])
7070
fn.write_text(txt)
7171

7272
# %% ../nbs/api/13_cli.ipynb

nbdev/quarto.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from fastcore.meta import delegates
1818
from .serve import proc_nbs,_proc_file
1919
from . import serve_drv
20-
import yaml
20+
import yaml, json
2121

2222
# %% auto 0
2323
__all__ = ['BASE_QUARTO_URL', 'install_quarto', 'install', 'IndentDumper', 'nbdev_sidebar', 'refresh_quarto_yml',
@@ -179,7 +179,7 @@ def refresh_quarto_yml():
179179
"Generate `_quarto.yml` from `settings.ini`."
180180
cfg = get_config()
181181
ny = cfg.nbs_path/'nbdev.yml'
182-
vals = {k:cfg[k] for k in ['title', 'description', 'branch', 'git_url', 'doc_host', 'doc_baseurl']}
182+
vals = {k:json.dumps(cfg[k])[1:-1] for k in ['title', 'description', 'branch', 'git_url', 'doc_host', 'doc_baseurl']}
183183
vals['doc_path'] = cfg.doc_path.name
184184
if 'title' not in vals: vals['title'] = vals['lib_name']
185185
ny.write_text(_nbdev_yml.format(**vals))

nbs/api/13_cli.ipynb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"\n",
5353
"from urllib.error import HTTPError\n",
5454
"from contextlib import redirect_stdout\n",
55-
"import os, tarfile, sys"
55+
"import os, tarfile, sys, json"
5656
]
5757
},
5858
{
@@ -152,7 +152,7 @@
152152
" \"Render templated values like `{{lib_name}}` in notebook at `fn` from `cfg`\"\n",
153153
" txt = fn.read_text()\n",
154154
" txt = txt.replace('from your_lib.core', f'from {cfg.lib_path}.core') # for compatibility with old templates\n",
155-
" for k,v in cfg.d.items(): txt = txt.replace('{{'+k+'}}', v)\n",
155+
" for k,v in cfg.d.items(): txt = txt.replace('{{'+k+'}}', json.dumps(v)[1:-1])\n",
156156
" fn.write_text(txt)"
157157
]
158158
},
@@ -372,7 +372,7 @@
372372
{
373373
"cell_type": "code",
374374
"execution_count": null,
375-
"id": "b50d27fb-c343-47e2-a008-7ebdd02e1356",
375+
"id": "7b05d8d8-3323-4fa1-bf1c-04ec3d5dfae1",
376376
"metadata": {},
377377
"outputs": [
378378
{
@@ -410,7 +410,7 @@
410410
"\u001b[1m\u001b[94mnbdev_trust\u001b[22m\u001b[39m Trust notebooks matching `fname`\n",
411411
"\u001b[1m\u001b[94mnbdev_update\u001b[22m\u001b[39m Propagate change in modules matching `fname` to notebooks that created them\n",
412412
"\u001b[1m\u001b[94mnbdev_update_license\u001b[22m\u001b[39m Allows you to update the license of your project.\n",
413-
"\u001b[1m\u001b[94mwatch_export\u001b[22m\u001b[39m None\n"
413+
"\u001b[1m\u001b[94mwatch_export\u001b[22m\u001b[39m Use `nb_export` on ipynb files in `nbs` directory on changes using nbdev config if available\n"
414414
]
415415
}
416416
],

nbs/api/14_quarto.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"from fastcore.meta import delegates\n",
5252
"from nbdev.serve import proc_nbs,_proc_file\n",
5353
"from nbdev import serve_drv\n",
54-
"import yaml"
54+
"import yaml, json"
5555
]
5656
},
5757
{
@@ -326,7 +326,7 @@
326326
" \"Generate `_quarto.yml` from `settings.ini`.\"\n",
327327
" cfg = get_config()\n",
328328
" ny = cfg.nbs_path/'nbdev.yml'\n",
329-
" vals = {k:cfg[k] for k in ['title', 'description', 'branch', 'git_url', 'doc_host', 'doc_baseurl']}\n",
329+
" vals = {k:json.dumps(cfg[k])[1:-1] for k in ['title', 'description', 'branch', 'git_url', 'doc_host', 'doc_baseurl']}\n",
330330
" vals['doc_path'] = cfg.doc_path.name\n",
331331
" if 'title' not in vals: vals['title'] = vals['lib_name']\n",
332332
" ny.write_text(_nbdev_yml.format(**vals))\n",

0 commit comments

Comments
 (0)