Skip to content

Commit c5cacc6

Browse files
releasing 0.0.2 for launch
0 parents  commit c5cacc6

19 files changed

+1832
-0
lines changed

.readthedocs.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
python:
2+
version: 3
3+
install:
4+
- requirements: docs/requirements.txt
5+
setup_py_install: true

DESCRIPTION.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Qwiic GPIO Py
2+
==========================
3+
4+
This package controls the [SparkFun Qwiic GPIO](https://www.sparkfun.com/products/15993) using I<sup>2</sup>C.

DOCUMENTATION.md

Lines changed: 339 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,339 @@
1+
Documentation Generation and Publishing
2+
=============================================
3+
4+
For each package, the documentation is automatically generated and published using readthedocs.org. The documentation itself is generated using [Sphinx](http://www.sphinx-doc.org/), which creates the desired documentation HTML output based on source code comments and documentation structure files.
5+
6+
The repository files used to define and create the documentation are the following:
7+
```
8+
Qwiic_Template_Py/
9+
+--- docs/
10+
| +--- conf.py - defines the input and output behavior of Sphinx
11+
| +--- index.rst - Top level documentation structure definition
12+
| +--- *.rst - Defines additional pages for the documentation - index.rst references these files.
13+
| +--- requirements.txt - Lists the python modules the package depends on.
14+
| `--- _static/
15+
| `--- favicon.ico - the favicon to use for the generated HTML text
16+
|
17+
|--- .readthedocs.yml - Defines how the ReadTheDocs environment is setup when building the documentation
18+
```
19+
20+
21+
To create a packages documentation, the general development pattern is as follows:
22+
* Documentation is added to the python source code using [docstrings](https://www.python.org/dev/peps/pep-0257/)
23+
* Documentation configuration is define in ```docs/conf.py```
24+
* Package depenancies are added to ```docs/requirements.txt```
25+
* The file ```index.rst``` is updated for the desired documentation structure. Addtional ```.rst``` files are added as needed.
26+
* Documentation is generated locally using Sphinx for testing
27+
* Validated documentation files are checked into the GitHub repository.
28+
* The GitHub repository is imported and linked to a project in ReadTheDocs.org
29+
* ReadThe docs generates and publishes the documentation.
30+
* The documentation is updated automatically when the project is updated on GitHub
31+
32+
___Python Docstrings___
33+
34+
Python has a built-in language feature used to embedd documentation strings in code, a feature called _docstrings_.
35+
36+
From the docstring spec (PEP-0257):
37+
> A docstring is a string literal that occurs as the first statement in a module, function, class, or method definition. Such a docstring becomes the \__doc__ special attribute of that object.
38+
39+
These strings are enclosed by triple quotes. While the format of the text is left to the user, the Sphinx system will honor reStructured text formatting. The qwiic system python documentation formats the docstrings as reStructure Text.
40+
41+
An example of a docstring is the class definition for the QwiicBME280 object.
42+
```python
43+
class QwiicBme280(object):
44+
"""
45+
QwiicBme280
46+
47+
:param address: The I2C address to use for the device.
48+
If not provided, the default address is used.
49+
:param i2c_driver: An existing i2c driver object. If not provided
50+
a driver object is created.
51+
:return: The BME280 device object.
52+
:rtype: Object
53+
"""
54+
```
55+
Note that the docstring is the first statement after the class definition.
56+
57+
Doc strings for methods following the method declaration statement:
58+
```python
59+
def setFilter(self, filterSetting):
60+
"""
61+
Set the filter bits in the BME280s config register
62+
63+
:param filterSetting: The filter bits for the BME280. Acceptable values
64+
0 = filter off
65+
1 = coefficients = 2
66+
2 = coefficients = 4
67+
3 = coefficients = 8
68+
4 = coefficients = 16
69+
70+
:return: No return value
71+
72+
"""
73+
```
74+
75+
And you can even add docstrings to a module (file) - placing the docstring at the top (first non-comment) of the file.
76+
```python
77+
#==================================================================================
78+
79+
"""
80+
qwiic_bme280
81+
============
82+
Python module for the qwiic bme280 sensor, which is part of the [SparkFun Qwiic Environmental Combo Breakout](https://www.sparkfun.com/products/14348)
83+
84+
This python package is a port of the existing [SparkFun BME280 Arduino Library](https://github.com/sparkfun/SparkFun_BME280_Arduino_Library)
85+
86+
This package can be used in conjunction with the overall [SparkFun qwiic Python Package](https://github.com/sparkfun/Qwiic_Py)
87+
88+
New to qwiic? Take a look at the entire [SparkFun qwiic ecosystem](https://www.sparkfun.com/qwiic).
89+
90+
"""
91+
#-----------------------------------------------------------------------------
92+
93+
import math
94+
import qwiic_i2c
95+
```
96+
97+
The Sphinx documentation package uses the values of the ```__doc___``` attribute of objects to locate and generate documentation. As such, the Sphinx system (either run locally or by ReadTheDocs.org) will instatiate the package as part of the documentation generation process. As such, the depenancies and needs of the package must be defined in the documentation configuration files.
98+
99+
___docs/conf.py___
100+
101+
The ````docs/conf.py``` file sets the configuration Sphinx will use when building the documentation set. Key areas of this file are:
102+
103+
*Project Information*
104+
105+
These are variables that describe the project. The key value being the name of the project.
106+
```python
107+
project = 'sparkfun_qwiic_bme280'
108+
copyright = '2019, SparkFun Electronics'
109+
author = 'SparkFun Electronics'
110+
```
111+
112+
*Project Extensions*
113+
114+
This is an array that contains the names of extensions to the Sphinx system to geneate the documentation. These are python packages that should be installed on your system (for local documentation builds). For the qwiic python packages, the following statement is used:
115+
```python
116+
extensions = [
117+
'sphinx.ext.autodoc',
118+
'sphinx.ext.intersphinx',
119+
'sphinx.ext.viewcode',
120+
'm2r'
121+
]
122+
```
123+
The unique package here is ```m2r```, which converts markdown into reStructured text. This allows the documentation system to import the GitHub README.md files into the generated documentation page.
124+
125+
*master_doc*
126+
127+
This variable is set to the master documentation structure file being used. For the qwiic packages, this value is set to ```"index"```, which tells Sphinx to use ```index.rst``` to define the documentation structure.
128+
```python
129+
master_doc = 'index'
130+
```
131+
132+
*Static Values*
133+
134+
The last value worth noting is the static resources that should be used in documentation generation. For SparkFun documentation we include the favion.ico file from www.sparkfun.com. This file is located at ```docs/_static/favicon.ico``` and documented as follows in the conf.py file.
135+
```python
136+
# Add any paths that contain custom static files (such as style sheets) here,
137+
# relative to this directory. They are copied after the builtin static files,
138+
# so a file named "default.css" will overwrite the builtin "default.css".
139+
html_static_path = ['_static']
140+
141+
html_favicon = '_static/favicon.ico'
142+
```
143+
144+
___docs/*.rst Files___
145+
146+
The structure and contents of the documentation is oulined using a set of reStructured text (```.rst```) files, with the starting definition contained in ```docs/index.rst```.
147+
148+
*docs/index.rst*
149+
150+
This file defines the entry page for the documentation. For the qwiic documentation, we include the GitHub README.md file, and define a table of contents, which defines other pages of the documentation.
151+
152+
For the qwiic BME280 python package, this file contains the following:
153+
```rst
154+
.. mdinclude:: ../README.md
155+
156+
Table of Contents
157+
=================
158+
159+
.. toctree::
160+
:maxdepth: 4
161+
:caption: Contents:
162+
163+
self
164+
165+
166+
.. toctree::
167+
:caption: API Reference
168+
:maxdepth: 3
169+
170+
apiref
171+
172+
.. toctree::
173+
:caption: Examples
174+
175+
ex1
176+
ex4
177+
ex5
178+
179+
.. toctree::
180+
:caption: Other Links
181+
182+
SparkFun <https://sparkfun.com>
183+
SparkFun Environmental Combo Breakout CCS811/BME280 <https://www.sparkfun.com/products/14348>
184+
GitHub <https://github.com/sparkfun/Qwiic_BME280_Py>
185+
SparkFun qwiic <https://www.sparkfun.com/qwiic>
186+
```
187+
188+
The key elements of this file:
189+
190+
**.. mdinclude:: ../README.md**
191+
192+
This includes the packages README.md file, with ```mdinclude``` noting that the file is formatted in markdown.
193+
194+
**.. toctree:: **
195+
196+
Defines an section in the table of contents, and the content of this section.
197+
198+
For the main page (index.rst):
199+
```rst
200+
.. toctree::
201+
:maxdepth: 4
202+
:caption: Contents:
203+
204+
self
205+
```
206+
Note the section referances ```self```
207+
208+
For the package API:
209+
```rst
210+
.. toctree::
211+
:caption: API Reference
212+
:maxdepth: 3
213+
214+
apiref
215+
```
216+
This section links to the file ```apiref.rst```
217+
218+
And the examples section, which links to three example rst files: ```ex1.rst, ex4.rst, ex5.rst```
219+
```rst
220+
.. toctree::
221+
:caption: Examples
222+
223+
ex1
224+
ex4
225+
ex5
226+
```
227+
228+
*API Documentation*
229+
230+
To document the projects API, the *autodoc* system of Sphinx is used. This system will crawl the specified files/packages and generate documention using the included *docstrings*.
231+
232+
For a moduled, like ```qwiic_bme280```, the contents of ```apiref.rst``` is:
233+
```rst
234+
API Reference
235+
==============
236+
237+
.. automodule:: qwiic_bme280
238+
:members:
239+
```
240+
This specifies that Sphinx should inspect the qwiic_bme280 module, and document the package members.
241+
242+
Got python packages, such as the ```qwiic_mico_oled``` package, the documentation is contained in module and underlying class, so the rst file file takes a slightly different format:
243+
```rst
244+
API Reference
245+
==============
246+
247+
.. automodule:: qwiic_micro_oled
248+
:members:
249+
250+
251+
.. autoclass:: QwiicMicroOled
252+
:members:
253+
```
254+
255+
The Sphinx autodoc feature is extemely useful, and fully documented by the [Sphinx project](http://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html).
256+
257+
___Documenting Examples___
258+
259+
Any examples for a package are also included in the documentation. These are defined in individiual rst files, which do nothing more that include the source of the example.
260+
261+
The following shows the format of an an example rst file, which does nothing more that inline a file, add the filename as the caption of the inline, and formats the included file with line numbers.
262+
```rst
263+
Basic Operation
264+
---------------------------
265+
.. literalinclude:: ../examples/qwiic_bme280_ex1.py
266+
:caption: examples/qwiic_bme280_ex1.py
267+
:linenos:
268+
```
269+
270+
___The .readthedocs.yml File___
271+
272+
This file defines the attributes and packages ReadTheDocs should use when creating the documentation generation environment. As noted above, Sphinx instantiates the contents of the package so that it can access the python docstrings during the generation process. The file ```.readthedocs.yml``` and it's associated file ```docs/requirements.txt``` define the environment to use.
273+
274+
The contents of ```.readthedocs``` used by the qwiic modules is:
275+
```yml
276+
python:
277+
version: 3
278+
install:
279+
- requirements: docs/requirements.txt
280+
setup_py_install: true
281+
```
282+
This file tells ReadTheDocs the following:
283+
* Use Python version 3 to generate the docs
284+
* Install the modules contained in ```docs/requirements.txt```
285+
* Install the package/module defined by this repository using a the contents of ```setup.py```
286+
287+
The ```docs/requirements.txt``` file contains the modules this package needs to generate documentation. This is used by Sphinx when generating local documentation, and by ReadTheDocs, as noted above in the contents of the ```.readthedocs.yml``` file.
288+
289+
For most qwiic driver packages, this file contains the following:
290+
```txt
291+
m2r
292+
sparkfun-qwiic-i2c
293+
```
294+
The contents specifically being:
295+
296+
* mr2 - the Markdown to reStructureText conversion module
297+
* sparkfun-qwiic-i2 - the I2C driver package used by all qwiic packages.
298+
299+
Local Documentation Generation
300+
_______________________________
301+
302+
Sphinx is used to test the documentation before uploading the contents to ReadTheDocs.org. To build locally, execute the following steps:
303+
304+
Insure the needed packages are installed, which are Sphinx, the sphinx read the docs theme and the markdown to reStructure Text conversion package m2r.
305+
306+
```sh
307+
sudo pip install Sphinx sphinx_rtd_theme m2r
308+
```
309+
Additionally, the package being documented should be installed locally. Normally this is just done by running the following command in the root of the package directory.
310+
```sh
311+
sudo python setup.py install
312+
```
313+
314+
Once installed, the documentatin is created as follows:
315+
```sh
316+
cd docs
317+
sphinx-build -E -b html . _build/html
318+
```
319+
The output of this process is placed in the directory ```docs/_build/html```. The generated documentation is visible by loading the file ```index.html``` in a browser.
320+
321+
Publishing to ReadTheDocs.org
322+
-------------------------------
323+
324+
To publish the documentation on ReadTheDocs.org, you'll need an account. Once the account is created, it needs to be linked/connected to the your SFE GitHub account. This is a standard oAuth2 connection process, which is initited in the the Account -> Settings -> Connected Services section of readthedocs.org.
325+
326+
To import a project the following steps are taken:
327+
* First ensure the project contents are checked into GitHub and that the repository is public.
328+
* View "My Projects" on ReadTheDocs.
329+
* Select *Import a Project*
330+
* Under **Filter repositories** on the right of the page, select "SparkFun Electronics"
331+
* Either page through and find the project to import, or select "Import Manually" and enter the details of the target project.
332+
* Once imported, ReadTheDocs will being the build process for the documentation. The progress of this is followed by selecting the project on the [My Projects](https://readthedocs.org/dashboard/) page, and selected the project and once in the project, selecting the "Builds" button.
333+
* If the builds is successful, a link to the new documentation is made available.
334+
335+
If a documentation build fails, the best method to debug is to dig into the specific build (The Project -> Builds) and review the build log. If more detail is needed, the __View raw__ link on the build page will dispaly the raw log file from the build run.
336+
337+
#### Documentation Update
338+
339+
The update process for the documentation is automatic. Whenever the projects master branch on GitHub is updated, ReadTheDocs will initiate a documentation build using the new package content.

LICENSE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright 2020 SparkFun Electronics
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

0 commit comments

Comments
 (0)