|
116 | 116 | "):\n", |
117 | 117 | " \"Create sidebar.yml\"\n", |
118 | 118 | " if not force and str2bool(config_key('custom_sidebar', path=False)): return\n", |
119 | | - " path = config_key(\"nbs_path\") if not path else Path(path)\n", |
| 119 | + " path = config_key(\"nbs_path\", \".\") if not path else Path(path)\n", |
120 | 120 | " files = nbglob(path, func=_f, symlinks=symlinks, file_re=file_re, folder_re=folder_re, file_glob=file_glob,\n", |
121 | 121 | " skip_file_glob=skip_file_glob, skip_file_re=skip_file_re, skip_folder_re=skip_folder_re).sorted(key=_sort)\n", |
122 | 122 | " lastd,res = Path(),[]\n", |
|
517 | 517 | " except subprocess.CalledProcessError as cpe: sys.exit(cpe.returncode)" |
518 | 518 | ] |
519 | 519 | }, |
| 520 | + { |
| 521 | + "cell_type": "code", |
| 522 | + "execution_count": null, |
| 523 | + "id": "5192dfae", |
| 524 | + "metadata": {}, |
| 525 | + "outputs": [], |
| 526 | + "source": [ |
| 527 | + "#|export\n", |
| 528 | + "def _doc_paths(path:str=None, doc_path:str=None):\n", |
| 529 | + " cfg = get_config()\n", |
| 530 | + " cfg_path = cfg.config_path\n", |
| 531 | + " path = config_key(\"nbs_path\", \".\") if not path else Path(path)\n", |
| 532 | + " doc_path = config_key(\"doc_path\") if not doc_path else Path(doc_path)\n", |
| 533 | + " tmp_doc_path = path/f\"{cfg['doc_path']}\"\n", |
| 534 | + " return cfg,cfg_path,path,doc_path,tmp_doc_path" |
| 535 | + ] |
| 536 | + }, |
| 537 | + { |
| 538 | + "cell_type": "code", |
| 539 | + "execution_count": null, |
| 540 | + "id": "4e995496", |
| 541 | + "metadata": {}, |
| 542 | + "outputs": [], |
| 543 | + "source": [ |
| 544 | + "#|export\n", |
| 545 | + "@call_parse\n", |
| 546 | + "def nbdev_readme(\n", |
| 547 | + " path:str=None, # Path to notebooks\n", |
| 548 | + " doc_path:str=None): # Path to output docs\n", |
| 549 | + " \"Render README.md from index.ipynb\"\n", |
| 550 | + " cfg,cfg_path,path,doc_path,tmp_doc_path = _doc_paths(path, doc_path)\n", |
| 551 | + " idx_path = path/config_key('readme_nb', 'index.ipynb', path=False)\n", |
| 552 | + " if idx_path.exists(): \n", |
| 553 | + " _sprun(f'cd {path} && quarto render {idx_path} -o README.md -t gfm --no-execute')\n", |
| 554 | + " if (tmp_doc_path/'README.md').exists():\n", |
| 555 | + " _rdm = cfg_path/'README.md'\n", |
| 556 | + " if _rdm.exists(): _rdm.unlink() # py37 doesn't have arg missing_ok so have to check first\n", |
| 557 | + " shutil.move(str(tmp_doc_path/'README.md'), cfg_path) # README.md is temporarily in nbs/_docs" |
| 558 | + ] |
| 559 | + }, |
520 | 560 | { |
521 | 561 | "cell_type": "code", |
522 | 562 | "execution_count": null, |
|
537 | 577 | " preview:bool=False # Preview the site instead of building it\n", |
538 | 578 | "):\n", |
539 | 579 | " \"Create Quarto docs and README.md\"\n", |
540 | | - " cfg = get_config()\n", |
541 | | - " cfg_path = cfg.config_path\n", |
| 580 | + " cfg,cfg_path,path,doc_path,tmp_doc_path = _doc_paths(path, doc_path)\n", |
542 | 581 | " refresh_quarto_yml()\n", |
543 | | - " path = config_key(\"nbs_path\") if not path else Path(path)\n", |
544 | | - " idx_path = path/config_key('readme_nb', 'index.ipynb', path=False)\n", |
545 | 582 | " files = nbdev_sidebar.__wrapped__(path, symlinks=symlinks, file_re=file_re, folder_re=folder_re,\n", |
546 | 583 | " skip_file_glob=skip_file_glob, skip_file_re=skip_file_re, returnit=True)\n", |
547 | | - " doc_path = config_key(\"doc_path\") if not doc_path else Path(doc_path)\n", |
548 | | - " tmp_doc_path = config_key('nbs_path')/f\"{cfg['doc_path']}\"\n", |
549 | 584 | " shutil.rmtree(doc_path, ignore_errors=True)\n", |
550 | 585 | " cmd = 'preview' if preview else 'render'\n", |
551 | 586 | " _sprun(f'cd {path} && quarto {cmd} --no-execute')\n", |
552 | 587 | " if not preview:\n", |
553 | | - " if idx_path.exists(): \n", |
554 | | - " _sprun(f'cd {path} && quarto render {idx_path} -o README.md -t gfm --no-execute')\n", |
555 | | - "\n", |
556 | | - " if (tmp_doc_path/'README.md').exists():\n", |
557 | | - " _rdm = cfg_path/'README.md'\n", |
558 | | - " if _rdm.exists(): _rdm.unlink() #py 3.7 doesn't have arg missing_ok so have to check first\n", |
559 | | - " shutil.move(str(tmp_doc_path/'README.md'), cfg_path) # README.md is temporarily in nbs/_docs\n", |
560 | | - "\n", |
| 588 | + " nbdev_readme.__wrapped__(path, doc_path)\n", |
561 | 589 | " if tmp_doc_path.parent != cfg_path: # move docs folder to root of repo if it doesn't exist there\n", |
562 | 590 | " shutil.rmtree(doc_path, ignore_errors=True)\n", |
563 | 591 | " shutil.move(tmp_doc_path, cfg_path)" |
|
0 commit comments