-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New Read the Docs tutorial, part II #8473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
79d505d
574f52f
3a03637
962af6d
77dbb1b
b54997b
d6b1e31
02ee249
49edd01
e9a28e5
e77c24a
0793e21
430da00
1751069
3a09fd3
e361ab9
1635106
1c242a3
8c379b4
8a1cca9
8aedaba
0f751cc
d04e09e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -259,7 +259,10 @@ __ https://docs.github.com/en/github/managing-files-in-a-repository/managing-fi | |
|
||
In the editor, add the following sentence to the file: | ||
|
||
Lumache has its documentation hosted on Read the Docs. | ||
.. code-block:: rst | ||
:caption: docs/source/index.rst | ||
|
||
Lumache has its documentation hosted on Read the Docs. | ||
|
||
Write an appropriate commit message, | ||
and choose the "Create a **new branch** for this commit and start a pull request" option, | ||
|
@@ -282,6 +285,159 @@ you will access the build logs, | |
otherwise it will take you directly to the documentation. | ||
When you are satisfied, you can merge the pull request! | ||
|
||
Customizing the build process | ||
----------------------------- | ||
|
||
The Settings page of the :term:`project home` allows you | ||
to change some *global* configuration values of your project. | ||
In addition, you can further customize the building process | ||
using the ``.readthedocs.yaml`` :doc:`configuration file </config-file/v2>`. | ||
This has two advantages: | ||
|
||
- The configuration lives next to your code and documentation, tracked by version control. | ||
- It can be different for every version (more on versioning in the next section). | ||
astrojuanlu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Read the Docs works without this configuration by making some decisions on your behalf. | ||
For example, what Python version to use, how to install the requirements, and others. | ||
astrojuanlu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
astrojuanlu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Upgrading the Python version | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
For example, to explicitly use Python 3.9 to build your project, | ||
navigate to your GitHub repository, click on the :guilabel:`Add file` button, | ||
and add a ``.readthedocs.yaml`` file with these contents to the root of your project: | ||
astrojuanlu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
.. code-block:: yaml | ||
:caption: .readthedocs.yaml | ||
|
||
version: 2 | ||
|
||
build: | ||
image: testing | ||
|
||
python: | ||
version: "3.9" | ||
|
||
The purpose of each key is: | ||
|
||
``version`` | ||
Mandatory, specifies :doc:`version 2 of the configuration file </config-file/v2>`. | ||
|
||
``build.image`` | ||
Specifies a newer :ref:`Docker image <builds:Docker images>`, | ||
needed to use more recent versions of Python. | ||
astrojuanlu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
``python.version`` | ||
Declares the Python version to be used. | ||
|
||
After you commit these changes, go back to your project home, | ||
navigate to the "Builds" page, and open the new build that just started. | ||
You will notice that one of the lines contains ``python3.9``: | ||
if you click on it, you will see the full output of the corresponding command, | ||
stating that it used ``CPython3.9.1`` to create the virtual environment. | ||
|
||
.. figure:: /_static/images/tutorial/build-python3.9.png | ||
:width: 80% | ||
:align: center | ||
:alt: Read the Docs build using Python 3.9 | ||
|
||
Read the Docs build using Python 3.9 | ||
|
||
Making warnings more visible | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
If you navigate to your HTML documentation, | ||
you will notice that the index page looks correct, | ||
but actually the API section is empty. | ||
This is a very common annoyance with Sphinx, | ||
astrojuanlu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
and the reason is stated in the build logs. | ||
On the build page you opened before, | ||
click on the "View raw" text on the top right, | ||
which opens the build logs in plain text, | ||
and you will see several warnings: | ||
|
||
.. code-block:: text | ||
|
||
WARNING: [autosummary] failed to import 'lumache': no module named lumache | ||
... | ||
WARNING: autodoc: failed to import function 'get_random_ingredients' from module 'lumache'; the following exception was raised: | ||
No module named 'lumache' | ||
WARNING: autodoc: failed to import exception 'InvalidKindError' from module 'lumache'; the following exception was raised: | ||
No module named 'lumache' | ||
|
||
To spot these warnings more easily and allow you to address them or selectively ignore them, | ||
astrojuanlu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
you can add the ``sphinx.fail_on_warning`` to your Read the Docs configuration file. | ||
astrojuanlu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
For that, navigate to GitHub, locate the ``.readthedocs.yaml`` file you created earlier, | ||
click on the |:pencil2:| icon, and add these contents: | ||
|
||
.. code-block:: yaml | ||
:caption: .readthedocs.yaml | ||
:emphasize-lines: 4-5 | ||
|
||
python: | ||
version: "3.9" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Think we should put the whole content or just the new content to avoid confusions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be a bit tedious to put all the content, and putting a fragment gives some context
astrojuanlu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
sphinx: | ||
fail_on_warning: true | ||
|
||
At this point, if you navigate back to your "Builds" page, | ||
you will see a `Failed` build, which is exactly the intended result: | ||
astrojuanlu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
the Sphinx project is not properly configured yet, | ||
and instead of rendering an empty API page, now the build fails. | ||
|
||
The reason :py:mod:`sphinx:sphinx.ext.autosummary` and :py:mod:`sphinx:sphinx.ext.autodoc` | ||
stsewd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
fail to import the code is because it is not installed. | ||
Luckily, the ``.readthedocs.yaml`` also allows you to specify | ||
which requirements to install. | ||
|
||
To install the library code of your project, | ||
go back to editing ``.readthedocs.yaml`` on GitHub and modify it as follows: | ||
|
||
.. code-block:: yaml | ||
:caption: .readthedocs.yaml | ||
:emphasize-lines: 3-5 | ||
|
||
python: | ||
version: "3.9" | ||
install: | ||
astrojuanlu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- method: pip | ||
path: . | ||
|
||
With this change, Read the Docs will install the Python code in the virtual environment | ||
astrojuanlu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
before starting the Sphinx build, which will finish seamlessly. | ||
If you go now to the API page of your HTML documentation, | ||
you will see the ``lumache`` summary! | ||
|
||
Enabling PDF and EPUB builds | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
Sphinx can build several other formats in addition to HTML, such as PDF and EPUB. | ||
You might want to enable this formats for your project | ||
astrojuanlu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
so your users can read the documentation offline. | ||
|
||
To do so, add this extra content to your ``.readthedocs.yaml``: | ||
|
||
.. code-block:: yaml | ||
:caption: .readthedocs.yaml | ||
:emphasize-lines: 4-6 | ||
|
||
sphinx: | ||
fail_on_warning: true | ||
|
||
formats: | ||
- epub | ||
|
||
After this change, PDF and EPUB downloads will be available | ||
both from the "Downloads" section of the :term:`project home`, | ||
as well as the :term:`flyout menu`. | ||
|
||
.. figure:: /_static/images/tutorial/flyout-downloads.png | ||
:align: center | ||
:alt: Downloads available from the flyout menu | ||
|
||
Downloads available from the flyout menu | ||
|
||
---- | ||
|
||
That's the end of the tutorial, | ||
|
Uh oh!
There was an error while loading. Please reload this page.