2626from sphinx .project import Project
2727from sphinx .errors import ApplicationError
2828from sphinx .util .logging import getLogger
29- from ..sphinxext .sphinx_doctree_builder import DocTreeBuilder , DocTreeWriter , DocTreeTranslator
29+ from ..sphinxext .sphinx_doctree_builder import (
30+ DocTreeBuilder , DocTreeWriter , DocTreeTranslator )
3031from ..sphinxext .sphinx_md_builder import MdBuilder , MdWriter , MdTranslator
31- from ..sphinxext .sphinx_latex_builder import EnhancedLaTeXBuilder , EnhancedLaTeXWriter , EnhancedLaTeXTranslator
32+ from ..sphinxext .sphinx_latex_builder import (
33+ EnhancedLaTeXBuilder , EnhancedLaTeXWriter , EnhancedLaTeXTranslator )
3234from ..sphinxext .sphinx_rst_builder import RstBuilder , RstWriter , RstTranslator
3335from ._single_file_html_builder import CustomSingleFileHTMLBuilder
3436
@@ -171,8 +173,8 @@ class HTMLTranslatorWithCustomDirectives(_AdditionalVisitDepart, HTMLTranslator)
171173 See @see cl HTMLWriterWithCustomDirectives.
172174 """
173175
174- def __init__ (self , builder , * args , ** kwds ):
175- HTMLTranslator .__init__ (self , builder , * args , ** kwds )
176+ def __init__ (self , document , builder , * args , ** kwds ):
177+ HTMLTranslator .__init__ (self , document , builder , * args , ** kwds )
176178 _AdditionalVisitDepart .__init__ (self , 'html' )
177179 nodes_list = getattr (builder , '_function_node' , None )
178180 if nodes_list is not None :
@@ -201,11 +203,11 @@ class RSTTranslatorWithCustomDirectives(_AdditionalVisitDepart, RstTranslator):
201203 See @see cl HTMLWriterWithCustomDirectives.
202204 """
203205
204- def __init__ (self , builder , * args , ** kwds ):
206+ def __init__ (self , document , builder , * args , ** kwds ):
205207 """
206208 constructor
207209 """
208- RstTranslator .__init__ (self , builder , * args , ** kwds )
210+ RstTranslator .__init__ (self , document , builder , * args , ** kwds )
209211 _AdditionalVisitDepart .__init__ (self , 'rst' )
210212 for name , f1 , f2 in builder ._function_node :
211213 setattr (self .__class__ , "visit_" + name , f1 )
@@ -218,11 +220,11 @@ class MDTranslatorWithCustomDirectives(_AdditionalVisitDepart, MdTranslator):
218220 See @see cl HTMLWriterWithCustomDirectives.
219221 """
220222
221- def __init__ (self , builder , * args , ** kwds ):
223+ def __init__ (self , document , builder , * args , ** kwds ):
222224 """
223225 constructor
224226 """
225- MdTranslator .__init__ (self , builder , * args , ** kwds )
227+ MdTranslator .__init__ (self , document , builder , * args , ** kwds )
226228 _AdditionalVisitDepart .__init__ (self , 'md' )
227229 for name , f1 , f2 in builder ._function_node :
228230 setattr (self .__class__ , "visit_" + name , f1 )
@@ -235,11 +237,11 @@ class DocTreeTranslatorWithCustomDirectives(DocTreeTranslator):
235237 See @see cl HTMLWriterWithCustomDirectives.
236238 """
237239
238- def __init__ (self , builder , * args , ** kwds ):
240+ def __init__ (self , document , builder , * args , ** kwds ):
239241 """
240242 constructor
241243 """
242- DocTreeTranslator .__init__ (self , builder , * args , ** kwds )
244+ DocTreeTranslator .__init__ (self , document , builder , * args , ** kwds )
243245 self .base_class = DocTreeTranslator
244246
245247
@@ -248,7 +250,7 @@ class LatexTranslatorWithCustomDirectives(_AdditionalVisitDepart, EnhancedLaTeXT
248250 See @see cl LatexWriterWithCustomDirectives.
249251 """
250252
251- def __init__ (self , builder , document , * args , ** kwds ):
253+ def __init__ (self , document , builder , * args , ** kwds ):
252254 """
253255 constructor
254256 """
@@ -258,7 +260,7 @@ def __init__(self, builder, document, *args, **kwds):
258260 raise TypeError ( # pragma: no cover
259261 "Builder has no config: {} - {}" .format (type (builder ), type (document )))
260262 EnhancedLaTeXTranslator .__init__ (
261- self , builder , document , * args , ** kwds )
263+ self , document , builder , * args , ** kwds )
262264 _AdditionalVisitDepart .__init__ (self , 'md' )
263265 for name , f1 , f2 in builder ._function_node :
264266 setattr (self .__class__ , "visit_" + name , f1 )
@@ -319,9 +321,6 @@ def write(self, document, destination):
319321
320322 Normally not overridden or extended in subclasses.
321323 """
322- # trans = self.builder.create_translator(self.builder, document)
323- # if not isinstance(trans, HTMLTranslatorWithCustomDirectives):
324- # raise TypeError("The translator is not of a known type but '{0}'".format(type(trans)))
325324 self .base_class .write (self , document , destination )
326325
327326
@@ -347,7 +346,7 @@ def __init__(self, builder=None, app=None): # pylint: disable=W0231
347346
348347 def translate (self ):
349348 self .visitor = visitor = self .translator_class (
350- self .builder , self .document )
349+ self .document , self .builder )
351350 self .document .walkabout (visitor )
352351 self .output = visitor .astext ()
353352 for attr in ('head_prefix' , 'stylesheet' , 'head' , 'body_prefix' ,
@@ -374,7 +373,7 @@ def __init__(self, builder=None, app=None): # pylint: disable=W0231
374373 self , RstWriter , RSTTranslatorWithCustomDirectives , app )
375374
376375 def translate (self ):
377- visitor = self .translator_class (self .builder , self .document )
376+ visitor = self .translator_class (self .document , self .builder )
378377 self .document .walkabout (visitor )
379378 self .output = visitor .body
380379
@@ -394,7 +393,7 @@ def __init__(self, builder=None, app=None): # pylint: disable=W0231
394393 self , MdWriter , MDTranslatorWithCustomDirectives , app )
395394
396395 def translate (self ):
397- visitor = self .translator_class (self .builder , self .document )
396+ visitor = self .translator_class (self .document , self .builder )
398397 self .document .walkabout (visitor )
399398 self .output = visitor .body
400399
@@ -414,7 +413,7 @@ def __init__(self, builder=None, app=None): # pylint: disable=W0231
414413 self , DocTreeWriter , DocTreeTranslatorWithCustomDirectives , app )
415414
416415 def translate (self ):
417- visitor = self .translator_class (self .builder , self .document )
416+ visitor = self .translator_class (self .document , self .builder )
418417 self .document .walkabout (visitor )
419418 self .output = visitor .body
420419
@@ -441,10 +440,10 @@ def translate(self):
441440 raise TypeError ( # pragma: no cover
442441 "Builder has no config: {}" .format (type (self .builder )))
443442 # The instruction
444- # visitor = self.builder.create_translator(self.builder , self.document )
443+ # visitor = self.builder.create_translator(self.document , self.builder )
445444 # automatically adds methods visit_ and depart_ for translator
446445 # based on the list of registered extensions. Might be worth using it.
447- visitor = self .translator_class (self .builder , self .document )
446+ visitor = self .translator_class (self .document , self .builder )
448447 self .document .walkabout (visitor )
449448 self .output = visitor .body
450449
@@ -1208,7 +1207,7 @@ def _citems():
12081207
12091208 # create the project
12101209 self .project = Project (self .srcdir , self .config .source_suffix )
1211- # create the builder
1210+ # create the builder, initializes _MemoryBuilder
12121211 self .builder = self .create_builder (buildername )
12131212 # set up the build environment
12141213 self ._init_env (freshenv )
@@ -1221,9 +1220,17 @@ def _citems():
12211220
12221221 # addition
12231222 self ._extended_init_ ()
1223+
1224+ # verification
1225+ self ._check_init_ ()
1226+
1227+ def _check_init_ (self ):
1228+ pass
12241229
12251230 def _init_env (self , freshenv ):
1226- if freshenv :
1231+ ENV_PICKLE_FILENAME = 'environment.pickle'
1232+ filename = os .path .join (self .doctreedir , ENV_PICKLE_FILENAME )
1233+ if freshenv or not os .path .exists (filename ):
12271234 self .env = _CustomBuildEnvironment (self )
12281235 self .env .setup (self )
12291236 if self .srcdir is not None and self .srcdir != "IMPOSSIBLE:TOFIND" :
0 commit comments