7
7
import os
8
8
import re
9
9
import types
10
+ from datetime import datetime
10
11
from distutils .version import LooseVersion
11
12
12
13
import sphinx
24
25
25
26
try :
26
27
# Available from Sphinx 2.0
28
+ from sphinx .builders .dirhtml import DirectoryHTMLBuilder
29
+ from sphinx .builders .html import StandaloneHTMLBuilder
27
30
from sphinx .builders .singlehtml import SingleFileHTMLBuilder
28
31
except ImportError :
29
- from sphinx .builders .html import SingleFileHTMLBuilder
32
+ from sphinx .builders .html import (
33
+ DirectoryHTMLBuilder ,
34
+ SingleFileHTMLBuilder ,
35
+ StandaloneHTMLBuilder ,
36
+ )
30
37
31
38
log = getLogger (__name__ )
32
39
36
43
# Exclude the SingleHTML builder that is used by RTD to zip up local media
37
44
# That builder is never used "online"
38
45
ONLINE_BUILDERS = [
39
- 'html' , 'dirhtml' , 'singlehtml'
46
+ 'html' ,
47
+ 'dirhtml' ,
48
+ 'singlehtml' ,
49
+ # Deprecated builders
50
+ 'readthedocs' ,
51
+ 'readthedocsdirhtml' ,
52
+ 'readthedocssinglehtml' ,
40
53
]
41
54
# Only run JSON output once during HTML build
42
55
# This saves resources and keeps filepaths correct,
43
56
# because singlehtml filepaths are different
44
57
JSON_BUILDERS = [
45
- 'html' , 'dirhtml' ,
58
+ 'html' ,
59
+ 'dirhtml' ,
60
+ 'readthedocs' ,
61
+ 'readthedocsdirhtml' ,
46
62
]
47
63
48
64
# Whitelist keys that we want to output
@@ -63,7 +79,6 @@ def update_body(app, pagename, templatename, context, doctree):
63
79
64
80
This is the most reliable way to inject our content into the page.
65
81
"""
66
-
67
82
STATIC_URL = context .get ('STATIC_URL' , DEFAULT_STATIC_URL )
68
83
if app .builder .name == 'readthedocssinglehtmllocalmedia' :
69
84
if 'html_theme' in context and context ['html_theme' ] == 'sphinx_rtd_theme' :
@@ -127,6 +142,7 @@ def rtd_render(self, template, render_context):
127
142
'api_host' : ctx .get ('api_host' , '' ),
128
143
'commit' : ctx .get ('commit' , '' ),
129
144
'ad_free' : ctx .get ('ad_free' , '' ),
145
+ 'build_date' : datetime .utcnow ().strftime ('%Y-%m-%dT%H:%M:%SZ' ),
130
146
'global_analytics_code' : ctx .get ('global_analytics_code' ),
131
147
'user_analytics_code' : ctx .get ('user_analytics_code' ),
132
148
'subprojects' : {
@@ -229,6 +245,8 @@ def remove_search_init(app, exception):
229
245
with codecs .open (searchtools_file , 'w' , encoding = 'utf-8' ) as outfile :
230
246
data = replacement_regex .sub (replacement_text , data )
231
247
outfile .write (data )
248
+ else :
249
+ log .warning ('Missing searchtools: {}' .format (searchtools_file ))
232
250
233
251
234
252
def dump_sphinx_data (app , exception ):
@@ -292,9 +310,53 @@ def dump_sphinx_data(app, exception):
292
310
)
293
311
294
312
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
+
295
352
class ReadtheDocsSingleFileHTMLBuilderLocalMedia (SingleFileHTMLBuilder ):
296
353
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
+ """
298
360
299
361
name = 'readthedocssinglehtmllocalmedia'
300
362
@@ -313,4 +375,9 @@ def setup(app):
313
375
app .add_config_value ('readthedocs_embed_doc' , '' , 'html' )
314
376
app .add_config_value ('rtd_generate_json_artifacts' , False , 'html' )
315
377
378
+ # Deprecated builders
379
+ app .add_builder (ReadtheDocsBuilder )
380
+ app .add_builder (ReadtheDocsDirectoryHTMLBuilder )
381
+ app .add_builder (ReadtheDocsSingleFileHTMLBuilder )
382
+
316
383
return {}
0 commit comments