|
166 | 166 | "source": [ |
167 | 167 | "Jupyter Notebooks can cause challenges with git conflicts, but life becomes much easier when you use `nbdev`. As a first step, run `nbdev_install_hooks` in the terminal from your project folder. This will set up hooks which will remove metadata from your notebooks when you commit, greatly reducing the chance you have a conflict.\n", |
168 | 168 | "\n", |
169 | | - "But if you do get a conflict later, simply run `nbdev_clean filename.ipynb`. This will replace any conflicts in cell outputs with your version, and if there are conflicts in input cells, then both cells will be included in the merged file, along with standard conflict markers (e.g. `=====`). Then you can open the notebook in Jupyter and choose which version to keep." |
| 169 | + "But if you do get a conflict later, simply run `nbdev_fix filename.ipynb`. This will replace any conflicts in cell outputs with your version, and if there are conflicts in input cells, then both cells will be included in the merged file, along with standard conflict markers (e.g. `=====`). Then you can open the notebook in Jupyter and choose which version to keep." |
170 | 170 | ] |
171 | 171 | }, |
172 | 172 | { |
|
350 | 350 | "cell_type": "markdown", |
351 | 351 | "metadata": {}, |
352 | 352 | "source": [ |
353 | | - "## Edit index.ipynb" |
| 353 | + "## Build and install lib" |
354 | 354 | ] |
355 | 355 | }, |
356 | 356 | { |
357 | 357 | "cell_type": "markdown", |
358 | 358 | "metadata": {}, |
359 | 359 | "source": [ |
360 | | - "Now you're ready to create your documentation home page and README.md file; these are both generated automatically from *index.ipynb*. So click on that to open it now.\n", |
| 360 | + "Now you can create your Python module. To do so, just run `nbdev_export` from the terminal at the root of your project folder, which builds the .py modules and library from the jupyter notebook.\n", |
361 | 361 | "\n", |
362 | | - "You'll see that there's already a line there to import your library - change it to use the name you selected in `settings.ini`. Then, add information about how to use your module, including some examples. Remember, these examples should be actual notebook code cells with real outputs." |
| 362 | + "Before you continue, you should ensure you have the latest version of your Python library and Quarto installed. Run `nbdev_install` to do an [editable install](https://stackoverflow.com/questions/35064426/when-would-the-e-editable-option-be-useful-with-pip-install) of your local Python library as well as fetch and install the latest version of Quarto. " |
363 | 363 | ] |
364 | 364 | }, |
365 | 365 | { |
366 | 366 | "cell_type": "markdown", |
367 | 367 | "metadata": {}, |
368 | 368 | "source": [ |
369 | | - "## Build lib + test" |
| 369 | + "## Edit index.ipynb" |
370 | 370 | ] |
371 | 371 | }, |
372 | 372 | { |
373 | 373 | "cell_type": "markdown", |
374 | 374 | "metadata": {}, |
375 | 375 | "source": [ |
376 | | - "Now you can create your Python module. To do so, just run `nbdev_prepare` from the terminal at the root of your project folder. `nbdev_prepare` bundles the following commands together for you to test your code and build the library. While running `nbdev_prepare` is convenient, you have the flexibility to choose these separate pieces.\n", |
377 | | - "\n", |
378 | | - "- `nbdev_export`: Builds the .py modules and library from the jupyter notebook\n", |
379 | | - "- `nbdev_test`: Tests all your notebooks\n", |
380 | | - "- `nbdev_clean`: Cleans your notebooks to get rid of extreanous output for Github\n", |
381 | | - "\n", |
| 376 | + "Now you're ready to create your documentation home page and README.md file; these are both generated automatically from *index.ipynb*. So click on that to open it now.\n", |
382 | 377 | "\n", |
383 | | - "Sometimes you may want to ensure you have the latest version of your Python library and Quarto installed. You can run `nbdev_install` to do an editable install of your local Python library as well as fetch and install the latest version of Quarto. " |
| 378 | + "You'll see that there's already a line there to import your library - change it to use the name you selected in `settings.ini`. Then, add information about how to use your module, including some examples. Remember, these examples should be actual notebook code cells with real outputs." |
384 | 379 | ] |
385 | 380 | }, |
386 | 381 | { |
|
399 | 394 | "## Commit to Github" |
400 | 395 | ] |
401 | 396 | }, |
| 397 | + { |
| 398 | + "cell_type": "markdown", |
| 399 | + "metadata": {}, |
| 400 | + "source": [ |
| 401 | + "Before commiting to GitHub we recommend running `nbdev_prepare`, which bundles the following commands together for you to test your code and build the library:\n", |
| 402 | + "\n", |
| 403 | + "- `nbdev_export`: Builds the .py modules and library from the jupyter notebook\n", |
| 404 | + "- `nbdev_test`: Tests all your notebooks\n", |
| 405 | + "- `nbdev_clean`: Cleans your notebooks to get rid of extreanous output for Github" |
| 406 | + ] |
| 407 | + }, |
402 | 408 | { |
403 | 409 | "cell_type": "markdown", |
404 | 410 | "metadata": {}, |
|
432 | 438 | "\n", |
433 | 439 | "#### Automatically building Docs\n", |
434 | 440 | "\n", |
435 | | - "CI will automatically build docs and deploy them for you. You can see the code for this in `.github/workflows/deploy.yaml`, but you normally don't have to worry about this unless you need to customize something. There might be certain circumstances in which your organization has disabled GitHub pages by default. If this is the case, you can enable Github Pages by clicking on the *Settings* tab in your repo, then click *Pages* on the left side bar. Set \"Source\" to *`gh-pages` branch and the `/root` folder*. Once you've saved, if you refresh that page, Github will have a link to your new website. Copy that URL, and then go back to your main repo page, click \"edit\" next to the description and paste the URL into the \"website\" section. While you're there, go ahead and put in your project description too. \n", |
| 441 | + "CI will automatically build docs and deploy them for you. You can see the code for this in `.github/workflows/deploy.yaml`. You can enable Github Pages by clicking on the *Settings* tab in your repo, then click *Pages* on the left side bar. Set \"Source\" to *`gh-pages` branch and the `/root` folder*. Once you've saved, if you refresh that page, Github will have a link to your new website. Copy that URL, and then go back to your main repo page, click \"edit\" next to the description and paste the URL into the \"website\" section. While you're there, go ahead and put in your project description too. \n", |
436 | 442 | "\n", |
437 | 443 | "#### Docs URL\n", |
438 | 444 | "\n", |
|
623 | 629 | "cell_type": "markdown", |
624 | 630 | "metadata": {}, |
625 | 631 | "source": [ |
626 | | - "It's helpful to be able to export all your modules directly from a notebook, rather than going to the terminal to do it. All nbdev commands are available directly from a notebook in Python. Add this line to any cell and run it to export your modules (I normally make this the last cell of my notebooks).\n", |
| 632 | + "It's helpful to be able to export all your modules directly from a notebook, rather than going to the terminal to do it. All nbdev commands are available directly from a notebook in Python. A new cell with the following contents and run it to export your modules (I normally make this the last cell of my notebooks).\n", |
627 | 633 | "\n", |
628 | 634 | "```python\n", |
629 | | - "from nbdev.doclinks import nbdev_export\n", |
| 635 | + "#| hide\n", |
| 636 | + "from nbdev import nbdev_export\n", |
630 | 637 | "nbdev_export()\n", |
631 | 638 | "```" |
632 | 639 | ] |
|
635 | 642 | "cell_type": "markdown", |
636 | 643 | "metadata": {}, |
637 | 644 | "source": [ |
638 | | - "## Run tests in parallel" |
639 | | - ] |
640 | | - }, |
641 | | - { |
642 | | - "cell_type": "markdown", |
643 | | - "metadata": {}, |
644 | | - "source": [ |
645 | | - "Before you push to github or make a release, you might want to run all your tests. nbdev can run all your notebooks in parallel to check for errors. Just run `nbdev_test` in a terminal.\n", |
646 | | - "\n", |
647 | 645 | "## Code Execution & Skipping Cells\n", |
648 | 646 | "\n", |
649 | 647 | "If you want to prevent code from getting executed when rendering or testing docs, use the comment `|#eval: false` in a code cell. \n", |
650 | 648 | "\n", |
651 | 649 | "See the [Quarto docs](https://quarto.org/docs/computations/execution-options.html) for more execution options." |
652 | 650 | ] |
653 | 651 | }, |
654 | | - { |
655 | | - "cell_type": "markdown", |
656 | | - "metadata": {}, |
657 | | - "source": [ |
658 | | - "## View docs locally" |
659 | | - ] |
660 | | - }, |
661 | | - { |
662 | | - "cell_type": "markdown", |
663 | | - "metadata": {}, |
664 | | - "source": [ |
665 | | - "If you want to look at your docs locally before you push to Github, you can do so by running `nbdev_preview`." |
666 | | - ] |
667 | | - }, |
668 | 652 | { |
669 | 653 | "cell_type": "markdown", |
670 | 654 | "metadata": {}, |
|
711 | 695 | "```" |
712 | 696 | ] |
713 | 697 | }, |
714 | | - { |
715 | | - "cell_type": "markdown", |
716 | | - "metadata": {}, |
717 | | - "source": [ |
718 | | - "## Test with editable install" |
719 | | - ] |
720 | | - }, |
721 | | - { |
722 | | - "cell_type": "markdown", |
723 | | - "metadata": {}, |
724 | | - "source": [ |
725 | | - "To test and use your modules in other projects, and use your console scripts (if you have any), the easiest approach is to use an [editable install](http://codumentary.blogspot.com/2014/11/python-tip-of-year-pip-install-editable.html). To do this, `cd` to the root of your repo in the terminal, and type:\n", |
726 | | - "```\n", |
727 | | - "pip install -e .\n", |
728 | | - "```\n", |
729 | | - "(Note that the trailing period is important.) Your module changes will be automatically picked up without reinstalling. If you add any additional console scripts, you will need to run this command again. After doing an editable install you can run `nbdev_test` to run all of the tests in your notebooks." |
730 | | - ] |
731 | | - }, |
732 | 698 | { |
733 | 699 | "cell_type": "markdown", |
734 | 700 | "metadata": {}, |
|
0 commit comments