Skip to content

Commit ac72647

Browse files
nikblanchetbenjaomingagjohnson
authored
Docs: Configuration file how-to guide (#10301)
* WIP. Completed introduction and file location sections. * WIP. Converted note admonition to a section. * WIP. Began config file requirements. Pausing so Manuel can create a bulleted list explaining what the requirements actually are. * Apply suggestions from code review by @benjaoming and @agjohnson Co-authored-by: Anthony <[email protected]> * Make it build * rtd's rst header coventions * Header as how-to + shorten intro a bit more * YAML: Reference Wikipedia * Use sphinx-copybutton * Start managing use of example configuration files * Turn tip into seealso * Updates the how-to with more content editing, aligning more with a step-by-step guide * Fix a syntax err * Add some more fluffy text to bind the flow together * Remove redundant sentence * Further refinements to the step-by-step structure * Add Next Steps section * More step-by-step flow and copy editing * Adds a tip (inspired by possible Configuration File howto UX) * More content for build.commands * Apply suggestions from @agjohnson code review with some additional suggestions from @benjaoming Co-authored-by: Anthony <[email protected]> * Trim the weird .readthedocs.yaml comment * Refactor: Remove the "bare" echo example and use Docusaurus instead. Remove section about custom commands and instead have it hidden in a tab * Fix some references * Fix a crashed sentence * Eliminate seealso from Docusaurus section (an almost identical one is in Next Steps) * Remove Docusaurus template * Remove section on adjusting for Docusaurus support * Point to the YAML site and simplify copy on our YAML note * Change note on Ubuntu image and package versions * Doc lint --------- Co-authored-by: Nik Blanchet <[email protected]> Co-authored-by: Benjamin Balder Bach <[email protected]> Co-authored-by: Anthony <[email protected]> Co-authored-by: Benjamin Bach <[email protected]>
1 parent e32efc0 commit ac72647

File tree

11 files changed

+267
-52
lines changed

11 files changed

+267
-52
lines changed

docs/conf.py

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"multiproject",
2323
"myst_parser",
2424
"notfound.extension",
25+
"sphinx_copybutton",
2526
"sphinx_design",
2627
"sphinx_search.extension",
2728
"sphinx_tabs.tabs",

docs/user/build-customization.rst

+2
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,8 @@ Take a look at the following example:
339339
configuration: docs/conf.py
340340
341341
342+
.. _build_commands_introduction:
343+
342344
Override the build process
343345
--------------------------
344346

docs/user/config-file/examples/README

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
README
2+
3+
What is config-file/examples for?
4+
5+
To make maintenance easier, we are collecting all examples of configurations
6+
used in documentation and on the website here.
7+
8+
Future potential scenarios for leveraging this structure aren't decided.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Read the Docs configuration file for MkDocs projects
2+
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
3+
4+
# Required
5+
version: 2
6+
7+
# Set the version of Python and other tools you might need
8+
build:
9+
os: ubuntu-22.04
10+
tools:
11+
python: "3.11"
12+
13+
mkdocs:
14+
configuration: mkdocs.yml
15+
16+
# Optionally declare the Python requirements required to build your docs
17+
python:
18+
install:
19+
- requirements: docs/requirements.txt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Read the Docs configuration file for Sphinx projects
2+
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
3+
4+
# Required
5+
version: 2
6+
7+
# Set the OS, Python version and other tools you might need
8+
build:
9+
os: ubuntu-22.04
10+
tools:
11+
python: "3.11"
12+
# You can also specify other tool versions:
13+
# nodejs: "19"
14+
# rust: "1.64"
15+
# golang: "1.19"
16+
17+
# Build documentation in the "docs/" directory with Sphinx
18+
sphinx:
19+
configuration: docs/conf.py
20+
21+
# Optionally build your docs in additional formats such as PDF and ePub
22+
# formats:
23+
# - pdf
24+
# - epub
25+
26+
# Optional but recommended, declare the Python requirements required
27+
# to build your documentation
28+
# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
29+
# python:
30+
# install:
31+
# - requirements: docs/requirements.txt

docs/user/config-file/v2.rst

+8-52
Original file line numberDiff line numberDiff line change
@@ -12,62 +12,18 @@ Below is an example YAML file which shows the most common configuration options:
1212

1313
.. tab:: Sphinx
1414

15-
.. code:: yaml
16-
17-
# .readthedocs.yaml
18-
# Read the Docs configuration file
19-
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
20-
21-
# Required
22-
version: 2
23-
24-
# Set the version of Python and other tools you might need
25-
build:
26-
os: ubuntu-22.04
27-
tools:
28-
python: "3.11"
29-
# You can also specify other tool versions:
30-
# nodejs: "19"
31-
# rust: "1.64"
32-
# golang: "1.19"
33-
34-
# Build documentation in the docs/ directory with Sphinx
35-
sphinx:
36-
configuration: docs/conf.py
37-
38-
# If using Sphinx, optionally build your docs in additional formats such as PDF
39-
# formats:
40-
# - pdf
41-
42-
# Optionally declare the Python requirements required to build your docs
43-
python:
44-
install:
45-
- requirements: docs/requirements.txt
15+
.. literalinclude:: /config-file/examples/sphinx/.readthedocs.yaml
16+
:language: yaml
17+
:linenos:
18+
:caption: .readthedocs.yaml
4619

4720
.. tab:: MkDocs
4821

49-
.. code:: yaml
22+
.. literalinclude:: /config-file/examples/mkdocs/.readthedocs.yaml
23+
:language: yaml
24+
:linenos:
25+
:caption: .readthedocs.yaml
5026

51-
# .readthedocs.yaml
52-
# Read the Docs configuration file
53-
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
54-
55-
# Required
56-
version: 2
57-
58-
# Set the version of Python and other tools you might need
59-
build:
60-
os: ubuntu-22.04
61-
tools:
62-
python: "3.11"
63-
64-
mkdocs:
65-
configuration: mkdocs.yml
66-
67-
# Optionally declare the Python requirements required to build your docs
68-
python:
69-
install:
70-
- requirements: docs/requirements.txt
7127

7228
Supported settings
7329
------------------

docs/user/guides/pull-requests.rst

+5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ If your account is already connected:
1414
#. Enable the :guilabel:`Build pull requests for this project` option
1515
#. Click on :guilabel:`Save`
1616

17+
.. tip::
18+
19+
Pull requests opened before enabling pull request builds will not trigger new builds automatically.
20+
Push a new commit to the pull request to trigger its first build.
21+
1722
Privacy levels
1823
--------------
1924

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
How to add a configuration file
2+
===============================
3+
4+
As part of the initial set up for your Read the Docs site,
5+
you need to create a **configuration file** called ``.readthedocs.yaml``.
6+
The configuration file tells Read the Docs what specific settings to use for your project.
7+
8+
This how-to guide covers:
9+
10+
#. Where to put your configuration file.
11+
#. What to put in the configuration file.
12+
#. How to customize the configuration for your project.
13+
14+
.. seealso::
15+
16+
:doc:`/tutorial/index`.
17+
Following the steps in our tutorial will help you setup your first documentation project.
18+
19+
20+
Where to put your configuration file
21+
------------------------------------
22+
23+
The ``.readthedocs.yaml`` file should be placed in the top-most directory of your project's repository.
24+
We will get to the contents of the file in the next steps.
25+
26+
When you have changed the configuration file,
27+
you need to commit and push the changes to your Git repository.
28+
Read the Docs will then automatically find and use the configuration to build your project.
29+
30+
.. note::
31+
32+
The Read the Docs configuration file is a `YAML`_ file.
33+
YAML is a human-friendly data serialization language for all programming languages.
34+
To learn more about the structure of these files, see the `YAML language overview`_.
35+
36+
.. _YAML: https://yaml.org/
37+
.. _YAML language overview: https://yaml.org/spec/1.2.2/#chapter-1-introduction-to-yaml
38+
39+
.. _howto_templates:
40+
41+
Getting started with a template
42+
-------------------------------
43+
44+
Here are some configuration file examples to help you get started.
45+
Pick an example based on the tool that your project is using,
46+
copy its contents to ``.readthedocs.yaml`` and add the file to your Git repository.
47+
48+
.. tabs::
49+
50+
.. tab:: Sphinx
51+
52+
If your project uses Sphinx,
53+
we offer a special builder optimized for Sphinx projects.
54+
55+
.. literalinclude:: /config-file/examples/sphinx/.readthedocs.yaml
56+
:language: yaml
57+
:linenos:
58+
:caption: .readthedocs.yaml
59+
60+
61+
.. tab:: MkDocs
62+
63+
If your project uses MkDocs,
64+
we offer a special builder optimized for MkDocs projects.
65+
66+
.. literalinclude:: /config-file/examples/mkdocs/.readthedocs.yaml
67+
:language: yaml
68+
:linenos:
69+
:caption: .readthedocs.yaml
70+
71+
Editing the template
72+
--------------------
73+
74+
Now that you have a ``.readthedocs.yaml`` file added to your Git repository,
75+
you should see Read the Docs trying to build your project with the configuration file.
76+
The configuration file probably needs some adjustments to accommodate exactly your project setup.
77+
78+
.. note::
79+
80+
If you added the configuration file in a separate branch,
81+
you may have to activate a :doc:`version </versions>` for that branch.
82+
83+
If you have added the file in a pull request,
84+
you should enable :doc:`pull request builds </guides/pull-requests>`.
85+
86+
Skip: file header and comments
87+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
88+
89+
There are some parts of the templates that you can leave in place:
90+
91+
Comments
92+
We added comments that explain the configuration options and optional features.
93+
These lines begin with a ``#``.
94+
95+
Commented out features
96+
We use the ``#`` in front of some popular configuration options.
97+
They are there as examples,
98+
which you can choose to enable, delete or save for later.
99+
100+
``version`` key
101+
The version key tells the system how to read the rest of the configuration file.
102+
The current and only supported version is **version 2**.
103+
104+
105+
Adjust: ``build.os``
106+
~~~~~~~~~~~~~~~~~~~~
107+
108+
In our examples,
109+
we are using Read the Docs' custom image based on the latest Ubuntu release.
110+
Package versions in these images will not change drastically,
111+
though will receive periodic security updates.
112+
113+
You should pay attention to this field if your project needs to build on an older version of Ubuntu,
114+
or in the future when you need features from a newer Ubuntu.
115+
116+
.. seealso::
117+
118+
:ref:`config-file/v2:build.os`
119+
Configuration file reference with all values possible for ``build.os``.
120+
121+
122+
Adjust: Python configuration
123+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
124+
125+
If you are using Python in your builds,
126+
you should define the Python version in ``build.tools.python``.
127+
128+
The ``python`` key contains a list of sub-keys,
129+
specifying the requirements to install.
130+
131+
- Use ``python.install.package`` to install the project itself as a Python package using pip
132+
- Use ``python.install.requirements`` to install packages from a requirements file
133+
- Use ``build.jobs`` to install packages using Poetry or PDM
134+
135+
.. seealso::
136+
137+
:ref:`config-file/v2:build.tools.python`
138+
Configuration file reference with all Python versions available for ``build.tools.python``.
139+
140+
:ref:`config-file/v2:python`
141+
Configuration file reference for configuring the Python environment activated by ``build.tools.python``.
142+
143+
Adjust: Sphinx and MkDocs version
144+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
145+
146+
If you are using either the ``sphinx`` or ``mkdocs`` builder,
147+
then Sphinx or MkDocs will be installed automatically in its latest version.
148+
149+
But we recommend that you specify the version that your documentation project uses.
150+
The ``requirements`` key is a file path that points to a text (``.txt``) file
151+
that lists the Python packages you want Read the Docs to install.
152+
153+
.. seealso::
154+
155+
:ref:`guides/reproducible-builds:Use a requirements file for Python dependencies`
156+
This guide explains how to specify Python requirements,
157+
such as the version of Sphinx or MkDocs.
158+
159+
:ref:`config-file/v2:sphinx`
160+
Configuration file reference for configuring the Sphinx builder.
161+
162+
:ref:`config-file/v2:mkdocs`
163+
Configuration file reference for configuring the MkDocs builder.
164+
165+
Next steps
166+
----------
167+
168+
There are more configuration options that the ones mentioned in this guide.
169+
170+
After you add a configuration file your Git repository,
171+
and you can see that Read the Docs is building your documentation using the file,
172+
you should have a look at the complete configuration file reference for options that might apply to your project.
173+
174+
.. seealso::
175+
176+
:doc:`/config-file/v2`.
177+
The complete list of all possible ``.readthedocs.yaml`` settings,
178+
including the optional settings not covered in on this page.
179+
180+
:doc:`/build-customization`
181+
Are familiar with running a command line?
182+
Perhaps there are special commands that you know you want Read the Docs to run.
183+
Read this guide and learn more about how you add your own commands to ``.readthedocs.yaml``.

docs/user/guides/setup/index.rst

+6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ The following how-to guides help you solve common tasks and challenges in the se
1414
If you are connecting a Git repository from another provider (for instance Gitea or Codeberg),
1515
this guide tells you how to add and configure the webhook **manually**.
1616

17+
:doc:`Adding a configuration file </guides/setup/configuration-file>`
18+
To build your documentation project,
19+
you need to add a ``.readthedocs.yaml`` configuration file.
20+
This guide gets you started.
21+
1722
⏩️ :doc:`Managing custom domains </guides/custom-domains>`
1823
Hosting your documentation using your own domain name, such as ``docs.example.com``.
1924

@@ -45,6 +50,7 @@ The following how-to guides help you solve common tasks and challenges in the se
4550
Connecting your Read the Docs account to your Git provider </guides/connecting-git-account>
4651
Configuring a Git repository automatically </guides/setup/git-repo-automatic>
4752
Configuring a Git repository manually </guides/setup/git-repo-manual>
53+
Adding a configuration file </guides/setup/configuration-file>
4854
Managing custom domains </guides/custom-domains>
4955
Managing subprojects </guides/subprojects>
5056
Hiding a version </guides/hiding-a-version>

requirements/docs.in

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ sphinxcontrib-httpdomain
1818
sphinx-prompt
1919
sphinx-autobuild
2020
sphinxext-opengraph
21+
sphinx-copybutton
2122

2223
# Markdown
2324
myst_parser

requirements/docs.txt

+3
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ sphinx==6.2.1
9696
# -r requirements/docs.in
9797
# myst-parser
9898
# sphinx-autobuild
99+
# sphinx-copybutton
99100
# sphinx-design
100101
# sphinx-hoverxref
101102
# sphinx-intl
@@ -109,6 +110,8 @@ sphinx==6.2.1
109110
# sphinxext-opengraph
110111
sphinx-autobuild==2021.3.14
111112
# via -r requirements/docs.in
113+
sphinx-copybutton==0.5.2
114+
# via -r requirements/docs.in
112115
sphinx-design==0.4.1
113116
# via -r requirements/docs.in
114117
sphinx-hoverxref==1.3.0

0 commit comments

Comments
 (0)