Skip to content

Commit 6e012d0

Browse files
committed
Design doc: new builder with explicit options
1 parent db24ee1 commit 6e012d0

File tree

1 file changed

+175
-0
lines changed

1 file changed

+175
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
Explicit Builders
2+
=================
3+
4+
.. contents::
5+
:local:
6+
:depth: 2
7+
8+
Background
9+
----------
10+
11+
In the past we have installed some dependencies on each build,
12+
and tried to guess some options for users in order to make it *easy* for them to start using Read the Docs.
13+
This has bring some unexpected problems and confusion to users, like:
14+
15+
- The Sphinx version (or from any other tool) isn't the one they expect.
16+
- Unexpected dependencies are installed.
17+
- The wrong docs directory is used.
18+
- Their configuration file is changed on build time overriding the defaults or adding new things.
19+
- Some files are auto-generated (like ``index.{rst,md}``).
20+
21+
Currently we are aiming to remove this *magic* behaviour from our build process,
22+
and educating users to be more explicit about their dependencies and options
23+
in order to make their builds reproducible.
24+
25+
We are using several feature flags to stop doing this for new projects,
26+
but with so many flags to check our code starts to be hard to follow.
27+
Instead we would manage a single feature flag and several classes of builds and environments.
28+
29+
Python Environments
30+
-------------------
31+
32+
Currently we have two Python environments: Virtualenv and Conda,
33+
they are in charge of installing requirements into an isolated environment.
34+
We would need to refactor those classes into two types: the new build, and the old build.
35+
36+
The new Python environments would install only the latest versions of the following dependencies:
37+
38+
Virtualenv
39+
- Sphinx or MkDocs
40+
- readthedocs-sphinx-ext
41+
42+
Conda
43+
- readthedocs-sphinx-ext
44+
45+
Note that for Conda we won't install Sphinx or MkDocs,
46+
this is to avoid problems like `#3829`_ and `#8096`_.
47+
48+
.. _#3829: https://github.com/readthedocs/readthedocs.org/issues/3829
49+
.. _#8096: https://github.com/readthedocs/readthedocs.org/issues/8096
50+
51+
Doc builders
52+
------------
53+
54+
Currently we have two types of doc builders: Sphinx and MkDocs.
55+
They are in charge of generating the HTML files (or PDF/EPUB) from the source files.
56+
We would need to refactor those classes into two types: the new build, and the old build.
57+
58+
Both builders create an ``index.{rst,md}`` file with some suggestions if one doesn't exist,
59+
this is to avoid surprises to users, but sometimes this is done on purpose.
60+
We could change our default 404 page to include some this suggestions instead.
61+
62+
The new builders would do the minimal (or none) changes to the user's configuration in order to build their docs.
63+
64+
Sphinx
65+
~~~~~~
66+
67+
conf.py
68+
'''''''
69+
70+
We should read the configuration file from the user or default to *one* path,
71+
and error if it doesn't exist.
72+
We shouldn't change or override the values from the user's configuration (``conf.py``),
73+
some are:
74+
75+
- ``_static`` is added to ``html_static_path`` (probably an old setting)
76+
- ``html_theme`` (we are only setting this if certain condition is met)
77+
- ``websupport2_*`` (probably old settings)
78+
- ``html_context`` (more information below)
79+
- Latex settings
80+
(they are used to improve the output for Chinese and Japanese languages, we should write a guide instead)
81+
82+
Sphinx's ``html_context``
83+
'''''''''''''''''''''''''
84+
85+
We should pass the minimal needed information into the context.
86+
This is related to :doc:`/development/design/theme-context`.
87+
88+
With :doc:`/api/v3` and environment variables (to store the secret token)
89+
should be possible to query several things from the project without having to pass them at build time into the context.
90+
Most the of basic information can be obtained from our environment variables (``READTHEDOCS_*``).
91+
92+
Some values from the context are used in our Sphinx extension,
93+
we should define them as configuration options instead.
94+
Others are used in our theme, should we stop setting them?
95+
96+
Extension
97+
'''''''''
98+
99+
There are some things our extension does that are already supported by Sphinx or themes
100+
(analytics, canonical URL, etc), we should write a guide instead of applying our magic.
101+
102+
The extension also injects some custom js and css files.
103+
We could try another more general approach and inject these on each HTML file after the build is complete.
104+
105+
The extension injects the warning banner if you are reading the docs from a pull request.
106+
We could implement this like the version warning banner instead, so it works for MkDocs too.
107+
(this is injected with the version selector).
108+
109+
MkDocs
110+
~~~~~~
111+
112+
We should read the configuration file from the user or default to *one* path,
113+
and error if it doesn't exist.
114+
115+
We shouldn't change the values from the user's configuration (``mkdocs.yml``),
116+
currently we change:
117+
118+
- ``docs_dir``
119+
- ``extra_javascript``
120+
- ``extra_css``
121+
- ``google_analytics`` (we change this to ``None`` and use our own method)
122+
- ``theme`` (we set it to our theme for old projects)
123+
124+
Only the additional js/css files should be added.
125+
Additionally, we could try another more general approach and inject these after the build is complete.
126+
127+
Related to `#7844`_, `#4924`_, `#4827`_, `#4820`_
128+
129+
.. _#7844: https://github.com/readthedocs/readthedocs.org/issues/7844
130+
.. _#4924: https://github.com/readthedocs/readthedocs.org/issues/4924
131+
.. _#4827: https://github.com/readthedocs/readthedocs.org/issues/4827
132+
.. _#4820: https://github.com/readthedocs/readthedocs.org/issues/4820
133+
134+
Web settings
135+
------------
136+
137+
Simple defaults, without fallbacks.
138+
139+
Currently if some of our settings aren't set or are incorrect
140+
we try to guess some values for the user.
141+
We should have some sane defaults and error otherwise.
142+
Some are:
143+
144+
- Requirements file (we shouldn't install any if isn't set)
145+
- Sphinx/MkDocs configuration file (we could default to ``docs/conf.py`` and ``mkdocs.yml``)
146+
147+
.. note::
148+
149+
When using the v2 of the config file we remove all this magic.
150+
151+
Other settings are used for things that can be done from the user side:
152+
153+
- Analytics code
154+
- Canonical domain (Sphinx only)
155+
156+
Adoption
157+
--------
158+
159+
If we remove some magical behaviour that was doing things for the user,
160+
we should document how to do them using Sphinx/MkDocs.
161+
162+
These new builders/environments would be under a feature flag,
163+
where projects created after ``x`` date would use the new builders and environments,
164+
and past projects would use the old ones.
165+
166+
Deprecation
167+
-----------
168+
169+
Using a feature flag can bring some confusion to users that have a project created before the given date,
170+
and other after that date. We can opt-in users into the new builders by adding them into the feature flag.
171+
172+
In order to simplify our code and have all projects using the same options and dependencies
173+
we want to fully migrate all projects to use the new builders.
174+
We could put a date to do this, and contact all users of old projects about this change
175+
(an entry in our blog would also be nice).

0 commit comments

Comments
 (0)