|
39 | 39 | "from nbdev.config import *\n", |
40 | 40 | "from nbdev.doclinks import *\n", |
41 | 41 | "from nbdev.process import NBProcessor, nb_lang\n", |
42 | | - "from nbdev.frontmatter import FrontmatterProc\n", |
| 42 | + "from nbdev.frontmatter import nb_frontmatter\n", |
43 | 43 | "\n", |
44 | 44 | "from execnb.nbio import *\n", |
45 | 45 | "from execnb.shell import *" |
|
59 | 59 | " do_print=False, # print completion?\n", |
60 | 60 | " showerr=True, # print errors to stderr?\n", |
61 | 61 | " basepath=None, # path to add to sys.path\n", |
62 | | - " verbose=False): # stream stdout/stderr from cells to console?\n", |
| 62 | + " verbose=False, # stream stdout/stderr from cells to console?\n", |
| 63 | + " save=False): # write outputs back to notebook on success?\n", |
63 | 64 | " \"Execute tests in notebook in `fn` except those with `skip_flags`\"\n", |
64 | 65 | " if basepath: sys.path.insert(0, str(basepath))\n", |
65 | 66 | " if not IN_NOTEBOOK: os.environ[\"IN_TEST\"] = '1'\n", |
66 | 67 | " flags=set(L(skip_flags)) - set(L(force_flags))\n", |
67 | | - " nb = NBProcessor(fn, procs=FrontmatterProc, process=True).nb\n", |
68 | | - " fm = getattr(nb, 'frontmatter_', {})\n", |
| 68 | + " nb = NBProcessor(fn, rm_directives=False, process=True).nb\n", |
| 69 | + " fm = nb_frontmatter(nb)\n", |
69 | 70 | " if str2bool(fm.get('skip_exec', False)) or nb_lang(nb) != 'python': return True, 0\n", |
70 | 71 | "\n", |
71 | 72 | " def _no_eval(cell):\n", |
|
81 | 82 | " try:\n", |
82 | 83 | " with working_directory(fn.parent):\n", |
83 | 84 | " k.run_all(nb, exc_stop=True, preproc=_no_eval, verbose=verbose)\n", |
| 85 | + " if save: write_nb(nb, fn)\n", |
84 | 86 | " res = True\n", |
85 | 87 | " except: \n", |
86 | 88 | " if showerr: sys.stderr.write(k.prettytb(fname=fn)+'\\n')\n", |
|
172 | 174 | " pause:float=0.01, # Pause time (in seconds) between notebooks to avoid race conditions\n", |
173 | 175 | " ignore_fname:str='.notest', # Filename that will result in siblings being ignored\n", |
174 | 176 | " verbose:bool=False, # Print stdout/stderr from notebook cells?\n", |
| 177 | + " save:bool=False, # Write outputs back to notebooks on success?\n", |
175 | 178 | " **kwargs):\n", |
176 | 179 | " \"Test in parallel notebooks matching `path`, passing along `flags`\"\n", |
177 | 180 | " skip_flags = get_config().tst_flags\n", |
|
186 | 189 | " wd_pth = get_config().nbs_path\n", |
187 | 190 | " with working_directory(wd_pth if (wd_pth and wd_pth.exists()) else os.getcwd()):\n", |
188 | 191 | " results = parallel(test_nb, files, skip_flags=skip_flags, force_flags=force_flags, n_workers=n_workers,\n", |
189 | | - " basepath=get_config().config_path, pause=pause, do_print=do_print, verbose=verbose, **kw)\n", |
| 192 | + " basepath=get_config().config_path, pause=pause, do_print=do_print, verbose=verbose, save=save, **kw)\n", |
190 | 193 | " passed,times = zip(*results)\n", |
191 | 194 | " if all(passed): print(\"Success.\")\n", |
192 | 195 | " else: \n", |
|
253 | 256 | "#| hide\n", |
254 | 257 | "import nbdev; nbdev.nbdev_export()" |
255 | 258 | ] |
256 | | - }, |
257 | | - { |
258 | | - "cell_type": "code", |
259 | | - "execution_count": null, |
260 | | - "id": "86f62c6e", |
261 | | - "metadata": {}, |
262 | | - "outputs": [], |
263 | | - "source": [] |
264 | 259 | } |
265 | 260 | ], |
266 | 261 | "metadata": {}, |
|
0 commit comments