|
| 1 | +# Using Sphinx to Build Python Package Documentation |
| 2 | + |
| 3 | +<!-- TODO: make this into include files so we can have a summary |
| 4 | +important points page --> |
| 5 | +<!-- |
| 6 | +```{important} |
| 7 | +
|
| 8 | +## Take Aways: Key Python Package Tools to Use |
| 9 | +
|
| 10 | +* Use Sphinx to build your documentation |
| 11 | +* Publish your documentation on ReadTheDocs (or GitHub pages if you are more advanced and also prefer to maintain your website locally) |
| 12 | +* Use `myST` syntax to write your documentation |
| 13 | +* Use sphinx gallery to write tutorials using .py files that automagically have downloadable .py and jupyter notebook files. Use nbsphinx if you prefer writing tutorials in jupyter notebook format and don't need a grid formatted gallery. *Both of these tools will run your tutorials from beginning to end providing an addition layer of testing to your package!* |
| 14 | +* OPTIONAL: Use [doctest](https://www.sphinx-doc.org/en/master/usage/extensions/doctest.html) to run the examples in your code's docstrings as a way to make sure that your code's functions and methods (the API) are running as you expect them to. |
| 15 | +``` --> |
| 16 | + |
| 17 | +On this page we discuss using [Sphinx](https://www.sphinx-doc.org/) to build your user-facing |
| 18 | +package documentation. While Sphinx is currently the most |
| 19 | +commonly-used tool in the scientific Python ecosystem, you |
| 20 | +are welcome to explore other tools to build documentation |
| 21 | +such as [mkdocs](https://www.mkdocs.org/) which is gaining |
| 22 | +popularity in the Python packaging ecosystem. |
| 23 | + |
| 24 | +```{tip} |
| 25 | +Examples of documentation websites that we love: |
| 26 | +
|
| 27 | +* [GeoPandas](https://geopandas.org/en/stable/) |
| 28 | + * [View rst to create landing page](https://raw.githubusercontent.com/geopandas/geopandas/main/doc/source/index.rst) |
| 29 | +* [verde](https://www.fatiando.org/verde/latest/) |
| 30 | + * [View verde landing page code - rst file.](https://github.com/fatiando/verde/blob/main/doc/index.rst) |
| 31 | +* [Here is our documentation if you want to see a myST example of a landing page.](https://github.com/pyOpenSci/python-package-guide/blob/main/index.md) |
| 32 | +``` |
| 33 | + |
| 34 | +## Sphinx - a static site generator |
| 35 | + |
| 36 | +Sphinx is a [static-site generator](https://www.cloudflare.com/learning/performance/static-site-generator/). A static site generator is a tool that creates |
| 37 | +html for a website based upon a set of templates. The html files are then served "Statically" which means that there is no generation or modification of the files on the fly. |
| 38 | + |
| 39 | +Sphinx is written using Python. |
| 40 | + |
| 41 | +### Sphinx sites can be customized using extensions and themes |
| 42 | + |
| 43 | +The functionality of Sphinx can be extended using extensions |
| 44 | +and themes. A few examples include: |
| 45 | + |
| 46 | +* You can apply documentation themes for quick generation of beautiful documentation. |
| 47 | +* You can [automatically create documentation for your package's functions and classes (that package's API) from docstrings in your code using the autodoc extension](https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html) |
| 48 | +* You can [run and test code examples in your docstrings using the doctest extension](https://www.sphinx-doc.org/en/master/usage/extensions/doctest.html) |
| 49 | +* While sphinx natively supports the `rST` syntax. You can add custom syntax parsers to support easier-to-write syntax using tools such as [myst](https://myst-parser.readthedocs.io/). |
| 50 | + |
| 51 | +### Commonly used sphinx themes |
| 52 | + |
| 53 | +You are free to use whatever sphinx theme that you prefer. |
| 54 | +However, the most common sphinx themes used in the Python |
| 55 | +scientific community include: |
| 56 | + |
| 57 | +* [pydata-sphinx-theme](https://pydata-sphinx-theme.readthedocs.io/) |
| 58 | +* [sphinx-book-theme](https://sphinx-book-theme.readthedocs.io/) |
| 59 | +* [furo](https://pradyunsg.me/furo/quickstart/) |
| 60 | + |
| 61 | + |
| 62 | +```{tip} |
| 63 | +This book is created using Sphinx and the `furo` theme. |
| 64 | +``` |
| 65 | +<!-- Should this also be it's own page?--> |
| 66 | + |
| 67 | + |
0 commit comments