|
404 | 404 | "outputs": [], |
405 | 405 | "source": [ |
406 | 406 | "#|export\n", |
407 | | - "def _readme_mtime_not_older(readme_path, readme_nb_path):\n", |
| 407 | + "def _doc_mtime_not_older(readme_path, readme_nb_path):\n", |
408 | 408 | " if not readme_nb_path.exists():\n", |
409 | 409 | " print(f\"Could not find {readme_nb_path}\")\n", |
410 | 410 | " return True\n", |
|
482 | 482 | " \"Create README.md from readme_nb (index.ipynb by default)\"\n", |
483 | 483 | " cfg = get_config()\n", |
484 | 484 | " path = Path(path) if path else cfg.nbs_path\n", |
485 | | - " if chk_time and _readme_mtime_not_older(cfg.config_path/'README.md', path/cfg.readme_nb): return\n", |
| 485 | + " if chk_time and _doc_mtime_not_older(cfg.config_path/'README.md', path/cfg.readme_nb): return\n", |
486 | 486 | "\n", |
487 | 487 | " with _SidebarYmlRemoved(path): # to avoid rendering whole website\n", |
488 | 488 | " cache = proc_nbs(path)\n", |
|
510 | 510 | "# nbdev_readme.__wrapped__(chk_time=False)" |
511 | 511 | ] |
512 | 512 | }, |
| 513 | + { |
| 514 | + "cell_type": "code", |
| 515 | + "execution_count": null, |
| 516 | + "id": "ef3f1e1f", |
| 517 | + "metadata": {}, |
| 518 | + "outputs": [], |
| 519 | + "source": [ |
| 520 | + "#|export\n", |
| 521 | + "def _save_cached_contributing(cache, cfg, contrib_nb):\n", |
| 522 | + " \"Move CONTRIBUTING.md (and any `_files` assets) from the Quarto build cache to the repo root.\"\n", |
| 523 | + " tmp_doc_path = cache / cfg.doc_path.name\n", |
| 524 | + " contrib_file = tmp_doc_path / 'CONTRIBUTING.md'\n", |
| 525 | + " if contrib_file.exists():\n", |
| 526 | + " final_path = cfg.config_path / 'CONTRIBUTING.md'\n", |
| 527 | + " if final_path.exists(): final_path.unlink() # Py3.7 doesn't have missing_ok\n", |
| 528 | + " move(contrib_file, final_path)\n", |
| 529 | + " # Move any supporting files folder\n", |
| 530 | + " assets_folder = tmp_doc_path / (Path(contrib_nb).stem + '_files')\n", |
| 531 | + " if assets_folder.exists():\n", |
| 532 | + " _copytree(assets_folder, cfg.config_path / assets_folder.name)" |
| 533 | + ] |
| 534 | + }, |
| 535 | + { |
| 536 | + "cell_type": "code", |
| 537 | + "execution_count": null, |
| 538 | + "id": "729a0fa1", |
| 539 | + "metadata": {}, |
| 540 | + "outputs": [], |
| 541 | + "source": [ |
| 542 | + "#|export\n", |
| 543 | + "@call_parse\n", |
| 544 | + "def nbdev_contributing(\n", |
| 545 | + " path:str=None, # Path to notebooks (defaults to nbs_path)\n", |
| 546 | + " chk_time:bool=False # Only build if out-of-date\n", |
| 547 | + "):\n", |
| 548 | + " \"\"\"\n", |
| 549 | + " Create CONTRIBUTING.md from contributing_nb (defaults to 'contributing.ipynb' if present).\n", |
| 550 | + " Skips if the file doesn't exist.\n", |
| 551 | + " \"\"\"\n", |
| 552 | + " cfg = get_config()\n", |
| 553 | + " path = Path(path) if path else cfg.nbs_path\n", |
| 554 | + " \n", |
| 555 | + " # Decide which notebook is your \"contributing\" NB (you can hardcode or add to settings.ini)\n", |
| 556 | + " contrib_nb_name = cfg.get('contributing_nb', 'contributing.ipynb')\n", |
| 557 | + " contrib_nb_path = path / contrib_nb_name\n", |
| 558 | + " \n", |
| 559 | + " contrib_md = cfg.config_path / 'CONTRIBUTING.md'\n", |
| 560 | + " \n", |
| 561 | + " # If out of date check is requested, skip if up-to-date or missing\n", |
| 562 | + " if chk_time and _doc_mtime_not_older(contrib_md, contrib_nb_path):\n", |
| 563 | + " return\n", |
| 564 | + " \n", |
| 565 | + " # If there's no contributing notebook, do nothing\n", |
| 566 | + " if not contrib_nb_path.exists():\n", |
| 567 | + " return\n", |
| 568 | + " \n", |
| 569 | + " # Temporarily remove sidebar.yml so Quarto doesn't try to build the entire site\n", |
| 570 | + " with _SidebarYmlRemoved(path):\n", |
| 571 | + " cache = proc_nbs(path)\n", |
| 572 | + " \n", |
| 573 | + " # Render a single .ipynb -> .md in GFM\n", |
| 574 | + " _sprun(f'cd \"{cache}\" && quarto render \"{cache/contrib_nb_name}\" -o CONTRIBUTING.md -t gfm --no-execute')\n", |
| 575 | + " \n", |
| 576 | + " # Copy the newly created CONTRIBUTING.md and _files folder back to the repo root\n", |
| 577 | + " _save_cached_contributing(cache, cfg, contrib_nb_name)\n" |
| 578 | + ] |
| 579 | + }, |
513 | 580 | { |
514 | 581 | "cell_type": "code", |
515 | 582 | "execution_count": null, |
|
527 | 594 | " \"Create Quarto docs and README.md\"\n", |
528 | 595 | " cache,cfg,path = _pre_docs(path, n_workers=n_workers, **kwargs)\n", |
529 | 596 | " nbdev_readme.__wrapped__(path=path, chk_time=True)\n", |
| 597 | + " nbdev_contributing.__wrapped__(path=path, chk_time=True)\n", |
530 | 598 | " _sprun(f'cd \"{cache}\" && quarto render --no-cache')\n", |
531 | 599 | " shutil.rmtree(cfg.doc_path, ignore_errors=True)\n", |
532 | 600 | " move(cache/cfg.doc_path.name, cfg.config_path)" |
|
559 | 627 | " nbdev.test.nbdev_test.__wrapped__()\n", |
560 | 628 | " nbdev.clean.nbdev_clean.__wrapped__()\n", |
561 | 629 | " refresh_quarto_yml()\n", |
562 | | - " nbdev_readme.__wrapped__(chk_time=True)" |
| 630 | + " nbdev_readme.__wrapped__(chk_time=True)\n", |
| 631 | + " nbdev_contributing.__wrapped__(chk_time=True)" |
563 | 632 | ] |
564 | 633 | }, |
565 | 634 | { |
|
0 commit comments