Skip to content

properly escape json and yaml on nbdev_new #1494

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 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions nbdev/cli.py
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@

from urllib.error import HTTPError
from contextlib import redirect_stdout
import os, tarfile, sys
import os, tarfile, sys, json

# %% auto 0
__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):
"Render templated values like `{{lib_name}}` in notebook at `fn` from `cfg`"
txt = fn.read_text()
txt = txt.replace('from your_lib.core', f'from {cfg.lib_path}.core') # for compatibility with old templates
for k,v in cfg.d.items(): txt = txt.replace('{{'+k+'}}', v)
for k,v in cfg.d.items(): txt = txt.replace('{{'+k+'}}', json.dumps(v)[1:-1])
fn.write_text(txt)

# %% ../nbs/api/13_cli.ipynb
4 changes: 2 additions & 2 deletions nbdev/quarto.py
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@
from fastcore.meta import delegates
from .serve import proc_nbs,_proc_file
from . import serve_drv
import yaml
import yaml, json

# %% auto 0
__all__ = ['BASE_QUARTO_URL', 'install_quarto', 'install', 'IndentDumper', 'nbdev_sidebar', 'refresh_quarto_yml',
@@ -179,7 +179,7 @@ def refresh_quarto_yml():
"Generate `_quarto.yml` from `settings.ini`."
cfg = get_config()
ny = cfg.nbs_path/'nbdev.yml'
vals = {k:cfg[k] for k in ['title', 'description', 'branch', 'git_url', 'doc_host', 'doc_baseurl']}
vals = {k:json.dumps(cfg[k])[1:-1] for k in ['title', 'description', 'branch', 'git_url', 'doc_host', 'doc_baseurl']}
vals['doc_path'] = cfg.doc_path.name
if 'title' not in vals: vals['title'] = vals['lib_name']
ny.write_text(_nbdev_yml.format(**vals))
8 changes: 4 additions & 4 deletions nbs/api/13_cli.ipynb
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@
"\n",
"from urllib.error import HTTPError\n",
"from contextlib import redirect_stdout\n",
"import os, tarfile, sys"
"import os, tarfile, sys, json"
]
},
{
@@ -152,7 +152,7 @@
" \"Render templated values like `{{lib_name}}` in notebook at `fn` from `cfg`\"\n",
" txt = fn.read_text()\n",
" txt = txt.replace('from your_lib.core', f'from {cfg.lib_path}.core') # for compatibility with old templates\n",
" for k,v in cfg.d.items(): txt = txt.replace('{{'+k+'}}', v)\n",
" for k,v in cfg.d.items(): txt = txt.replace('{{'+k+'}}', json.dumps(v)[1:-1])\n",
" fn.write_text(txt)"
]
},
@@ -372,7 +372,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "b50d27fb-c343-47e2-a008-7ebdd02e1356",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure why nbdev_clean didn't pick this one up

"id": "7b05d8d8-3323-4fa1-bf1c-04ec3d5dfae1",
"metadata": {},
"outputs": [
{
@@ -410,7 +410,7 @@
"\u001b[1m\u001b[94mnbdev_trust\u001b[22m\u001b[39m Trust notebooks matching `fname`\n",
"\u001b[1m\u001b[94mnbdev_update\u001b[22m\u001b[39m Propagate change in modules matching `fname` to notebooks that created them\n",
"\u001b[1m\u001b[94mnbdev_update_license\u001b[22m\u001b[39m Allows you to update the license of your project.\n",
"\u001b[1m\u001b[94mwatch_export\u001b[22m\u001b[39m None\n"
"\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"
]
}
],
4 changes: 2 additions & 2 deletions nbs/api/14_quarto.ipynb
Original file line number Diff line number Diff line change
@@ -51,7 +51,7 @@
"from fastcore.meta import delegates\n",
"from nbdev.serve import proc_nbs,_proc_file\n",
"from nbdev import serve_drv\n",
"import yaml"
"import yaml, json"
]
},
{
@@ -326,7 +326,7 @@
" \"Generate `_quarto.yml` from `settings.ini`.\"\n",
" cfg = get_config()\n",
" ny = cfg.nbs_path/'nbdev.yml'\n",
" vals = {k:cfg[k] for k in ['title', 'description', 'branch', 'git_url', 'doc_host', 'doc_baseurl']}\n",
" vals = {k:json.dumps(cfg[k])[1:-1] for k in ['title', 'description', 'branch', 'git_url', 'doc_host', 'doc_baseurl']}\n",
" vals['doc_path'] = cfg.doc_path.name\n",
" if 'title' not in vals: vals['title'] = vals['lib_name']\n",
" ny.write_text(_nbdev_yml.format(**vals))\n",