You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: documentation/index.md
+23-10Lines changed: 23 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,20 @@
1
1
# Documentation for your Open Source Python Package - An Overview
2
2
3
+
```{important}
4
+
## Quick Takeaways: Documentation must haves
5
+
6
+
Your package should at a minimum have:
7
+
* README.MD file
8
+
* CONTRIBUTING.md file
9
+
* CODE_OF_CONDUCT.md
10
+
* LICENSE.txt
11
+
* User-facing documentation website with tutorials
12
+
* API documentation (often found in the user facing documentation website)
13
+
14
+
The pages in this section of our guide provide you with more
15
+
detail about creating each of the above elements. We also suggest
16
+
tools that will help you build your documentation.
17
+
```
3
18
4
19
## Documentation is critical to the success of your Python open source package
5
20
@@ -17,22 +32,20 @@ In the pyOpenSci open peer review process we look for several files and elements
17
32
when evaluating package documentation, including:
18
33
19
34
1.[A clear and to the point **README.md** file](readme-file-best-practices)
20
-
1.**User oriented package documentation** that helps users understand how to install, use and cite your package.
35
+
1.[**User focused package documentation**](package-documentation-best-practices) that helps users understand how to install, use and cite your package. Documentation is most often contained in a stand-alone website.
21
36
1.**Tutorials and quick start code examples** that help a user get started using your package.
22
-
1.**Package API documentation.** Package API documentation refers to documentation for each class, function, method and user-facing attribute (*available for a user to see*) in your package. This means that your package methods and classes should have [thoughtful docstrings](https://pandas.pydata.org/docs/development/contributing_docstring.html) that describe both the purpose of the code element and each input and output. To help your users better understand how to use your package, you can include short code examples showing how to use the function or class in each docstring. If you don't know what API documentation means, this section of the pyOpenSci Python packaging guide is for you!
23
-
1. A **CONTRIBUTING.md** file that outlines how others can contribute to your package. This file should also link to your development guide and code of conduct. A well-crafted contributing guide will make it much easier for the community to contribute to your project.
24
-
1. A **CODE_OF_CONDUCT.md** file.
25
-
1.**LICENSE.txt file & Citation instructions:** A license file and instructions for citing your package.
26
-
27
-
37
+
1.**Package API documentation.** Package API documentation refers to documentation for each class, function, method and user-facing attribute (*available for a user to see*) in your package. This means that your package methods and classes should have [thoughtful docstrings](https://pandas.pydata.org/docs/development/contributing_docstring.html) that describe both the purpose of the code element and each input and output.
38
+
1. A [**CONTRIBUTING.md** file](contributing-license-coc) that outlines how others can contribute to your package. This file should also link to your development guide and code of conduct. A well-crafted contributing guide will make it much easier for the community to contribute to your project.
39
+
1. A [**CODE_OF_CONDUCT.md**](contributing-license-coc.html#the-code-of-conduct-md-file) file. This file sets up the guidelines for how your community interacts. It ideally ensures that everyone feels safe and can report inappropriate behavior if need be. <!--<not sure why header targets aren't working here with sphinx they work online> -->
40
+
1.[**LICENSE.txt file & Citation instructions:**](contributing-license-coc.html#your-repository-should-have-a-license-md-file) A license file declaring the OSI-approved license that you select and instructions for citing your package.
alt: Image showing the files in the Moving Pandas GitHub repository.
34
47
---
35
-
An example GitHub repository with all of the major files in it including CONTRIBUTING.md, README.md, CODE_OF_CONDUCT.md and a LICENSE.txt file. *(screen shot taken Nov 23 2022)*
48
+
An example from the MovingPandas GitHub repository with all of the major files in it including CONTRIBUTING.md, README.md, CODE_OF_CONDUCT.md and a LICENSE.txt file. *(screen shot taken Nov 23 2022)*
36
49
```
37
50
38
51
The above files are evaluated on many online platforms that track package health.
@@ -44,7 +57,7 @@ has in their GitHub repository.
44
57
name: directive-fig
45
58
width: 80%
46
59
---
47
-
GitHub community health looks for a readme file among other elements when it evaluates the community level health of your repository. This example is from the [moving pandas GitHub repo](https://github.com/anitagraser/movingpandas/community) *(screen shot taken Nov 23 2022)*
60
+
GitHub community health looks for a readme file among other elements when it evaluates the community level health of your repository. This example is from the [MovingPandas GitHub repo](https://github.com/anitagraser/movingpandas/community) *(screen shot taken Nov 23 2022)*
48
61
```
49
62
50
63
SNYK is another well-known company that keeps tabs on package health.
@@ -63,7 +76,7 @@ Screenshot showing [SNYK](https://snyk.io/advisor/python/movingpandas) package h
63
76
## What's next in this Python package documentation section?
64
77
65
78
The rest of the pages in this section will walk you through best practices for setting up
66
-
documentation for your Python package.
79
+
documentation for your Python package. We will also suggest tools that you can use to build your user-facing documentation website.
67
80
68
81
69
82
<!-- # TODO LINK TO CI BUILD examples FOR Documentation - we have plenty in our repos already for folks to look at. -->
Copy file name to clipboardExpand all lines: documentation/package-documentation-best-practices.md
+24-3Lines changed: 24 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,11 +1,23 @@
1
1
# Best practices for writing user-facing documentation for your Python package
2
2
3
+
```{important}
4
+
## Quick takeaways: best practices
5
+
6
+
Your package:
7
+
* Should have a documentation website
8
+
* All of its functions and classes (the API) documented
9
+
* Your package should use numpy-style docstrings
10
+
* Your documentation landing page should direct users to 4 core sections: get started, documentation content, about and community.
11
+
* Documentation should include short quick-start tutorials
12
+
```
13
+
3
14
In addition to a well designed [README.md file](readme-file-best-practices),
4
15
and a [CONTRIBUTING.md file](contributing-file),
5
16
there are several core components of Python package documentation,
6
17
including:
7
18
8
19
***User-facing documentation website:** This refers to easy-to-read documentation that helps a user work with your package. This documentation should help users both install and use the functionality of your package.
20
+
* Your user facing documentation should also include [short tutorials that show a user how to quickly get started using your package](python-package-documentation-tools.html#create-python-package-tutorials-that-both-help-users-and-test-your-package-s-code). If you use a tool such as sphinx-gallery or nbsphinx that runs the code in your tutorials, then these tutorials can also become an important part of your package's test suite.
9
21
***API documentation:** The API refers to the functions and classes in a
10
22
package that makes up the user interface. API documentation is generated from [docstrings](https://pandas.pydata.org/docs/development/contributing_docstring.html) found in your
11
23
code. Ideally you have docstrings for all user-facing functions, methods and classes in
@@ -53,11 +65,20 @@ Below is an example of doing this using `myst` syntax.
53
65
````
54
66
`````
55
67
56
-
## API's and Docstrings
68
+
## Create tutorials in your documentation
69
+
Your package should have tutorials that make it easy for a user
70
+
to get started using your package. Ideally, those tutorials
71
+
also can be run from start to finish providing a second set of
72
+
checks (on top of your test suite) to your package's code base.
57
73
58
-
### What is an API?
74
+
In the [documentation tools page](python-package-documentation-tools) we talk about two sphinx extensions (sphinx gallery and nbsphinx)
75
+
that allow you to create reproducible tutorials that are run
76
+
when your sphinx documentation builds.
59
77
60
-
API standards for **A**pplied **P**rogramming **I**nterface. When
78
+
## Documenting the code in your package's API using docstrings
79
+
80
+
### What is an API?
81
+
API stands for **A**pplied **P**rogramming **I**nterface. When
61
82
discussed in the context of a (Python) package, the API refers to
62
83
the interface and tools that you, as a package user, use in a package.
Copy file name to clipboardExpand all lines: documentation/python-package-documentation-tools.md
+66-15Lines changed: 66 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,13 +10,13 @@ important points page -->
10
10
* Use Sphinx to build your documentation
11
11
* Publish your documentation on ReadTheDocs (or GitHub pages if you are more advanced and also prefer to maintain your website locally)
12
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.
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
14
15
15
```
16
16
17
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),
18
+
*[README.md file](readme-file-best-practices),
19
+
*[CONTRIBUTING.md and development guides and LICENSE file](contributing-license-coc),
20
20
21
21
you should also have user-facing documentation for your Python
22
22
package. Most often, user-facing documentation is contained on a hosted
@@ -30,9 +30,9 @@ Here, we focus on tools and infrastructure that you can use.
30
30
[Click here if you want to learn more about documentation best practices](package-documentation-best-practices.md).
31
31
32
32
```{note}
33
-
Examples of documentation that we love:
33
+
Examples of documentation websites that we love:
34
34
35
-
* [geopandas](https://geopandas.org/en/stable/)
35
+
* [GeoPandas](https://geopandas.org/en/stable/)
36
36
* [View rst to create landing page](https://raw.githubusercontent.com/geopandas/geopandas/main/doc/source/index.rst)
@@ -107,7 +107,7 @@ If you are on the fence about myST vs rst, you might find that **myST** is easie
107
107
for more people to contribute to.
108
108
```
109
109
110
-
## Sphinx extensions to support python package tutorials
110
+
## Create python package tutorials that both help users and test your package's code
111
111
112
112
Adding well constructed tutorials to your package will make it easier for someone
113
113
new to begin using your package.
@@ -135,12 +135,34 @@ your documentation, the gallery extension:
135
135
1. Creates a rendered **.html** page with the code elements and code outputs in a user-friendly tutorial gallery.
136
136
1. Creates a gallery landing page with visual thumbnails for each tutorial that you create
137
137
138
-
<!-- TODO: Add thumbnails out tutorial outputs -->
138
+
139
+
```{figure} ../images/sphinx-gallery-overview.png
140
+
---
141
+
name: directive-fig
142
+
width: 80%
143
+
alt: Image showing the gallery output provided by sphinx-gallery where each tutorial is in a grid and the tutorial thumbnails are created from a graphic in the tutorial.
144
+
---
145
+
`sphinx-gallery` makes it easy to create a user-friendly tutorial gallery.
146
+
Each tutorial has a download link where the user can download a **.py** file or a Jupyter Notebook. And it renders the tutorials in a user-friendly grid.
147
+
```
148
+
149
+
Below you can see what a tutorial looks like created with sphinx-gallery.
150
+
151
+
```{figure} ../images/sphinx-gallery-tutorial.png
152
+
---
153
+
name: directive-fig
154
+
width: 80%
155
+
alt: Image showing ta single tutorial from sphinx gallery. The tutorial shows a simple matplotlib created plot and associated code.
156
+
---
157
+
`sphinx-gallery` tutorials by default include download links for both the
158
+
python script (**.py** file) and a Jupyter notebook (**.ipynb** file) at the bottom.
159
+
```
139
160
140
161
### Sphinx Gallery benefits
141
162
* easy-to-download notebook and .py outputs for each tutorials
142
163
* .py files are easy to work with in the GitHub pull request environment.
143
-
* Nice gridded gallery output
164
+
* Nice gridded gallery output
165
+
* Build execution time data per tutorial [Example](https://sphinx-gallery.github.io/stable/auto_examples/sg_execution_times.html)
144
166
145
167
#### Sphinx gallery challenges
146
168
@@ -157,13 +179,31 @@ These nuances can make it challenging for potential contributors to add
157
179
tutorials to your package. This can also present maintenance challenge.
158
180
159
181
Add about the gallery setup -
182
+
183
+
```bash
184
+
$ docs % make html
185
+
186
+
Sphinx-Gallery successfully executed 2 out of 2 files
187
+
```
188
+
File directory structure:
189
+
160
190
```bash
161
191
tutorials/
162
192
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...
193
+
plot_tutorial.py # a tutorial
194
+
plot_tutorial-2.py # a tutorial that produces a plot output
195
+
_build/
196
+
build_examples/ # This is where the downloadable tutorial files live
197
+
plot_sample-1.ipynb
198
+
plot_sample-1.py
199
+
...
200
+
html/
201
+
built_examples/ # You can specify this dir name in gallery settings
202
+
index.html
203
+
plot_sample-1.html
204
+
plot_sample.html
205
+
sg_execution_times.html # in case you want to see build times for each tutorial
206
+
167
207
```
168
208
169
209
### [nbsphinx - tutorials using Jupyter Notebooks](https://nbsphinx.readthedocs.io/en/latest/)
@@ -193,8 +233,19 @@ tutorials/
193
233
index.md # Landing page for your gallery
194
234
tutorial.ipynb # A tutorial in a jupyter notebook
195
235
another_tutorial.ipynb
196
-
tutorial_outputs/
197
-
add fils here...
198
-
```
236
+
# This shows you what the build directory looks like when you build with sphinx-build
237
+
_build/
238
+
html/
239
+
# Notice that nbsphinx runs each notebook and produces an
240
+
# html file with all of the outputs of your code
241
+
# you can link to the notebook in your docs by modifying
242
+
# the nbsphinx build - we will cover this in a separate tutorial series focused on python packaging!
0 commit comments