| 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 -M html docs/source/ docs/build/ |
| 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. |
| 120 |
Now you can start :doc:`customizing it </tutorial/first-steps>`. |