Skip to content

Commit 0ad92eb

Browse files
committed
Fix: breakout docs into separate pages with separate goals and update left bar links
1 parent 1d032de commit 0ad92eb

6 files changed

+202
-49
lines changed

documentation/package-documentation-best-practices.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ have 4 elements on the home page of their documentation:
3131
* **Community:** Instructions for how to help and/or get involved. This section might include a development guide.
3232
* **Documentation:** The actual project documentation. You may have two sections of documentation - the user facing documentation and your API reference.
3333

34+
35+
```{figure} ../images/geopandas-documentation-landing-page.png
36+
---
37+
name: directive-fig
38+
width: 80%
39+
alt: Image showing the landing page for GeoPandas documentation which has 4 sections including Getting started, Documentation, About GeoPandas, Community.
40+
---
41+
The documentation landing page of GeoPandas, a spatial Python library, has the 4 element specified above. Notice that the landing page is simple and directs users to each element using a Sphinx card.
42+
```
43+
3444
NOTE: in many cases you can include your **README** file and your **CONTRIBUTING** files
3545
in your documentation given those files may have some of the components listed above.
3646

@@ -43,11 +53,6 @@ Below is an example of doing this using `myst` syntax.
4353
````
4454
`````
4555

46-
## Documentation tutorials
47-
48-
* sphinx gallery vs ()
49-
* best practices...
50-
5156
## API's and Docstrings
5257

5358
### What is an API?

documentation/python-package-documentation-tools.md

Lines changed: 140 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,33 @@
11
# Python Package Documentation
22

3-
In addition to your README, CONTRIBUTING and DEVELOPMENT guides,
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.
14+
15+
```
16+
17+
In addition to your:
18+
* [README.md file](readme-file-best-practices.md),
19+
* [CONTRIBUTING.md and development guides and LICENSE file](contributing-file.md),
20+
421
you should also have user-facing documentation for your Python
5-
package. Below we you will learn about the most common tools that
6-
are used to build Python packaging documentation.
22+
package. Most often, user-facing documentation is contained on a hosted
23+
website.
24+
25+
Below you will learn about the most common tools that
26+
are used to build scientific Python packaging documentation. You will also
27+
learn about hosting options for your documentation.
28+
29+
Here, we focus on tools and infrastructure that you can use.
30+
[Click here if you want to learn more about documentation best practices](package-documentation-best-practices.md).
731

832
```{note}
933
Examples of documentation that we love:
@@ -16,31 +40,38 @@ Examples of documentation that we love:
1640
```
1741

1842

19-
## What tools to use to build your documentation: sphinx
43+
## Sphinx, the most common tool used in the scientific Python ecosystem
2044

21-
Most python packages use [sphinx](https://www.sphinx-doc.org/) to build their documentation.
45+
Most scientific Python packages use [sphinx](https://www.sphinx-doc.org/) to
46+
build their documentation. As such, we will focus on sphinx in this guide.
2247

23-
```{tip}
24-
Sphinx is a static-site generator. A static site generator is a tool that creates
48+
Sphinx is a [static-site generator](https://www.cloudflare.com/learning/performance/static-site-generator/). A static site generator is a tool that creates
2549
html for a website based upon a set of templates. Sphinx is written
2650
using Python tool which
2751
is why it's commonly used in the Python ecosystem.
2852

29-
There are however other tools that could be used such as [mkdocs](https://www.mkdocs.org/). We won't
30-
got into others tools in this guide given sphinx is currently the most
31-
popular in the scientific Python ecosystem. However, you are welcome to use whatever documentation tool that you prefer for your Python package development!
53+
```{tip}
54+
There are other static site generator tools that could be used to create user-facing documentation including
55+
[mkdocs](https://www.mkdocs.org/). We won't
56+
discuss others tools in this guide given sphinx is currently the most
57+
popular in the scientific Python ecosystem.
58+
59+
You are welcome to use whatever documentation tool that you prefer for your Python package development!
3260
```
3361

34-
Sphinx can be extended with various elements including themes and directives (extensions) as follows:
62+
### Sphinx sites can be optimized for documentation with extensions and themes
63+
64+
The functionality of sphinx can be extended using extensions and themes. A few
65+
examples include:
3566

3667
* You can apply documentation themes for quick generation of beautiful documentation.
37-
* You can [automatically create documentation for your package's functions and classes (API) from docstrings in your code using the autodoc extension](https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html)
38-
* You can [run and testing code examples in your docstrings using doctest](https://www.sphinx-doc.org/en/master/usage/extensions/doctest.html)
39-
* While sphinx natively supports the rst syntax. You can add custom syntax parsers to support easier to write syntax such as [myst](https://myst-parser.readthedocs.io/) .
68+
* 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)
69+
* 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)
70+
* 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/).
4071

41-
While you are free to use whatever sphinx theme you prefer,
42-
the most common modern templates that recommend for the Python scientific
43-
community are:
72+
You are free to use whatever sphinx theme that you prefer. However, the most
73+
common sphinx themes that we recommend for the Python scientific
74+
community include:
4475

4576
* [pydata-sphinx-theme](https://pydata-sphinx-theme.readthedocs.io/)
4677
* [sphinx-book-theme](https://sphinx-book-theme.readthedocs.io/)
@@ -57,46 +88,113 @@ There are three commonly used syntaxes for creating Python documentation:
5788
1. [markdown](https://www.markdownguide.org/): Markdown is an easy-to-learn text
5889
syntax. It is the default syntax use in Jupyter Notebooks. There are tools that you can add to a sphinx website that allow it to render markdown as html. However, using markdown to write documentation has limitations. For instance if you want to add references,
5990
colored call out blocks and other custom elements to your documentation, you will
60-
need to use either myST or rST.
61-
1. [rST (ReStructured Text):](https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html). rST is the native syntax that sphinx supports. rST was the default syntax used for documentation for many years given the limitations associated with markdown. However, in recent years myST has risen to the top as a favorite for documentation given the flexibility that it allows.
62-
1. [myST:](https://myst-parser.readthedocs.io/en/latest/intro.html) myST is a combination of vanilla of `markdown` and `rST` syntax. It is a nice option if you are more comfortable writing markdown. `myst` is preferred by many because it offers both the rich functionality
91+
need to use either **myST** or **rST**.
92+
1. [rST (ReStructured Text):](https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html). **rST** is the native syntax that sphinx supports. rST was the default syntax used for documentation for many years given the limitations of markdown. However, in recent years myST has risen to the top as a favorite for documentation given the flexibility that it allows.
93+
1. [myST:](https://myst-parser.readthedocs.io/en/latest/intro.html) myST is a combination of vanilla of `markdown` and `rST` syntax. It is a nice option if you are comfortable writing markdown. `myst` is preferred by many because it offers both the rich functionality
6394
of rST combined with a simple-to-write markdown syntax.
6495

65-
While you can chose to use any of the syntaxes listed above, `myST` is a
66-
preferred syntax to because:
96+
While you can chose to use any of the syntaxes listed above, we suggest using
97+
`myST` because:
6798

6899
* It is a simpler syntax and thus easier to learn;
100+
* The above simplicity will make it easier for more people to contribute to your documentation.
69101
* Most of your core python package text files, such as your README.md file, are already in `.md` format
70-
* `GitHub` and `Jupyter Notebooks` support this default syntax/file format.
102+
* `GitHub` and `Jupyter Notebooks` support markdown thus it's more widely used in the scientific ecosystem.
71103

72-
There is no wrong or right when choosing a syntax to write your documentation.
73-
Choose whichever syntax works best for you and your community!
74104

75105
```{tip}
76-
If you are on the fence about myST vs rst, you might find that *myST* is easier
106+
If you are on the fence about myST vs rst, you might find that **myST** is easier
77107
for more people to contribute to.
78108
```
79109

80-
## How to host your Python package documentation
110+
## Sphinx extensions to support python package tutorials
111+
112+
Adding well constructed tutorials to your package will make it easier for someone
113+
new to begin using your package.
114+
115+
There are two sphinx tools that make it easy to add tutorials to your package:
116+
117+
* [Sphinx Gallery](https://sphinx-gallery.github.io/stable/index.html) and
118+
* [NbSphinx](https://nbsphinx.readthedocs.io/en/latest/)
119+
120+
Both of these tools act as sphinx extensions and:
121+
122+
* Support creating a gallery type page in your sphinx documentation where users can explore tutorials via thumbnails.
123+
* Run the code in your tutorials adding another level of "testing" for your package as used.
124+
* Render your tutorials with Python code and plot outputs
81125

82-
We suggest that you setup a website to host your documentation. There are two
83-
ways to do quickly create a documentation website:
126+
### [sphinx gallery:](https://sphinx-gallery.github.io/stable/index.html)
84127

85-
1. You can host your documentation yourself using [GitHub Pages](https://pages.github.com/) or another online hosting service.
86-
2. You can host your documentation using [Read the Docs](https://readthedocs.org/).
128+
If you prefer to write your tutorials using python **.py** scripts, you
129+
may enjoy using sphinx gallery. Sphinx gallery uses **.py** files with
130+
text and code sections that mimics the Jupyter Notebook format. When you build
131+
your documentation, the gallery extension:
87132

88-
If you don't want to maintain a documentation website for your Python package,
89-
we suggest using the Read the Docs website. Read the Docs allows you to:
133+
1. Runs the code in each tutorial: this acts as a check to ensure your package is working as you think it is!
134+
1. Creates a downloadable Jupyter Notebook **.ipynb** file and a **.py** script for your tutorial that a user can quickly download and run.
135+
1. Creates a rendered **.html** page with the code elements and code outputs in a user-friendly tutorial gallery.
136+
1. Creates a gallery landing page with visual thumbnails for each tutorial that you create
90137

91-
* Quickly launch a website using the documentation found in your GitHub repository.
92-
* Track versions of your documentation as you release updates.
138+
<!-- TODO: Add thumbnails out tutorial outputs -->
93139

94-
## Tutorials
95-
* sphinx gallery...
140+
### Sphinx Gallery benefits
141+
* easy-to-download notebook and .py outputs for each tutorials
142+
* .py files are easy to work with in the GitHub pull request environment.
143+
* Nice gridded gallery output
144+
145+
#### Sphinx gallery challenges
146+
147+
The downsides of using sphinx gallery include:
148+
149+
* the **.py** files can be finicky to configure, particularly if you have matplotlib plot outputs.
150+
151+
For example: To make allow for plots to render, you need to name each file with `plot_`
152+
at the beginning.
153+
154+
* Many users these days are used to working in Jupyter Notebooks. .py may be slightly less user friendly to work with
155+
156+
These nuances can make it challenging for potential contributors to add
157+
tutorials to your package. This can also present maintenance challenge.
158+
159+
Add about the gallery setup -
160+
```bash
161+
tutorials/
162+
index.rst # landing page for your gallery
163+
tutorial.py # a tutorial
164+
plot_tutorial.py # a tutorial that produces a plot output
165+
tutorial_outputs/
166+
add fils here...
167+
```
168+
169+
### [nbsphinx - tutorials using Jupyter Notebooks](https://nbsphinx.readthedocs.io/en/latest/)
170+
171+
If you prefer to use Jupyter Notebooks to create tutorials you can use nbsphinx.
172+
nbsphinx operates similarly to sphinx gallery in that:
173+
174+
* It runs your notebooks and produces outputs in the rendered tutorials
175+
176+
* Pro/con By default it does not support downloading of **.py** and **.ipynb** files. However you can add a [link to the notebook at the top of the page with
177+
some additional conf.py settings (see: epilog settings)](https://nbsphinx.readthedocs.io/en/0.8.10/prolog-and-epilog.html)
178+
179+
180+
```{figure} ../images/python-package-documentation-nb_sphinx-gallery-output.png
181+
---
182+
name: directive-fig
183+
width: 80%
184+
alt: Image showing the gallery output provided by nbsphinx using the sphinx-gallery front end interface.
185+
---
186+
`nbsphinx` can be combined with sphinx gallery to create a gallery of tutorials.
187+
However, rather render the gallery as a grid, it lists all of the gallery
188+
elements in a single column.
189+
```
190+
191+
```bash
192+
tutorials/
193+
index.md # Landing page for your gallery
194+
tutorial.ipynb # A tutorial in a jupyter notebook
195+
another_tutorial.ipynb
196+
tutorial_outputs/
197+
add fils here...
198+
```
96199

97-
<!-- Bells and whistles additions-->
98-
## Bells and whistles for your documentation
99200

100-
* sitemap - for google seo
101-
* other extension??
102-
* google analytics
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Hosting your Python package documentation and optimizing online content
2+
3+
## How to host your Python package documentation
4+
5+
We suggest that you setup a hosting for your Python package
6+
documentation. Two, free and most commonly used ways to
7+
quickly create a documentation website hosting environment are below.
8+
9+
1. You can host your documentation yourself using [GitHub Pages](https://pages.github.com/) or another online hosting service.
10+
1. You can host your documentation using [Read the Docs](https://readthedocs.org/).
11+
12+
If you don't want to maintain a documentation website for your Python package,
13+
we suggest using the Read the Docs website. Read the Docs allows you to:
14+
15+
* Quickly launch a website using the documentation found in your GitHub repository.
16+
* Track versions of your documentation as you release updates.
17+
* Provides support for Google analytics.
18+
* Allows you to turn on integration with pull requests where you can view documentation build progress (success vs failure).
19+
20+
21+
22+
## Optimizing your documentation so search engines (and other users) find it
23+
24+
If you are interested in more people finding your package, you may want to
25+
add some core sphinx extensions (and theme settings) that will help search
26+
engines such as Google find your documentation.
27+
28+
29+
### Google Analytics
30+
Some of the [sphinx themes such as the `pydata-sphinx-theme` and
31+
sphinx-book-theme have built in support for google analytics](https://pydata-sphinx-theme.readthedocs.io/en/latest/user_guide/analytics.html#google-analytics). However, if the theme that you chose does not offer
32+
Google Analytics support, you can use the [`sphinxcontrib-gtagjs` extension](https://github.com/attakei/sphinxcontrib-gtagjs).
33+
This extension will add a Google Analytics site tag to each page of your
34+
documentation.
35+
36+
### [sphinx-sitemap](https://sphinx-sitemap.readthedocs.io/en/latest/index.html)
37+
38+
If you are interested in optimizing your documentation for search engines such as Google, you want a sitemap.xml file. You can submit this sitemap to Google and it will index your entire site. This over time can make the content on your site more visible to others when they search.
39+
40+
This extension is light weight.
41+
42+
It [requires that you to add it to your sphinx `conf.py` extension list and site your documentation base url.](https://sphinx-sitemap.readthedocs.io/en/latest/getting-started.html).
43+
44+
### [sphinxext.opengraph](https://github.com/wpilibsuite/sphinxext-opengraph)
45+
46+
OpenGraph is an extension that allows you to add metadata to your documentation
47+
content pages. [The OpenGraph protocol allows other websites to provide a
48+
useful preview of the content on your page when shared](https://www.freecodecamp.org/news/what-is-open-graph-and-how-can-i-use-it-for-my-website/#what-is-open-graph). This is important
49+
for when the pages in your documentation are shared.
Loading
Loading

index.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,11 @@ to see here, [we invite you to open an issue on GitHub that details any changes
112112
:caption: Documentation
113113
114114
Documentation Overview <documentation/index>
115+
Package Documentation Best Practices <documentation/package-documentation-best-practices>
116+
Package Documentation Tools <documentation/python-package-documentation-tools>
117+
Host & Help People Find Your Docs <documentation/website-hosting-optimizing-your-docs>
115118
The README File <documentation/readme-file-best-practices.md>
116119
Contributing & License files <documentation/contributing-file>
117-
Package Documentation Tools <documentation/python-package-documentation-tools>
118-
Package Documentation Best Practices <documentation/package-documentation-best-practices>
119120
```
120121

121122
```{toctree}

0 commit comments

Comments
 (0)