Skip to content

Commit 018d2e9

Browse files
committed
WIP: Now upgraded with some auto-generated API documentation
1 parent a31ebe5 commit 018d2e9

File tree

8 files changed

+143
-8
lines changed

8 files changed

+143
-8
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ Tutorial](https://docs.readthedocs.io/en/stable/tutorial/index.html).
1111

1212
📚 [docs/](https://github.com/readthedocs-examples/example-sphinx-basic/blob/main/docs/)
1313

14-
: A basic Sphinx project lives in `docs/`, it was generated using
14+
A basic Sphinx project lives in `docs/`, it was generated using
1515
Sphinx defaults. All the `*.rst` make up sections in the
1616
documentation.
1717

1818
⚙️ [.readthedocs.yaml](https://github.com/readthedocs-examples/example-sphinx-basic/blob/main/.readthedocs.yaml)
1919

20-
: Read the Docs Build configuration is stored in `.readthedocs.yaml`.
20+
Read the Docs Build configuration is stored in `.readthedocs.yaml`.
2121

2222
📍 [docs/requirements.txt](https://github.com/readthedocs-examples/example-sphinx-basic/blob/main/docs/requirements.txt) and [docs/requirements.in](https://github.com/readthedocs-examples/example-sphinx-basic/blob/main/docs/requirements.in)
2323

24-
: Python dependencies are
24+
Python dependencies are
2525
[pinned](https://docs.readthedocs.io/en/latest/guides/reproducible-builds.html)
2626
(uses [pip-tools](https://pip-tools.readthedocs.io/en/latest/)).
2727

@@ -33,32 +33,32 @@ Tutorial](https://docs.readthedocs.io/en/stable/tutorial/index.html).
3333

3434
💡 [docs/usage.rst](https://github.com/readthedocs-examples/example-sphinx-basic/blob/main/docs/usage.rst)
3535

36-
: Sphinx can automatically extract API documentation directly from
36+
Sphinx can automatically extract API documentation directly from
3737
Python modules, using for instance the `:autofunction:` directive.
3838

3939
💡 [lumache.py](https://github.com/readthedocs-examples/example-sphinx-basic/blob/main/lumache.py)
4040

41-
: API docs are generated for this example Python module - they use
41+
API docs are generated for this example Python module - they use
4242
*docstrings* directly in the documentation, notice how this shows up
4343
in the rendered documentation.
4444

4545
🔢 Git tags versioning
4646

47-
: We use a basic versioning mechanism by adding a git tag for every
47+
We use a basic versioning mechanism by adding a git tag for every
4848
release of the example project. All releases and their version
4949
numbers are visible on
5050
[example-sphinx-basic.readthedocs.io](https://example-sphinx-basic.readthedocs.io/en/latest/).
5151

5252
📜 [README.rst](https://github.com/readthedocs-examples/example-sphinx-basic/blob/main/README.rst)
5353

54-
: Contents of this `README.rst` are visible on Github and included on
54+
Contents of this `README.rst` are visible on Github and included on
5555
[the documentation index
5656
page](https://example-sphinx-basic.readthedocs.io/en/latest/)
5757
(Don\'t Repeat Yourself).
5858

5959
⁉️ Questions / comments
6060

61-
: If you have questions related to this example, feel free to can ask
61+
If you have questions related to this example, feel free to can ask
6262
them as a Github issue
6363
[here](https://github.com/readthedocs-examples/example-sphinx-basic/issues).
6464

README.rst

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
Example: Basic Sphinx project for Read the Docs
2+
===============================================
3+
4+
.. image:: https://readthedocs.org/projects/example-sphinx-basic/badge/?version=latest
5+
:target: https://example-sphinx-basic.readthedocs.io/en/latest/?badge=latest
6+
:alt: Documentation Status
7+
8+
.. This README.rst should work on Github and is also included in the Sphinx documentation project in docs/ - therefore, README.rst uses absolute links for most things so it renders properly on GitHub
9+
10+
This example shows the an integration of a basic Sphinx project with Read the Docs. You're encouraged to view it to get inspiration and copy & paste from the files in the source code. If you are using Read the Docs for the first time, have a look at the official `Read the Docs Tutorial <https://docs.readthedocs.io/en/stable/tutorial/index.html>`__.
11+
12+
📚 `docs/ <https://github.com/readthedocs-examples/example-sphinx-basic/blob/main/docs/>`_
13+
A basic Sphinx project lives in ``docs/``, it was generated using Sphinx defaults. All the ``*.rst`` make up sections in the documentation.
14+
⚙️ `.readthedocs.yaml <https://github.com/readthedocs-examples/example-sphinx-basic/blob/main/.readthedocs.yaml>`_
15+
Read the Docs Build configuration is stored in ``.readthedocs.yaml``.
16+
📍 `docs/requirements.txt <https://github.com/readthedocs-examples/example-sphinx-basic/blob/main/docs/requirements.txt>`_ and `docs/requirements.in <https://github.com/readthedocs-examples/example-sphinx-basic/blob/main/docs/requirements.in>`_
17+
Python dependencies are `pinned <https://docs.readthedocs.io/en/latest/guides/reproducible-builds.html>`_ (uses `pip-tools <https://pip-tools.readthedocs.io/en/latest/>`_).
18+
💡 `docs/api.rst <https://github.com/readthedocs-examples/example-sphinx-basic/blob/main/docs/api.rst>`_
19+
By adding our example Python module ``lumache`` in the reStructuredText directive ``:autosummary:``, Sphinx will automatically scan this module and generate API docs.
20+
💡 `docs/usage.rst <https://github.com/readthedocs-examples/example-sphinx-basic/blob/main/docs/usage.rst>`_
21+
Sphinx can automatically extract API documentation directly from Python modules, using for instance the ``:autofunction:`` directive.
22+
💡 `lumache.py <https://github.com/readthedocs-examples/example-sphinx-basic/blob/main/lumache.py>`_
23+
API docs are generated for this example Python module - they use *docstrings* directly in the documentation, notice how this shows up in the rendered documentation.
24+
🔢 Git tags versioning
25+
We use a basic versioning mechanism by adding a git tag for every release of the example project. All releases and their version numbers are visible on `example-sphinx-basic.readthedocs.io <https://example-sphinx-basic.readthedocs.io/en/latest/>`__.
26+
📜 `README.rst <https://github.com/readthedocs-examples/example-sphinx-basic/blob/main/README.rst>`_
27+
Contents of this ``README.rst`` are visible on Github and included on `the documentation index page <https://example-sphinx-basic.readthedocs.io/en/latest/>`_ (Don't Repeat Yourself).
28+
⁉️ Questions / comments
29+
If you have questions related to this example, feel free to can ask them as a Github issue `here <https://github.com/readthedocs-examples/example-sphinx-basic/issues>`_.
30+
31+
32+
Sphinx Example Project usage
33+
----------------------------
34+
35+
This project has a standard Sphinx layout which is built by Read the Docs almost the same way that you would build it locally (on your own laptop!).
36+
37+
You can build and view this documentation project locally - we recommend that you activate `a local Python virtual environment first <https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/#creating-a-virtual-environment>`_:
38+
39+
.. code-block:: console
40+
41+
# Install required Python dependencies (Sphinx etc.)
42+
pip install -r docs/requirements.txt
43+
44+
# Enter the Sphinx project
45+
cd docs/
46+
47+
# Run the raw sphinx-build command
48+
sphinx-build -M html . _build/
49+
50+
51+
You can also build the documentation locally with ``make``:
52+
53+
.. code-block:: console
54+
55+
# Enter the Sphinx project
56+
cd docs/
57+
58+
# Build with make
59+
make html
60+
61+
# Open with your preferred browser, pointing it to the documentation index page
62+
firefox _build/html/index.html
63+
64+
65+
Using the example in your own project
66+
-------------------------------------
67+
68+
If you are new to Read the Docs, you may want to refer to the `Read the Docs User documentation <https://docs.readthedocs.io/>`_.
69+
70+
If you are copying this code in order to get started with your documentation, you need to:
71+
72+
* Create a new repository on Github, GitLab, Bitbucket or another host supported by Read the Docs
73+
* Customize all ``docs/*.rst`` files
74+
* Add your own Python project, replacing the ``pyproject.toml`` configuration and ``lumache.py`` module.
75+
* Rebuild the documenation locally to see that it works.
76+
* Register your project on Read the Docs, see `Importing Your Documentation <https://docs.readthedocs.io/en/stable/intro/import-guide.html>`_.
77+
78+
79+
Read the Docs tutorial
80+
----------------------
81+
82+
To get started with Read the Docs, you may also refer to the `Read the Docs tutorial <https://docs.readthedocs.io/en/stable/tutorial/>`__.
83+
It provides a full walk-through of building an example project similar to the one in this repository.

docs/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ For full documentation visit [mkdocs.org](https://www.mkdocs.org).
1515
docs/
1616
index.md # The documentation homepage.
1717
... # Other markdown pages, images and other files.
18+
19+
# Reference
20+
21+
::: lumache

docs/requirements.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
mkdocs
2+
mkdocstrings[python]

docs/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
mkdocs==1.3.0
2+
mkdocstrings==0.19.0[python]

lumache.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""
2+
Lumache - Python library for cooks and food lovers.
3+
4+
This is a Python docstring, we can use Markdown syntax here because
5+
our API documentation library understands it (mkdocstrings).
6+
7+
# Import lumache
8+
import lumache
9+
10+
# Call its only function
11+
get_random_ingredients(kind=["cheeses"])
12+
13+
"""
14+
15+
__version__ = "0.1.0"
16+
17+
18+
class InvalidKindError(Exception):
19+
"""Raised if the kind is invalid."""
20+
21+
pass
22+
23+
24+
def get_random_ingredients(kind=None):
25+
"""
26+
Return a list of random ingredients as strings.
27+
28+
:param kind: Optional "kind" of ingredients.
29+
:type kind: list[str] or None
30+
:raise lumache.InvalidKindError: If the kind is invalid.
31+
:return: The ingredients list.
32+
:rtype: list[str]
33+
"""
34+
return ["shells", "gorgonzola", "parsley"]

mkdocs.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
site_name: My Docs
22
theme: readthedocs
3+
plugins:
4+
- search
5+
- mkdocstrings

pyproject.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[build-system]
2+
requires = ["flit_core >=3.2,<4"]
3+
build-backend = "flit_core.buildapi"
4+
5+
[project]
6+
name = "lumache"
7+
authors = [{name = "Graziella", email = "graziella@lumache"}]
8+
dynamic = ["version", "description"]

0 commit comments

Comments
 (0)