|
30 | 30 | "#|export\n",
|
31 | 31 | "from __future__ import annotations\n",
|
32 | 32 | "import warnings\n",
|
| 33 | + "import time\n", |
33 | 34 | "\n",
|
34 | 35 | "from nbdev.config import *\n",
|
35 | 36 | "from nbdev.process import *\n",
|
36 | 37 | "from nbdev.processors import *\n",
|
37 | 38 | "from nbdev.doclinks import *\n",
|
38 | 39 | "from nbdev.test import *\n",
|
39 | 40 | "from nbdev.clean import *\n",
|
40 |
| - "from nbdev.quarto import nbdev_readme, refresh_quarto_yml\n", |
| 41 | + "from nbdev.quarto import nbdev_readme, refresh_quarto_yml, fs_watchdog\n", |
41 | 42 | "from nbdev.export import nb_export\n",
|
42 | 43 | "from nbdev.frontmatter import FrontmatterProc\n",
|
43 | 44 | "\n",
|
| 45 | + "from fastcore.xtras import run\n", |
44 | 46 | "from execnb.nbio import *\n",
|
45 | 47 | "from fastcore.meta import *\n",
|
46 | 48 | "from fastcore.utils import *\n",
|
|
304 | 306 | " return nb_export(nbname=nbname, debug=debug, **kwargs)"
|
305 | 307 | ]
|
306 | 308 | },
|
| 309 | + { |
| 310 | + "cell_type": "code", |
| 311 | + "execution_count": null, |
| 312 | + "id": "aaa472e7", |
| 313 | + "metadata": {}, |
| 314 | + "outputs": [], |
| 315 | + "source": [ |
| 316 | + "#|export\n", |
| 317 | + "@call_parse\n", |
| 318 | + "def watch_export(nbs:str=None, # Nb directory to watch for changes\n", |
| 319 | + " lib:str=None, # Export directory to write py files to\n", |
| 320 | + " force:bool=False # Ignore nbdev config if in nbdev project\n", |
| 321 | + " ):\n", |
| 322 | + " '''Use `nb_export` on ipynb files in `nbs` directory on changes using nbdev config if available'''\n", |
| 323 | + " cfg = get_config() if is_nbdev() else None\n", |
| 324 | + " nbs = nbs or (cfg.nbs_path if cfg else '.')\n", |
| 325 | + " lib = lib or (cfg.lib_path if cfg else '.')\n", |
| 326 | + " if cfg and (nbs != cfg.nbs_path or lib != cfg.lib_path) and not force:\n", |
| 327 | + " raise ValueError(\"In nbdev project. Use --force to override config.\")\n", |
| 328 | + " def _export(e,lib=lib):\n", |
| 329 | + " p = e.src_path\n", |
| 330 | + " if (not '.ipynb_checkpoints' in p and p.endswith('.ipynb') and not Path(p).name.startswith('.~')):\n", |
| 331 | + " run(f'nb_export --lib_path {lib} \"{p}\"')\n", |
| 332 | + " with fs_watchdog(_export, nbs):\n", |
| 333 | + " while True: time.sleep(1)" |
| 334 | + ] |
| 335 | + }, |
307 | 336 | {
|
308 | 337 | "cell_type": "code",
|
309 | 338 | "execution_count": null,
|
|
380 | 409 | "\u001b[1m\u001b[94mnbdev_test\u001b[22m\u001b[39m Test in parallel notebooks matching `path`, passing along `flags`\n",
|
381 | 410 | "\u001b[1m\u001b[94mnbdev_trust\u001b[22m\u001b[39m Trust notebooks matching `fname`\n",
|
382 | 411 | "\u001b[1m\u001b[94mnbdev_update\u001b[22m\u001b[39m Propagate change in modules matching `fname` to notebooks that created them\n",
|
383 |
| - "\u001b[1m\u001b[94mnbdev_update_license\u001b[22m\u001b[39m Allows you to update the license of your project.\n" |
| 412 | + "\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" |
384 | 414 | ]
|
385 | 415 | }
|
386 | 416 | ],
|
|
0 commit comments