Skip to content

Commit ed129aa

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

File tree

1 file changed

+171
-0
lines changed

1 file changed

+171
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
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+
MkDocs
106+
~~~~~~
107+
108+
We should read the configuration file from the user or default to *one* path,
109+
and error if it doesn't exist.
110+
111+
We shouldn't change the values from the user's configuration (``mkdocs.yml``),
112+
currently we change:
113+
114+
- ``docs_dir``
115+
- ``extra_javascript``
116+
- ``extra_css``
117+
- ``google_analytics`` (we change this to ``None`` and use our own method)
118+
- ``theme`` (we set it to our theme for old projects)
119+
120+
Only the additional js/css files should be added.
121+
Additionally, we could try another more general approach and inject these after the build is complete.
122+
123+
Related to `#7844`_, `#4924`_, `#4827`_, `#4820`_
124+
125+
.. _#7844: https://github.com/readthedocs/readthedocs.org/issues/7844
126+
.. _#4924: https://github.com/readthedocs/readthedocs.org/issues/4924
127+
.. _#4827: https://github.com/readthedocs/readthedocs.org/issues/4827
128+
.. _#4820: https://github.com/readthedocs/readthedocs.org/issues/4820
129+
130+
Web settings
131+
------------
132+
133+
Simple defaults, without fallbacks.
134+
135+
Currently if some of our settings aren't set or are incorrect
136+
we try to guess some values for the user.
137+
We should have some sane defaults and error otherwise.
138+
Some are:
139+
140+
- Requirements file (we shouldn't install any if isn't set)
141+
- Sphinx/MkDocs configuration file (we could default to ``docs/conf.py`` and ``mkdocs.yml``)
142+
143+
.. note::
144+
145+
When using the v2 of the config file we remove all this magic.
146+
147+
Other settings are used for things that can be done from the user side:
148+
149+
- Analytics code
150+
- Canonical domain (Sphinx only)
151+
152+
Adoption
153+
--------
154+
155+
If we remove some magical behaviour that was doing things for the user,
156+
we should document how to do them using Sphinx/MkDocs.
157+
158+
These new builders/environments would be under a feature flag,
159+
where projects created after ``x`` date would use the new builders and environments,
160+
and past projects would use the old ones.
161+
162+
Deprecation
163+
-----------
164+
165+
Using a feature flag can bring some confusion to users that have a project created before the given date,
166+
and other after that date. We can opt-in users into the new builders by adding them into the feature flag.
167+
168+
In order to simplify our code and have all projects using the same options and dependencies
169+
we want to fully migrate all projects to use the new builders.
170+
We could put a date to do this, and contact all users of old projects about this change
171+
(an entry in our blog would also be nice).

0 commit comments

Comments
 (0)