Skip to content

Commit 9247c9e

Browse files
committed
Build: do not auto-create conf.py Sphinx file
Follows https://blog.readthedocs.com/doctool-without-configuration-file/
1 parent 60ff7d6 commit 9247c9e

File tree

3 files changed

+2
-119
lines changed

3 files changed

+2
-119
lines changed

readthedocs/doc_builder/backends/sphinx.py

+2-31
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import structlog
1313
from django.conf import settings
1414
from django.template import loader as template_loader
15-
from django.template.loader import render_to_string
1615
from django.urls import reverse
1716
from requests.exceptions import ConnectionError
1817

@@ -24,7 +23,6 @@
2423
from readthedocs.projects.exceptions import ProjectConfigurationError, UserFileNotFound
2524
from readthedocs.projects.models import Feature
2625
from readthedocs.projects.templatetags.projects_tags import sort_version_aware
27-
from readthedocs.projects.utils import safe_write
2826

2927
from ..base import BaseBuilder
3028
from ..constants import PDF_RE
@@ -113,25 +111,6 @@ def __init__(self, *args, **kwargs):
113111
# because Read the Docs will automatically create one for it.
114112
pass
115113

116-
def _write_config(self, master_doc='index'):
117-
"""Create ``conf.py`` if it doesn't exist."""
118-
log.info(
119-
'Creating default Sphinx config file for project.',
120-
project_slug=self.project.slug,
121-
version_slug=self.version.slug,
122-
)
123-
docs_dir = self.docs_dir()
124-
conf_template = render_to_string(
125-
'sphinx/conf.py.conf',
126-
{
127-
'project': self.project,
128-
'version': self.version,
129-
'master_doc': master_doc,
130-
},
131-
)
132-
conf_file = os.path.join(docs_dir, 'conf.py')
133-
safe_write(conf_file, conf_template)
134-
135114
def get_config_params(self):
136115
"""Get configuration parameters to be rendered into the conf file."""
137116
# TODO this should be handled better in the theme
@@ -272,18 +251,10 @@ def get_config_params(self):
272251

273252
def append_conf(self):
274253
"""
275-
Find or create a ``conf.py`` and appends default content.
254+
Find a ``conf.py`` and appends default content.
276255
277256
The default content is rendered from ``doc_builder/conf.py.tmpl``.
278257
"""
279-
280-
# Generate a `conf.py` from a template
281-
#
282-
# TODO: we should remove this feature at some point to move forward
283-
# with the idea of remove magic from the builders.
284-
if not self.config_file:
285-
self._write_config()
286-
287258
try:
288259
self.config_file = (
289260
self.config_file or self.project.conf_file(self.version.slug)
@@ -310,7 +281,7 @@ def append_conf(self):
310281
outfile.write(rendered)
311282

312283
# Print the contents of conf.py in order to make the rendered
313-
# configfile visible in the build logs
284+
# config file visible in the build logs
314285
self.run(
315286
'cat',
316287
os.path.relpath(

readthedocs/rtd_tests/tests/test_doc_builder.py

-60
Original file line numberDiff line numberDiff line change
@@ -165,66 +165,6 @@ def test_html_context_only_has_public_versions(
165165
}
166166
self.assertEqual(versions, {'v1', 'v2'})
167167

168-
@patch('readthedocs.doc_builder.backends.sphinx.BaseSphinx.docs_dir')
169-
@patch('readthedocs.doc_builder.backends.sphinx.BaseSphinx.get_config_params')
170-
@patch('readthedocs.doc_builder.backends.sphinx.BaseSphinx.run')
171-
@patch('readthedocs.builds.models.Version.get_conf_py_path')
172-
@patch('readthedocs.projects.models.Project.checkout_path')
173-
def test_create_conf_py(
174-
self,
175-
checkout_path,
176-
get_conf_py_path,
177-
_,
178-
get_config_params,
179-
docs_dir,
180-
):
181-
"""
182-
Test for a project without ``conf.py`` file.
183-
184-
When this happen, the ``get_conf_py_path`` raises a
185-
``ProjectConfigurationError`` which is captured by our own code and
186-
generates a conf.py file based using our own template.
187-
188-
This template should be properly rendered in Python2 and Python3 without
189-
any kind of exception raised by ``append_conf`` (we were originally
190-
having a ``TypeError`` because of an encoding problem in Python3)
191-
"""
192-
tmp_dir = tempfile.mkdtemp()
193-
checkout_path.return_value = tmp_dir
194-
docs_dir.return_value = tmp_dir
195-
get_config_params.return_value = {}
196-
get_conf_py_path.side_effect = ProjectConfigurationError
197-
python_env = Virtualenv(
198-
version=self.version,
199-
build_env=self.build_env,
200-
config=None,
201-
)
202-
base_sphinx = BaseSphinx(
203-
build_env=self.build_env,
204-
python_env=python_env,
205-
)
206-
try:
207-
with override_settings(DOCROOT=tmp_dir):
208-
base_sphinx.append_conf()
209-
except Exception:
210-
pytest.fail('Exception was generated when append_conf called.')
211-
212-
# Check the content generated by our method is the same than what we
213-
# expects from a pre-generated file
214-
generated_conf_py = os.path.join(base_sphinx.docs_dir(), 'conf.py')
215-
expected_conf_py = os.path.join(
216-
os.path.dirname(__file__),
217-
'..',
218-
'files',
219-
'conf.py',
220-
)
221-
with open(generated_conf_py) as gf, open(expected_conf_py) as ef:
222-
autogenerated_confpy_lines = 28
223-
self.assertEqual(
224-
gf.readlines()[:autogenerated_confpy_lines],
225-
ef.readlines()[:autogenerated_confpy_lines],
226-
)
227-
228168
@patch('readthedocs.doc_builder.backends.sphinx.BaseSphinx.docs_dir')
229169
@patch('readthedocs.doc_builder.backends.sphinx.BaseSphinx.get_config_params')
230170
@patch('readthedocs.doc_builder.backends.sphinx.BaseSphinx.run')

readthedocs/templates/sphinx/conf.py.conf

-28
This file was deleted.

0 commit comments

Comments
 (0)