Skip to content

Docs: Configuration file how-to guide #10301

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

Merged
merged 33 commits into from
Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
1b3e201
WIP. Completed introduction and file location sections.
nikblanchet May 7, 2023
063ad2a
WIP. Converted note admonition to a section.
nikblanchet May 7, 2023
04ce49b
WIP. Began config file requirements.
nikblanchet May 7, 2023
70ac7e4
Apply suggestions from code review by @benjaoming and @agjohnson
benjaoming Jun 7, 2023
0ec9ef1
Merge branch 'main' of github.com:readthedocs/readthedocs.org into do…
benjaoming Jun 7, 2023
dae85dc
Make it build
benjaoming Jun 7, 2023
fcccd92
rtd's rst header coventions
benjaoming Jun 7, 2023
580fe2b
Header as how-to + shorten intro a bit more
benjaoming Jun 7, 2023
b1b9bb9
YAML: Reference Wikipedia
benjaoming Jun 7, 2023
ff26253
Use sphinx-copybutton
benjaoming Jun 7, 2023
1cc548a
Start managing use of example configuration files
benjaoming Jun 7, 2023
69e4fb6
Turn tip into seealso
benjaoming Jun 7, 2023
715fba5
Updates the how-to with more content editing, aligning more with a st…
benjaoming Jun 7, 2023
9145cfe
Fix a syntax err
benjaoming Jun 7, 2023
0c09e13
Add some more fluffy text to bind the flow together
benjaoming Jun 7, 2023
9818ac1
Remove redundant sentence
benjaoming Jun 7, 2023
fde407c
Further refinements to the step-by-step structure
benjaoming Jun 7, 2023
61a5322
Add Next Steps section
benjaoming Jun 7, 2023
0907b67
More step-by-step flow and copy editing
benjaoming Jun 8, 2023
0d51abb
Adds a tip (inspired by possible Configuration File howto UX)
benjaoming Jun 8, 2023
4098d85
More content for build.commands
benjaoming Jun 8, 2023
4eb0ba3
Apply suggestions from @agjohnson code review with some additional su…
benjaoming Jun 9, 2023
811f118
Trim the weird .readthedocs.yaml comment
benjaoming Jun 9, 2023
166549b
Refactor: Remove the "bare" echo example and use Docusaurus instead. …
benjaoming Jun 9, 2023
a9b7c53
Merge branch 'main' of github.com:readthedocs/readthedocs.org into do…
benjaoming Jun 9, 2023
8501d88
Fix some references
benjaoming Jun 9, 2023
a2de19b
Fix a crashed sentence
benjaoming Jun 9, 2023
92b1fc9
Eliminate seealso from Docusaurus section (an almost identical one is…
benjaoming Jun 9, 2023
7c3632c
Remove Docusaurus template
benjaoming Jun 9, 2023
2aecfbd
Remove section on adjusting for Docusaurus support
agjohnson Jun 9, 2023
46fa1af
Point to the YAML site and simplify copy on our YAML note
agjohnson Jun 9, 2023
18b209f
Change note on Ubuntu image and package versions
agjohnson Jun 9, 2023
01db977
Doc lint
agjohnson Jun 9, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"multiproject",
"myst_parser",
"notfound.extension",
"sphinx_copybutton",
"sphinx_design",
"sphinx_search.extension",
"sphinx_tabs.tabs",
Expand Down
2 changes: 2 additions & 0 deletions docs/user/build-customization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,8 @@ Take a look at the following example:
configuration: docs/conf.py


.. _build_commands_introduction:

Override the build process
--------------------------

Expand Down
8 changes: 8 additions & 0 deletions docs/user/config-file/examples/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
README

What is config-file/examples for?

To make maintenance easier, we are collecting all examples of configurations
used in documentation and on the website here.

Future potential scenarios for leveraging this structure aren't decided.
19 changes: 19 additions & 0 deletions docs/user/config-file/examples/mkdocs/.readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Read the Docs configuration file for MkDocs projects
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Set the version of Python and other tools you might need
build:
os: ubuntu-22.04
tools:
python: "3.11"

mkdocs:
configuration: mkdocs.yml

# Optionally declare the Python requirements required to build your docs
python:
install:
- requirements: docs/requirements.txt
31 changes: 31 additions & 0 deletions docs/user/config-file/examples/sphinx/.readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Read the Docs configuration file for Sphinx projects
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Set the OS, Python version and other tools you might need
build:
os: ubuntu-22.04
tools:
python: "3.11"
# You can also specify other tool versions:
# nodejs: "19"
# rust: "1.64"
# golang: "1.19"

# Build documentation in the "docs/" directory with Sphinx
sphinx:
configuration: docs/conf.py

# Optionally build your docs in additional formats such as PDF and ePub
# formats:
# - pdf
# - epub

# Optional but recommended, declare the Python requirements required
# to build your documentation
# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
# python:
# install:
# - requirements: docs/requirements.txt
60 changes: 8 additions & 52 deletions docs/user/config-file/v2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,62 +12,18 @@ Below is an example YAML file which shows the most common configuration options:

.. tab:: Sphinx

.. code:: yaml

# .readthedocs.yaml
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Set the version of Python and other tools you might need
build:
os: ubuntu-22.04
tools:
python: "3.11"
# You can also specify other tool versions:
# nodejs: "19"
# rust: "1.64"
# golang: "1.19"

# Build documentation in the docs/ directory with Sphinx
sphinx:
configuration: docs/conf.py

# If using Sphinx, optionally build your docs in additional formats such as PDF
# formats:
# - pdf

# Optionally declare the Python requirements required to build your docs
python:
install:
- requirements: docs/requirements.txt
.. literalinclude:: /config-file/examples/sphinx/.readthedocs.yaml
:language: yaml
:linenos:
:caption: .readthedocs.yaml

.. tab:: MkDocs

.. code:: yaml
.. literalinclude:: /config-file/examples/mkdocs/.readthedocs.yaml
:language: yaml
:linenos:
:caption: .readthedocs.yaml

# .readthedocs.yaml
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Set the version of Python and other tools you might need
build:
os: ubuntu-22.04
tools:
python: "3.11"

mkdocs:
configuration: mkdocs.yml

# Optionally declare the Python requirements required to build your docs
python:
install:
- requirements: docs/requirements.txt

Supported settings
------------------
Expand Down
5 changes: 5 additions & 0 deletions docs/user/guides/pull-requests.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ If your account is already connected:
#. Enable the :guilabel:`Build pull requests for this project` option
#. Click on :guilabel:`Save`

.. tip::

Pull requests opened before enabling pull request builds will not trigger new builds automatically.
Push a new commit to the pull request to trigger its first build.

Privacy levels
--------------

Expand Down
183 changes: 183 additions & 0 deletions docs/user/guides/setup/configuration-file.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
How to add a configuration file
===============================

As part of the initial set up for your Read the Docs site,
you need to create a **configuration file** called ``.readthedocs.yaml``.
The configuration file tells Read the Docs what specific settings to use for your project.

This how-to guide covers:

#. Where to put your configuration file.
#. What to put in the configuration file.
#. How to customize the configuration for your project.

.. seealso::

:doc:`/tutorial/index`.
Following the steps in our tutorial will help you setup your first documentation project.


Where to put your configuration file
------------------------------------

The ``.readthedocs.yaml`` file should be placed in the top-most directory of your project's repository.
We will get to the contents of the file in the next steps.

When you have changed the configuration file,
you need to commit and push the changes to your Git repository.
Read the Docs will then automatically find and use the configuration to build your project.

.. note::

The Read the Docs configuration file is a `YAML`_ file.
YAML is a human-friendly data serialization language for all programming languages.
To learn more about the structure of these files, see the `YAML language overview`_.

.. _YAML: https://yaml.org/
.. _YAML language overview: https://yaml.org/spec/1.2.2/#chapter-1-introduction-to-yaml

.. _howto_templates:

Getting started with a template
-------------------------------

Here are some configuration file examples to help you get started.
Pick an example based on the tool that your project is using,
copy its contents to ``.readthedocs.yaml`` and add the file to your Git repository.

.. tabs::

.. tab:: Sphinx

If your project uses Sphinx,
we offer a special builder optimized for Sphinx projects.

.. literalinclude:: /config-file/examples/sphinx/.readthedocs.yaml
:language: yaml
:linenos:
:caption: .readthedocs.yaml


.. tab:: MkDocs

If your project uses MkDocs,
we offer a special builder optimized for MkDocs projects.

.. literalinclude:: /config-file/examples/mkdocs/.readthedocs.yaml
:language: yaml
:linenos:
:caption: .readthedocs.yaml

Editing the template
--------------------

Now that you have a ``.readthedocs.yaml`` file added to your Git repository,
you should see Read the Docs trying to build your project with the configuration file.
The configuration file probably needs some adjustments to accommodate exactly your project setup.

.. note::

If you added the configuration file in a separate branch,
you may have to activate a :doc:`version </versions>` for that branch.

If you have added the file in a pull request,
you should enable :doc:`pull request builds </guides/pull-requests>`.

Skip: file header and comments
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

There are some parts of the templates that you can leave in place:

Comments
We added comments that explain the configuration options and optional features.
These lines begin with a ``#``.

Commented out features
We use the ``#`` in front of some popular configuration options.
They are there as examples,
which you can choose to enable, delete or save for later.

``version`` key
The version key tells the system how to read the rest of the configuration file.
The current and only supported version is **version 2**.


Adjust: ``build.os``
~~~~~~~~~~~~~~~~~~~~

In our examples,
we are using Read the Docs' custom image based on the latest Ubuntu release.
Package versions in these images will not change drastically,
though will receive periodic security updates.

You should pay attention to this field if your project needs to build on an older version of Ubuntu,
or in the future when you need features from a newer Ubuntu.

.. seealso::

:ref:`config-file/v2:build.os`
Configuration file reference with all values possible for ``build.os``.


Adjust: Python configuration
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

If you are using Python in your builds,
you should define the Python version in ``build.tools.python``.

The ``python`` key contains a list of sub-keys,
specifying the requirements to install.

- Use ``python.install.package`` to install the project itself as a Python package using pip
- Use ``python.install.requirements`` to install packages from a requirements file
- Use ``build.jobs`` to install packages using Poetry or PDM

.. seealso::

:ref:`config-file/v2:build.tools.python`
Configuration file reference with all Python versions available for ``build.tools.python``.

:ref:`config-file/v2:python`
Configuration file reference for configuring the Python environment activated by ``build.tools.python``.

Adjust: Sphinx and MkDocs version
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

If you are using either the ``sphinx`` or ``mkdocs`` builder,
then Sphinx or MkDocs will be installed automatically in its latest version.

But we recommend that you specify the version that your documentation project uses.
The ``requirements`` key is a file path that points to a text (``.txt``) file
that lists the Python packages you want Read the Docs to install.

.. seealso::

:ref:`guides/reproducible-builds:Use a requirements file for Python dependencies`
This guide explains how to specify Python requirements,
such as the version of Sphinx or MkDocs.

:ref:`config-file/v2:sphinx`
Configuration file reference for configuring the Sphinx builder.

:ref:`config-file/v2:mkdocs`
Configuration file reference for configuring the MkDocs builder.

Next steps
----------

There are more configuration options that the ones mentioned in this guide.

After you add a configuration file your Git repository,
and you can see that Read the Docs is building your documentation using the file,
you should have a look at the complete configuration file reference for options that might apply to your project.

.. seealso::

:doc:`/config-file/v2`.
The complete list of all possible ``.readthedocs.yaml`` settings,
including the optional settings not covered in on this page.

:doc:`/build-customization`
Are familiar with running a command line?
Perhaps there are special commands that you know you want Read the Docs to run.
Read this guide and learn more about how you add your own commands to ``.readthedocs.yaml``.
6 changes: 6 additions & 0 deletions docs/user/guides/setup/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ The following how-to guides help you solve common tasks and challenges in the se
If you are connecting a Git repository from another provider (for instance Gitea or Codeberg),
this guide tells you how to add and configure the webhook **manually**.

⏩ :doc:`Adding a configuration file </guides/setup/configuration-file>`
To build your documentation project,
you need to add a ``.readthedocs.yaml`` configuration file.
This guide gets you started.

⏩️ :doc:`Managing custom domains </guides/custom-domains>`
Hosting your documentation using your own domain name, such as ``docs.example.com``.

Expand Down Expand Up @@ -45,6 +50,7 @@ The following how-to guides help you solve common tasks and challenges in the se
Connecting your Read the Docs account to your Git provider </guides/connecting-git-account>
Configuring a Git repository automatically </guides/setup/git-repo-automatic>
Configuring a Git repository manually </guides/setup/git-repo-manual>
Adding a configuration file </guides/setup/configuration-file>
Managing custom domains </guides/custom-domains>
Managing subprojects </guides/subprojects>
Hiding a version </guides/hiding-a-version>
Expand Down
1 change: 1 addition & 0 deletions requirements/docs.in
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ sphinxcontrib-httpdomain
sphinx-prompt
sphinx-autobuild
sphinxext-opengraph
sphinx-copybutton

# Markdown
myst_parser
Expand Down
3 changes: 3 additions & 0 deletions requirements/docs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ sphinx==6.2.1
# -r requirements/docs.in
# myst-parser
# sphinx-autobuild
# sphinx-copybutton
# sphinx-design
# sphinx-hoverxref
# sphinx-intl
Expand All @@ -109,6 +110,8 @@ sphinx==6.2.1
# sphinxext-opengraph
sphinx-autobuild==2021.3.14
# via -r requirements/docs.in
sphinx-copybutton==0.5.2
# via -r requirements/docs.in
sphinx-design==0.4.1
# via -r requirements/docs.in
sphinx-hoverxref==1.3.0
Expand Down