Skip to content

Commit f152680

Browse files
committed
Split tutorial in several files
1 parent c66b3ad commit f152680

File tree

6 files changed

+425
-422
lines changed

6 files changed

+425
-422
lines changed

doc/tutorial/end.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Where to go from here
2+
=====================
3+
4+
This tutorial covered the very first steps to create a documentation project
5+
with Sphinx. To continue learning more about Sphinx, check out the :ref:`rest
6+
of the documentation <contents>`.

doc/tutorial/first-steps.rst

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
First steps to document your project using Sphinx
2+
=================================================
3+
4+
Building your HTML documentation
5+
--------------------------------
6+
7+
The ``index.rst`` file that ``sphinx-quickstart`` created has some content
8+
already, and it gets rendered as the front page of your HTML documentation. It
9+
is written in reStructuredText, a powerful markup language.
10+
11+
Modify the file as follows:
12+
13+
.. code-block:: rst
14+
:caption: docs/source/index.rst
15+
16+
Welcome to Lumache's documentation!
17+
===================================
18+
19+
**Lumache** (/lu'make/) is a Python library for cooks and food lovers that
20+
creates recipes mixing random ingredients. It pulls data from the `Open Food
21+
Facts database <https://world.openfoodfacts.org/>`_ and offers a *simple* and
22+
*intuitive* API.
23+
24+
.. note::
25+
26+
This project is under active development.
27+
28+
This showcases several features of the reStructuredText syntax, including:
29+
30+
- a **section header** using ``===`` for the underline,
31+
- two examples of :ref:`rst-inline-markup`: ``**strong emphasis**`` (typically
32+
bold) and ``*emphasis*`` (typically italics),
33+
- an **inline external link**,
34+
- and a ``note`` **admonition** (one of the available :ref:`directives
35+
<rst-directives>`)
36+
37+
Now to render it with the new content, you can use the ``sphinx-build`` command
38+
as before, or leverage the convenience script as follows:
39+
40+
.. code-block:: console
41+
42+
(.venv) $ cd docs
43+
(.venv) $ make html
44+
45+
After running this command, you will see that ``index.html`` reflects the new
46+
changes!
47+
48+
Building your documentation in other formats
49+
--------------------------------------------
50+
51+
Sphinx supports a variety of formats apart from HTML, including PDF, EPUB,
52+
:ref:`and more <builders>`. For example, to build your documentation
53+
in EPUB format, run this command from the ``docs`` directory:
54+
55+
.. code-block:: console
56+
57+
(.venv) $ make epub
58+
59+
After that, you will see the files corresponding to the e-book under
60+
``docs/build/epub/``. You can either open ``Lumache.epub`` with an
61+
EPUB-compatible e-book viewer, like `Calibre <https://calibre-ebook.com/>`_,
62+
or preview ``index.xhtml`` on a web browser.
63+
64+
.. note::
65+
66+
To quickly display a complete list of possible output formats, plus some
67+
extra useful commands, you can run :code:`make help`.
68+
69+
Each output format has some specific configuration options that you can tune,
70+
:ref:`including EPUB <epub-options>`. For instance, the default value of
71+
:confval:`epub_show_urls` is ``inline``, which means that, by default, URLs are
72+
shown right after the corresponding link, in parentheses. You can change that
73+
behavior by adding the following code at the end of your ``conf.py``:
74+
75+
.. code-block:: python
76+
77+
# EPUB options
78+
epub_show_urls = 'footnote'
79+
80+
With this configuration value, and after running ``make epub`` again, you will
81+
notice that URLs appear now as footnotes, which avoids cluttering the text.
82+
Sweet!
83+
84+
.. note::
85+
86+
Generating a PDF using Sphinx can be done running ``make latexpdf``,
87+
provided that the system has a working LaTeX installation,
88+
as explained in the documentation of :class:`sphinx.builders.latex.LaTeXBuilder`.
89+
Although this is perfectly feasible, such installations are often big,
90+
and in general LaTeX requires careful configuration in some cases,
91+
so PDF generation is out of scope for this tutorial.

doc/tutorial/getting-started.rst

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
Getting started
2+
===============
3+
4+
Setting up your project and development environment
5+
---------------------------------------------------
6+
7+
In a new directory, create a file called ``README.rst`` with the following
8+
content.
9+
10+
.. code-block:: rst
11+
:caption: README.rst
12+
13+
Lumache
14+
=======
15+
16+
**Lumache** (/lu'make/) is a Python library for cooks and food lovers that
17+
creates recipes mixing random ingredients.
18+
19+
It is a good moment to create a Python virtual environment and install the
20+
required tools. For that, open a command line terminal, ``cd`` into the
21+
directory you just created, and run the following commands:
22+
23+
.. code-block:: console
24+
25+
$ python -m venv .venv
26+
$ source .venv/bin/activate
27+
(.venv) $ python -m pip install sphinx
28+
29+
.. note::
30+
31+
The installation method used above is described in more detail in
32+
:ref:`install-pypi`. For the rest of this tutorial, the instructions will
33+
assume a Python virtual environment.
34+
35+
If you executed these instructions correctly, you should have the Sphinx command
36+
line tools available. You can do a basic verification running this command:
37+
38+
.. code-block:: console
39+
40+
(.venv) $ sphinx-build --version
41+
sphinx-build 4.0.2
42+
43+
If you see a similar output, you are on the right path!
44+
45+
Creating the documentation layout
46+
---------------------------------
47+
48+
Then from the command line, run the following command:
49+
50+
.. code-block:: console
51+
52+
(.venv) $ sphinx-quickstart docs
53+
54+
This will present to you a series of questions required to create the basic
55+
directory and configuration layout for your project inside the ``docs`` folder.
56+
To proceed, answer each question as follows:
57+
58+
- ``> Separate source and build directories (y/n) [n]``: Write "``y``" (without
59+
quotes) and press :kbd:`Enter`.
60+
- ``> Project name``: Write "``Lumache``" (without quotes) and press
61+
:kbd:`Enter`.
62+
- ``> Author name(s)``: Write "``Graziella``" (without quotes) and press
63+
:kbd:`Enter`.
64+
- ``> Project release []``: Write "``0.1``" (without quotes) and press
65+
:kbd:`Enter`.
66+
- ``> Project language [en]``: Leave it empty (the default, English) and press
67+
:kbd:`Enter`.
68+
69+
After the last question, you will see the new ``docs`` directory with the
70+
following content.
71+
72+
.. code-block:: text
73+
74+
docs
75+
├── build
76+
├── make.bat
77+
├── Makefile
78+
└── source
79+
├── conf.py
80+
├── index.rst
81+
├── _static
82+
└── _templates
83+
84+
The purpose of each of these files is:
85+
86+
``build/``
87+
An empty directory (for now) that will hold the rendered documentation.
88+
89+
``make.bat`` and ``Makefile``
90+
Convenience scripts to simplify some common Sphinx operations, such as
91+
rendering the content.
92+
93+
``source/conf.py``
94+
A Python script holding the configuration of the Sphinx project. It contains
95+
the project name and release you specified to ``sphinx-quickstart``, as well
96+
as some extra configuration keys.
97+
98+
``source/index.rst``
99+
The :term:`root document` of the project, which serves as welcome page and
100+
contains the root of the "table of contents tree" (or *toctree*).
101+
102+
Thanks to this bootstrapping step, you already have everything needed to render
103+
the documentation as HTML for the first time. To do that, run this command:
104+
105+
.. code-block:: console
106+
107+
(.venv) $ sphinx-build -b html docs/source/ docs/build/html
108+
109+
And finally, open ``docs/build/html/index.html`` in your browser. You should see
110+
something like this:
111+
112+
.. figure:: /_static/tutorial/lumache-first-light.png
113+
:width: 80%
114+
:align: center
115+
:alt: Freshly created documentation of Lumache
116+
117+
Freshly created documentation of Lumache
118+
119+
There we go! You created your first HTML documentation using Sphinx.

0 commit comments

Comments
 (0)