Anonymous avatar Anonymous committed 593794f

Handle versioning in the environment

Comments (0)

Files changed (4)

sphinx/builders/intl.py

 from docutils import nodes
 
 from sphinx.builders import Builder
-from sphinx.builders.versioning import VersioningBuilderMixin
 from sphinx.util.nodes import extract_messages
 from sphinx.util.osutil import SEP, copyfile
 from sphinx.util.console import darkgreen
 """[1:]
 
 
-class I18nBuilder(Builder, VersioningBuilderMixin):
+class I18nBuilder(Builder):
     """
     General i18n builder.
     """
 
     def init(self):
         Builder.init(self)
-        VersioningBuilderMixin.init(self)
         self.catalogs = defaultdict(dict)
 
     def get_target_uri(self, docname, typ=None):
     def write_doc(self, docname, doctree):
         catalog = self.catalogs[docname.split(SEP, 1)[0]]
 
-        self.handle_versioning(docname, doctree, nodes.TextElement)
-
         for node, msg in extract_messages(doctree):
             catalog.setdefault(node.uid, msg)
 
-    def finish(self):
-        Builder.finish(self)
-        VersioningBuilderMixin.finish(self)
-
 
 class MessageCatalogBuilder(I18nBuilder):
     """

sphinx/builders/versioning.py

-# -*- coding: utf-8 -*-
-"""
-    sphinx.builders.versioning
-    ~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-    :copyright: Copyright 2007-2011 by the Sphinx team, see AUTHORS.
-    :license: BSD, see LICENSE for details.
-"""
-import os
-import cPickle as pickle
-
-from docutils.utils import Reporter
-
-from sphinx.util.osutil import copyfile
-from sphinx.environment import WarningStream
-from sphinx.versioning import add_uids, merge_doctrees
-
-
-class VersioningBuilderMixin(object):
-    def walk_doctree_files(self):
-        for root, dirs, files in os.walk(self.doctreedir):
-            for fn in files:
-                yield os.path.join(root, fn)
-
-    def init(self):
-        for fp in self.walk_doctree_files():
-            if fp.endswith('.doctree'):
-                copyfile(fp, fp + '.old')
-
-    def get_old_doctree(self, docname):
-        fp = self.env.doc2path(docname, self.doctreedir, '.doctree.old')
-        try:
-            f = open(fp, 'rb')
-            try:
-                doctree = pickle.load(f)
-            finally:
-                f.close()
-        except IOError:
-            return None
-        doctree.settings.env = self.env
-        doctree.reporter = Reporter(self.env.doc2path(docname), 2, 5,
-                                    stream=WarningStream(self.env._warnfunc))
-        return doctree
-
-    def resave_doctree(self, docname, doctree):
-        reporter = doctree.reporter
-        doctree.reporter = None
-        doctree.settings.warning_stream = None
-        doctree.settings.env = None
-        doctree.settings.record_dependencies = None
-
-        fp = self.env.doc2path(docname, self.doctreedir, '.doctree')
-        f = open(fp, 'wb')
-        try:
-            pickle.dump(doctree, f, pickle.HIGHEST_PROTOCOL)
-        finally:
-            f.close()
-
-        doctree.reporter = reporter
-
-    def handle_versioning(self, docname, doctree, condition):
-        old_doctree = self.get_old_doctree(docname)
-        if old_doctree:
-            list(merge_doctrees(old_doctree, doctree, condition))
-        else:
-            list(add_uids(doctree, condition))
-        self.resave_doctree(docname, doctree)
-
-    def finish(self):
-        for fp in self.walk_doctree_files():
-            if fp.endswith('.doctree.old'):
-                os.remove(fp)

sphinx/builders/websupport.py

 
 from sphinx.jinja2glue import BuiltinTemplateLoader
 from sphinx.util.osutil import os_path, relative_uri, ensuredir, copyfile
-from sphinx.util.websupport import is_commentable
 from sphinx.builders.html import PickleHTMLBuilder
-from sphinx.builders.versioning import VersioningBuilderMixin
 from sphinx.writers.websupport import WebSupportTranslator
 
 
-class WebSupportBuilder(PickleHTMLBuilder, VersioningBuilderMixin):
+class WebSupportBuilder(PickleHTMLBuilder):
     """
     Builds documents for the web support package.
     """
 
     def init(self):
         PickleHTMLBuilder.init(self)
-        VersioningBuilderMixin.init(self)
         # templates are needed for this builder, but the serializing
         # builder does not initialize them
         self.init_templates()
         destination = StringOutput(encoding='utf-8')
         doctree.settings = self.docsettings
 
-        self.handle_versioning(docname, doctree, is_commentable)
-
         self.cur_docname = docname
         self.secnumbers = self.env.toc_secnumbers.get(docname, {})
         self.imgpath = '/' + posixpath.join(self.virtual_staticdir, '_images')
         self.globalcontext['script'] = doc_ctx['script']
 
         PickleHTMLBuilder.handle_finish(self)
-        VersioningBuilderMixin.finish(self)
 
         # move static stuff over to separate directory
         directories = ['_images', '_static']

sphinx/environment.py

 from sphinx.util.pycompat import all, class_types
 from sphinx.errors import SphinxError, ExtensionError
 from sphinx.locale import _, init as init_locale
+from sphinx.versioning import add_uids, merge_doctrees
 
 fs_encoding = sys.getfilesystemencoding() or sys.getdefaultencoding()
 
         # store time of build, for outdated files detection
         self.all_docs[docname] = time.time()
 
+        # get old doctree
+        old_doctree_path = self.doc2path(docname, self.doctreedir, '.doctree')
+        try:
+            f = open(old_doctree_path, 'rb')
+            try:
+                old_doctree = pickle.load(f)
+            finally:
+                f.close()
+            old_doctree.settings.env = self
+            old_doctree.reporter = Reporter(self.doc2path(docname), 2, 5,
+                                            stream=WarningStream(self._warnfunc))
+        except EnvironmentError:
+            old_doctree = None
+
+        # add uids for versioning
+        if old_doctree is None:
+            list(add_uids(doctree, nodes.TextElement))
+        else:
+            list(merge_doctrees(old_doctree, doctree, nodes.TextElement))
+
         # make it picklable
         doctree.reporter = None
         doctree.transformer = None
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.