Skip to content

Commit 0e5818a

Browse files
authored
Merge pull request #8473 from readthedocs/juanlu/rtd-tutorial-part-ii
New Read the Docs tutorial, part II
2 parents 3f6ed2e + d04e09e commit 0e5818a

File tree

8 files changed

+289
-5
lines changed

8 files changed

+289
-5
lines changed
51.3 KB
Loading
Loading
Loading
Loading
Loading

docs/glossary.rst

+9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ Glossary
77
`Main page <https://readthedocs.org/dashboard>`_ where you can see all your projects with their build status
88
and import a new project.
99

10+
flyout menu
11+
Menu displayed on the documentation, readily accessible for readers, containing the list active versions,
12+
links to the static downloads, and other useful information.
13+
1014
profile page
1115
Page where you can see the projects of a certain user.
1216

@@ -16,3 +20,8 @@ Glossary
1620

1721
project page
1822
Another name for :term:`project home`.
23+
24+
root URL
25+
Home URL of your documentation without the ``/<lang>`` and ``/<version>`` segments.
26+
For projects without custom domains, the one ending in ``.readthedocs.io/``
27+
(for example, ``https://docs.readthedocs.io`` as opposed to ``https://docs.readthedocs.io/en/latest``).

docs/tutorial/index.rst

+277-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,10 @@ __ https://docs.github.com/en/github/managing-files-in-a-repository/managing-fi
259259

260260
In the editor, add the following sentence to the file:
261261

262-
Lumache has its documentation hosted on Read the Docs.
262+
.. code-block:: rst
263+
:caption: docs/source/index.rst
264+
265+
Lumache has its documentation hosted on Read the Docs.
263266
264267
Write an appropriate commit message,
265268
and choose the "Create a **new branch** for this commit and start a pull request" option,
@@ -282,6 +285,279 @@ you will access the build logs,
282285
otherwise it will take you directly to the documentation.
283286
When you are satisfied, you can merge the pull request!
284287

288+
Customizing the build process
289+
-----------------------------
290+
291+
The Settings page of the :term:`project home` allows you
292+
to change some *global* configuration values of your project.
293+
In addition, you can further customize the building process
294+
using the ``.readthedocs.yaml`` :doc:`configuration file </config-file/v2>`.
295+
This has several advantages:
296+
297+
- The configuration lives next to your code and documentation, tracked by version control.
298+
- It can be different for every version (more on versioning in the next section).
299+
- Some configurations are only available using the config file.
300+
301+
Read the Docs works without this configuration by making some decisions on your behalf.
302+
For example, what Python version to use, how to install the requirements, and others.
303+
304+
.. tip::
305+
306+
Settings that apply to the entire project are controlled in the web dashboard,
307+
while settings that are version or build specific are better in the YAML file.
308+
309+
Upgrading the Python version
310+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
311+
312+
For example, to explicitly use Python 3.8 to build your project,
313+
navigate to your GitHub repository, click on the :guilabel:`Add file` button,
314+
and add a ``.readthedocs.yaml`` file with these contents to the root of your project:
315+
316+
.. code-block:: yaml
317+
:caption: .readthedocs.yaml
318+
319+
version: 2
320+
321+
python:
322+
version: "3.8"
323+
324+
The purpose of each key is:
325+
326+
``version``
327+
Mandatory, specifies :doc:`version 2 of the configuration file </config-file/v2>`.
328+
329+
``python.version``
330+
Declares the Python version to be used.
331+
332+
After you commit these changes, go back to your project home,
333+
navigate to the "Builds" page, and open the new build that just started.
334+
You will notice that one of the lines contains ``python3.8``:
335+
if you click on it, you will see the full output of the corresponding command,
336+
stating that it used Python 3.8.6 to create the virtual environment.
337+
338+
.. figure:: /_static/images/tutorial/build-python3.8.png
339+
:width: 80%
340+
:align: center
341+
:alt: Read the Docs build using Python 3.8
342+
343+
Read the Docs build using Python 3.8
344+
345+
Making warnings more visible
346+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
347+
348+
If you navigate to your HTML documentation,
349+
you will notice that the index page looks correct,
350+
but actually the API section is empty.
351+
This is a very common issue with Sphinx,
352+
and the reason is stated in the build logs.
353+
On the build page you opened before,
354+
click on the "View raw" text on the top right,
355+
which opens the build logs in plain text,
356+
and you will see several warnings:
357+
358+
.. code-block:: text
359+
360+
WARNING: [autosummary] failed to import 'lumache': no module named lumache
361+
...
362+
WARNING: autodoc: failed to import function 'get_random_ingredients' from module 'lumache'; the following exception was raised:
363+
No module named 'lumache'
364+
WARNING: autodoc: failed to import exception 'InvalidKindError' from module 'lumache'; the following exception was raised:
365+
No module named 'lumache'
366+
367+
To spot these warnings more easily and allow you to address them,
368+
you can add the ``sphinx.fail_on_warning`` option to your Read the Docs configuration file.
369+
For that, navigate to GitHub, locate the ``.readthedocs.yaml`` file you created earlier,
370+
click on the |:pencil2:| icon, and add these contents:
371+
372+
.. code-block:: yaml
373+
:caption: .readthedocs.yaml
374+
:emphasize-lines: 4-5
375+
376+
python:
377+
version: "3.8"
378+
379+
sphinx:
380+
fail_on_warning: true
381+
382+
At this point, if you navigate back to your "Builds" page,
383+
you will see a ``Failed`` build, which is exactly the intended result:
384+
the Sphinx project is not properly configured yet,
385+
and instead of rendering an empty API page, now the build fails.
386+
387+
The reason :py:mod:`sphinx:sphinx.ext.autosummary` and :py:mod:`sphinx:sphinx.ext.autodoc`
388+
fail to import the code is because it is not installed.
389+
Luckily, the ``.readthedocs.yaml`` also allows you to specify
390+
which requirements to install.
391+
392+
To install the library code of your project,
393+
go back to editing ``.readthedocs.yaml`` on GitHub and modify it as follows:
394+
395+
.. code-block:: yaml
396+
:caption: .readthedocs.yaml
397+
:emphasize-lines: 3-5
398+
399+
python:
400+
version: "3.9"
401+
# Install our python package before building the docs
402+
install:
403+
- method: pip
404+
path: .
405+
406+
With this change, Read the Docs will install the Python code
407+
before starting the Sphinx build, which will finish seamlessly.
408+
If you go now to the API page of your HTML documentation,
409+
you will see the ``lumache`` summary!
410+
411+
Enabling PDF and EPUB builds
412+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
413+
414+
Sphinx can build several other formats in addition to HTML, such as PDF and EPUB.
415+
You might want to enable these formats for your project
416+
so your users can read the documentation offline.
417+
418+
To do so, add this extra content to your ``.readthedocs.yaml``:
419+
420+
.. code-block:: yaml
421+
:caption: .readthedocs.yaml
422+
:emphasize-lines: 4-6
423+
424+
sphinx:
425+
fail_on_warning: true
426+
427+
formats:
428+
- pdf
429+
- epub
430+
431+
After this change, PDF and EPUB downloads will be available
432+
both from the "Downloads" section of the :term:`project home`,
433+
as well as the :term:`flyout menu`.
434+
435+
.. figure:: /_static/images/tutorial/flyout-downloads.png
436+
:align: center
437+
:alt: Downloads available from the flyout menu
438+
439+
Downloads available from the flyout menu
440+
441+
Versioning documentation
442+
------------------------
443+
444+
Read the Docs allows you to have :doc:`several versions of your documentation </versions>`,
445+
in the same way that you have several versions of your code.
446+
By default, it creates a ``latest`` version
447+
that points to the default branch of your version control system
448+
(``main`` in the case of this tutorial),
449+
and that's why the URLs of your HTML documentation contain the string ``/latest/``.
450+
451+
Creating a new version
452+
~~~~~~~~~~~~~~~~~~~~~~
453+
454+
Let's say you want to create a ``1.0`` version of your code,
455+
with a corresponding ``1.0`` version of the documentation.
456+
For that, first navigate to your GitHub repository, click on the branch selector,
457+
type ``1.0.x``, and click on "Create branch: 1.0.x from 'main'"
458+
(more information `on their documentation`__).
459+
460+
__ https://docs.github.com/en/github/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-and-deleting-branches-within-your-repository
461+
462+
Next, go to your :term:`project home`, click on the "Versions" button,
463+
and under "Active Versions" you will see two entries:
464+
465+
- The ``latest`` version, pointing to the ``main`` branch.
466+
- A new ``stable`` version, pointing to the ``origin/1.0.x`` branch.
467+
468+
.. figure:: /_static/images/tutorial/active-versions.png
469+
:width: 80%
470+
:align: center
471+
:alt: List of active versions of the project
472+
473+
List of active versions of the project
474+
475+
Right after you created your branch,
476+
Read the Docs created a new special version called ``stable`` pointing to it,
477+
and started building it. When the build finishes,
478+
the ``stable`` version will be listed in the :term:`flyout menu`
479+
and your readers will be able to choose it.
480+
481+
.. note::
482+
483+
Read the Docs :ref:`follows some rules <versions:how we envision versions working>`
484+
to decide whether to create a ``stable`` version pointing to your new branch or tag.
485+
To simplify, it will check if the name resembles a version number
486+
like ``1.0``, ``2.0.3`` or ``4.x``.
487+
488+
Now you might want to set ``stable`` as the *default version*,
489+
rather than ``latest``,
490+
so that users see the ``stable`` documentation
491+
when they visit the :term:`root URL` of your documentation
492+
(while still being able to change the version in the flyout menu).
493+
494+
For that, go to the "Advanced Settings" link under the "⚙ Admin" menu of your project home,
495+
choose ``stable`` in the "Default version*" dropdown,
496+
and hit :guilabel:`Save` at the bottom.
497+
Done!
498+
499+
Modifying versions
500+
~~~~~~~~~~~~~~~~~~
501+
502+
Both ``latest`` and ``stable`` are now *active*, which means that
503+
they are visible for users, and new builds can be triggered for them.
504+
In addition to these, Read the Docs also created an *inactive* ``1.0.x``
505+
version, which will always point to the ``1.0.x`` branch of your repository.
506+
507+
.. figure:: /_static/images/tutorial/inactive-versions.png
508+
:width: 80%
509+
:align: center
510+
:alt: List of inactive versions of the project
511+
512+
List of inactive versions of the project
513+
514+
Let's activate the ``1.0.x`` version.
515+
For that, go to the "Versions" on your :term:`project home`,
516+
locate ``1.0.x`` under "Activate a version",
517+
and click on the :guilabel:`Activate` button.
518+
This will take you to a new page with two checkboxes,
519+
"Active" and "Hidden". Check only "Active",
520+
and click :guilabel:`Save`.
521+
522+
After you do this, ``1.0.x`` will appear on the "Active Versions" section,
523+
and a new build will be triggered for it.
524+
525+
.. note::
526+
527+
You can read more about :ref:`hidden versions <versions:hidden>`
528+
in our documentation.
529+
530+
Show a warning for old versions
531+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
532+
533+
When your project matures, the number of versions might increase.
534+
Sometimes you will want to warn your readers
535+
when they are browsing an old or outdated version of your documentation.
536+
537+
To showcase how to do that, let's create a ``2.0`` version of the code:
538+
navigate to your GitHub repository, click on the branch selector,
539+
type ``2.0.x``, and click on "Create branch: 2.0.x from 'main'".
540+
This will trigger two things:
541+
542+
- Since ``2.0.x`` is your newest branch, ``stable`` will switch to tracking it.
543+
- A new ``2.0.x`` version will be created on your Read the Docs project.
544+
- Since you already have an active ``stable`` version, ``2.0.x`` will be activated.
545+
546+
From this point, ``1.0.x`` version is no longer the most up to date one.
547+
To display a warning to your readers, go to the "⚙ Admin" menu of your project home,
548+
click on the "Advanced Settings" link on the left,
549+
enable the "Show version warning" checkbox, and click the :guilabel:`Save` button.
550+
551+
If you now browse the ``1.0.x`` documentation, you will see a warning on top
552+
encouraging you to browse the latest version instead. Neat!
553+
554+
.. figure:: /_static/images/tutorial/old-version-warning.png
555+
:width: 80%
556+
:align: center
557+
:alt: Warning for old versions
558+
559+
Warning for old versions
560+
285561
----
286562

287563
That's the end of the tutorial,

docs/versions.rst

+3-4
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ On initial import,
66
we will create a ``latest`` version.
77
This will point at the default branch for your VCS control: ``master``, ``default``, or ``trunk``.
88

9-
We also create a ``stable`` version,
10-
if your project has any tagged releases.
11-
``stable`` will be automatically kept up to date to point at your highest version.
9+
If your project has any tags or branches with a name following `semantic versioning <https://semver.org/>`_,
10+
we also create a ``stable`` version, tracking your most recent release.
1211
If you want a custom ``stable`` version,
1312
create either a tag or branch in your project with that name.
1413

@@ -24,7 +23,7 @@ If you develop on a branch that is different than the default for your VCS,
2423
you should set the **Default Branch** to that branch.
2524

2625
You should push a **tag** for each version of your project.
27-
These tags should be numbered in a way that is consistent with `semantic versioning <https://semver.org/>`_.
26+
These tags should be numbered in a way that is consistent with semantic versioning.
2827
This will map to your ``stable`` branch by default.
2928

3029
.. note::

0 commit comments

Comments
 (0)