Skip to content

Commit 9af02e6

Browse files
stsewdericholscher
andauthored
Docs: guide about reproducible builds (#7888)
Close #7852 Co-authored-by: Eric Holscher <[email protected]>
1 parent d1fda37 commit 9af02e6

10 files changed

+188
-64
lines changed

docs/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ clean:
5353
rm -rf $(BUILDDIR)/*
5454

5555
auto:
56-
sphinx-autobuild -p 8888 $(ALLSPHINXOPTS) $(BUILDDIR)/html
56+
sphinx-autobuild --port 8888 $(ALLSPHINXOPTS) $(BUILDDIR)/html
5757
@echo
5858
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
5959

docs/builds.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ An example in code:
6767
.. note::
6868

6969
Regardless of whether you build your docs with Sphinx or MkDocs,
70-
we recommend you pin the version of Sphinx or Mkdocs you want us to use.
71-
You can do this the same way other
72-
:doc:`dependencies are specified <guides/specifying-dependencies>`.
70+
we recommend you :ref:`pinning the version <guides/reproducible-builds:pinning dependencies>` of Sphinx or Mkdocs you want us to use.
7371
Some examples of pinning versions might be ``sphinx<2.0`` or ``mkdocs>=1.0``.
7472

7573
Build environment

docs/faq.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ My documentation requires additional dependencies
3333
-------------------------------------------------
3434

3535
For most Python dependencies, you can can specify a requirements file
36-
which details your dependencies. See our guide on :doc:`/guides/specifying-dependencies`.
36+
which details your dependencies. See our guide on :ref:`guides/reproducible-builds:using a configuration file`.
3737
You can also set your project documentation to install your project itself
3838
as a dependency.
3939

@@ -216,8 +216,7 @@ and as a result, it tends to look a bit better with the default theme.
216216
.. note::
217217

218218
To use these extensions you need to specify the dependencies on your project
219-
by following this :doc:`guide <guides/specifying-dependencies>`.
220-
219+
by following this :ref:`guide <guides/reproducible-builds:using a configuration file>`.
221220

222221
Can I document a python package that is not at the root of my repository?
223222
-------------------------------------------------------------------------

docs/guides/mkdocs-old-versions.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ To make your project continue using this version you will need to create a ``req
2929
markdown>=2.3.1,<2.5
3030

3131

32-
More detailed information about how to specify dependencies can be found :ref:`here <guides/specifying-dependencies:Specifying Dependencies>`.
33-
32+
More detailed information about how to specify dependencies can be found :ref:`here <guides/reproducible-builds:pinning dependencies>`.
3433

3534
Upgrade your custom theme to be compatible with later MkDocs versions
3635
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

docs/guides/platform.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ These guides will help you customize or tune aspects of Read the Docs.
1111
canonical
1212
conda
1313
deprecating-content
14+
embedding-content
1415
environment-variables
1516
feature-flags
1617
google-analytics
1718
hiding-a-version
19+
reproducible-builds
1820
searching-with-readthedocs
19-
embedding-content
20-
specifying-dependencies
2121
technical-docs-seo-guide
2222
wipe-environment

docs/guides/reproducible-builds.rst

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
Reproducible Builds
2+
===================
3+
4+
Your docs depend on tools and other dependencies to be built.
5+
If your docs don't have reproducible builds,
6+
an update in a dependency can break your builds when least expected,
7+
or make your docs look different from your local version.
8+
This guide will help you to keep your builds working over time, and in a reproducible way.
9+
10+
.. contents:: Contents
11+
:local:
12+
:depth: 3
13+
14+
Building your docs
15+
------------------
16+
17+
To test your build process, you can build them locally in a clean environment
18+
(this is without any dependencies installed).
19+
Then you should make sure you are running those same steps on Read the Docs.
20+
21+
You can configure how your project is built from the web interface (:guilabel:`Admin` tab),
22+
or by :ref:`using a configuration file <guides/reproducible-builds:using a configuration file>` (recommended).
23+
If you aren't familiar with these tools, check our docs:
24+
25+
- :doc:`/intro/getting-started-with-sphinx`
26+
- :doc:`/intro/getting-started-with-mkdocs`
27+
- :doc:`/config-file/v2`
28+
29+
.. note::
30+
31+
You can see the exact commands that are run on Read the Docs by going to the :guilabel:`Builds` tab of your project.
32+
33+
Using a configuration file
34+
--------------------------
35+
36+
If you use the web interface to configure your project,
37+
the options are applied to *all* versions and builds of your docs,
38+
and can be lost after changing them over time.
39+
Using a :doc:`configuration file </config-file/v2>` **provides you per version settings**,
40+
and **those settings live in your repository**.
41+
42+
A configuration file with explicit dependencies looks like this:
43+
44+
.. code-block:: yaml
45+
46+
# File: .readthedocs.yaml
47+
48+
version: 2
49+
50+
# Build from the docs/ directory with Sphinx
51+
sphinx:
52+
configuration: docs/conf.py
53+
54+
# Explicitly set the version of Python and its requirements
55+
python:
56+
version: 3.7
57+
install:
58+
- requirements: docs/requirements.txt
59+
60+
.. code-block::
61+
62+
# File: docs/requirements.txt
63+
64+
# Defining the exact version will make sure things don't break
65+
sphinx==3.4.3
66+
sphinx_rtd_theme==0.5.1
67+
readthedocs-sphinx-search==0.1.0
68+
69+
Don't rely on implicit dependencies
70+
-----------------------------------
71+
72+
By default Read the Docs will install the tool you chose to build your docs,
73+
and other dependencies, this is done so new users can build their docs without much configuration.
74+
75+
We highly recommend not to assume these dependencies will always be present or that their versions won't change.
76+
Always declare your dependencies explicitly using a :ref:`configuration file <guides/reproducible-builds:using a configuration file>`,
77+
for example:
78+
79+
✅ Good:
80+
Your project is declaring the Python version explicitly,
81+
and its dependencies using a requirements file.
82+
83+
.. code-block:: yaml
84+
85+
# File: .readthedocs.yaml
86+
87+
version: 2
88+
89+
sphinx:
90+
configuration: docs/conf.py
91+
92+
python:
93+
version: 3.7
94+
install:
95+
- requirements: docs/requirements.txt
96+
97+
❌ Bad:
98+
Your project is relying on the default Python version and default installed dependencies.
99+
100+
.. code-block:: yaml
101+
102+
# File: .readthedocs.yaml
103+
104+
version: 2
105+
106+
sphinx:
107+
configuration: docs/conf.py
108+
109+
Pinning dependencies
110+
--------------------
111+
112+
As you shouldn't rely on implicit dependencies,
113+
you shouldn't rely on undefined versions of your dependencies.
114+
Some examples:
115+
116+
✅ Good:
117+
The specified versions will be used for all your builds,
118+
in all platforms, and won't be updated unexpectedly.
119+
120+
.. code-block::
121+
122+
# File: docs/requirements.txt
123+
124+
sphinx==3.4.3
125+
sphinx_rtd_theme==0.5.1
126+
readthedocs-sphinx-search==0.1.0rc3
127+
128+
.. code-block:: yaml
129+
130+
# File: docs/environment.yaml
131+
132+
name: docs
133+
channels:
134+
- conda-forge
135+
- defaults
136+
dependencies:
137+
- sphinx==3.4.3
138+
- nbsphinx==0.8.1
139+
- pip:
140+
- sphinx_rtd_theme==0.5.1
141+
142+
❌ Bad:
143+
The latest or any other already installed version will be used,
144+
and your builds can fail or change unexpectedly any time.
145+
146+
.. code-block::
147+
148+
# File: docs/requirements.txt
149+
150+
sphinx
151+
sphinx_rtd_theme
152+
readthedocs-sphinx-search
153+
154+
.. code-block:: yaml
155+
156+
# File: docs/environment.yaml
157+
158+
name: docs
159+
channels:
160+
- conda-forge
161+
- defaults
162+
dependencies:
163+
- sphinx
164+
- nbsphinx
165+
- pip:
166+
- sphinx_rtd_theme
167+
168+
Check the `pip user guide`_ for more information about requirements files,
169+
or our Conda docs about :ref:`environment files <guides/conda:creating the \`\`environment.yml\`\`>`.
170+
171+
.. _`pip user guide`: https://pip.pypa.io/en/stable/user_guide/#requirements-files
172+
173+
.. tip::
174+
175+
Remember to update your docs' dependencies from time to time to get new improvements and fixes.
176+
It also makes it easy to manage in case a version reaches it's end of support date.
177+
178+
.. TODO: link to the supported versions policy.

docs/guides/specifying-dependencies.rst

Lines changed: 0 additions & 48 deletions
This file was deleted.

docs/intro/getting-started-with-mkdocs.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,9 @@ you can start using Read the Docs by :doc:`importing your docs </intro/import-gu
6666

6767
.. warning::
6868

69-
We strongly recommend to :ref:`pin the MkDocs version <guides/specifying-dependencies:Specifying Dependencies>`
69+
We strongly recommend to :ref:`pin the MkDocs version <guides/reproducible-builds:pinning dependencies>`
7070
used for your project to build the docs to avoid potential future incompatibilities.
7171

72-
7372
External resources
7473
------------------
7574

docs/intro/getting-started-with-sphinx.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ by :doc:`importing your docs </intro/import-guide>`.
8383

8484
.. warning::
8585

86-
We strongly recommend to :ref:`pin the Sphinx version <guides/specifying-dependencies:Specifying Dependencies>`
86+
We strongly recommend to :ref:`pin the Sphinx version <guides/reproducible-builds:pinning dependencies>`
8787
used for your project to build the docs to avoid potential future incompatibilities.
8888

8989
.. _this template: https://www.writethedocs.org/guide/writing/beginners-guide-to-docs/#id1

docs/intro/import-guide.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ You can configure these settings in a ``.readthedocs.yaml`` file.
7676
See our :doc:`/config-file/index` docs for more details.
7777

7878
It is also important to note that the default version of Sphinx is ``v1.8.5``.
79-
If choosing to build your documentation other than this,
80-
:ref:`it must be specified <guides/specifying-dependencies:Specifying Dependencies>`.
79+
We recommend to set the version your project uses :ref:`explicitily <guides/reproducible-builds:don't rely on implicit dependencies>`.
8180

8281
Read the Docs will host multiple versions of your code. You can read more about
8382
how to use this well on our :doc:`/versions` page.

0 commit comments

Comments
 (0)