Skip to content
This repository was archived by the owner on Apr 8, 2025. It is now read-only.

Commit a9ac695

Browse files
committed
Re-add the builders as deprecated
1 parent c8c0b54 commit a9ac695

File tree

1 file changed

+72
-5
lines changed

1 file changed

+72
-5
lines changed

readthedocs_ext/readthedocs.py

Lines changed: 72 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import os
88
import re
99
import types
10+
from datetime import datetime
1011
from distutils.version import LooseVersion
1112

1213
import sphinx
@@ -24,9 +25,15 @@
2425

2526
try:
2627
# Available from Sphinx 2.0
28+
from sphinx.builders.dirhtml import DirectoryHTMLBuilder
29+
from sphinx.builders.html import StandaloneHTMLBuilder
2730
from sphinx.builders.singlehtml import SingleFileHTMLBuilder
2831
except ImportError:
29-
from sphinx.builders.html import SingleFileHTMLBuilder
32+
from sphinx.builders.html import (
33+
DirectoryHTMLBuilder,
34+
SingleFileHTMLBuilder,
35+
StandaloneHTMLBuilder,
36+
)
3037

3138
log = getLogger(__name__)
3239

@@ -36,13 +43,22 @@
3643
# Exclude the SingleHTML builder that is used by RTD to zip up local media
3744
# That builder is never used "online"
3845
ONLINE_BUILDERS = [
39-
'html', 'dirhtml', 'singlehtml'
46+
'html',
47+
'dirhtml',
48+
'singlehtml',
49+
# Deprecated builders
50+
'readthedocs',
51+
'readthedocsdirhtml',
52+
'readthedocssinglehtml',
4053
]
4154
# Only run JSON output once during HTML build
4255
# This saves resources and keeps filepaths correct,
4356
# because singlehtml filepaths are different
4457
JSON_BUILDERS = [
45-
'html', 'dirhtml',
58+
'html',
59+
'dirhtml',
60+
'readthedocs',
61+
'readthedocsdirhtml',
4662
]
4763

4864
# Whitelist keys that we want to output
@@ -63,7 +79,6 @@ def update_body(app, pagename, templatename, context, doctree):
6379
6480
This is the most reliable way to inject our content into the page.
6581
"""
66-
6782
STATIC_URL = context.get('STATIC_URL', DEFAULT_STATIC_URL)
6883
if app.builder.name == 'readthedocssinglehtmllocalmedia':
6984
if 'html_theme' in context and context['html_theme'] == 'sphinx_rtd_theme':
@@ -127,6 +142,7 @@ def rtd_render(self, template, render_context):
127142
'api_host': ctx.get('api_host', ''),
128143
'commit': ctx.get('commit', ''),
129144
'ad_free': ctx.get('ad_free', ''),
145+
'build_date': datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ'),
130146
'global_analytics_code': ctx.get('global_analytics_code'),
131147
'user_analytics_code': ctx.get('user_analytics_code'),
132148
'subprojects': {
@@ -229,6 +245,8 @@ def remove_search_init(app, exception):
229245
with codecs.open(searchtools_file, 'w', encoding='utf-8') as outfile:
230246
data = replacement_regex.sub(replacement_text, data)
231247
outfile.write(data)
248+
else:
249+
log.warning('Missing searchtools: {}'.format(searchtools_file))
232250

233251

234252
def dump_sphinx_data(app, exception):
@@ -292,9 +310,53 @@ def dump_sphinx_data(app, exception):
292310
)
293311

294312

313+
class ReadtheDocsBuilder(StandaloneHTMLBuilder):
314+
315+
"""
316+
Sphinx builder that builds HTML docs.
317+
318+
Note: This builder is DEPRECATED.
319+
In the future Read the Docs will use Sphinx's "html" instead.
320+
"""
321+
322+
name = 'readthedocs'
323+
324+
325+
class ReadtheDocsDirectoryHTMLBuilder(DirectoryHTMLBuilder):
326+
327+
"""
328+
Sphinx builder that builds docs with clean URLs where each page gets its own directory.
329+
330+
Note: This builder is DEPRECATED.
331+
In the future Read the Docs will use Sphinx's "dirhtml" instead.
332+
"""
333+
334+
name = 'readthedocsdirhtml'
335+
336+
337+
class ReadtheDocsSingleFileHTMLBuilder(SingleFileHTMLBuilder):
338+
339+
"""
340+
Sphinx builder that builds a single HTML file to be served by Read the Docs.
341+
342+
This is for users who choose singlehtml as their main output format.
343+
The downloadable .zip file is the builder below.
344+
345+
Note: This builder is DEPRECATED.
346+
In the future Read the Docs will use Sphinx's "singlehtml" instead.
347+
"""
348+
349+
name = 'readthedocssinglehtml'
350+
351+
295352
class ReadtheDocsSingleFileHTMLBuilderLocalMedia(SingleFileHTMLBuilder):
296353

297-
"""Sphinx builder that builds a single HTML file that will be zipped by Read the Docs."""
354+
"""
355+
Sphinx builder that builds a single HTML file that will be zipped by Read the Docs.
356+
357+
Read the Docs specific extras are typically not added to this builder
358+
since it is intended for offline use.
359+
"""
298360

299361
name = 'readthedocssinglehtmllocalmedia'
300362

@@ -313,4 +375,9 @@ def setup(app):
313375
app.add_config_value('readthedocs_embed_doc', '', 'html')
314376
app.add_config_value('rtd_generate_json_artifacts', False, 'html')
315377

378+
# Deprecated builders
379+
app.add_builder(ReadtheDocsBuilder)
380+
app.add_builder(ReadtheDocsDirectoryHTMLBuilder)
381+
app.add_builder(ReadtheDocsSingleFileHTMLBuilder)
382+
316383
return {}

0 commit comments

Comments
 (0)