summaryrefslogtreecommitdiff
path: root/sphinx
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2011-01-08 17:32:32 +0100
committerGeorg Brandl <georg@python.org>2011-01-08 17:32:32 +0100
commit4526dd75ca7a1a61555fb47dffd1d4e4de4ee0cb (patch)
treec3678ebad572a3a8d4ad37d45dc783abae3fdeaa /sphinx
parent16c45674eff514fc7a23528ba207721dd8215a2a (diff)
downloadsphinx-4526dd75ca7a1a61555fb47dffd1d4e4de4ee0cb.tar.gz
Rename "intl" module to "gettext", to make it easier to find. Distinguish environments with different versioning methods and always give the gettext builder its own doctree dir.
Diffstat (limited to 'sphinx')
-rw-r--r--sphinx/builders/__init__.py5
-rw-r--r--sphinx/builders/gettext.py (renamed from sphinx/builders/intl.py)5
-rw-r--r--sphinx/builders/websupport.py1
-rw-r--r--sphinx/environment.py62
-rw-r--r--sphinx/quickstart.py9
5 files changed, 58 insertions, 24 deletions
diff --git a/sphinx/builders/__init__.py b/sphinx/builders/__init__.py
index 33954033..5240a1c7 100644
--- a/sphinx/builders/__init__.py
+++ b/sphinx/builders/__init__.py
@@ -31,9 +31,12 @@ class Builder(object):
name = ''
# builder's output format, or '' if no document output is produced
format = ''
+ # doctree versioning method
+ versioning_method = 'none'
def __init__(self, app):
self.env = app.env
+ self.env.set_versioning_method(self.versioning_method)
self.srcdir = app.srcdir
self.confdir = app.confdir
self.outdir = app.outdir
@@ -330,5 +333,5 @@ BUILTIN_BUILDERS = {
'changes': ('changes', 'ChangesBuilder'),
'linkcheck': ('linkcheck', 'CheckExternalLinksBuilder'),
'websupport': ('websupport', 'WebSupportBuilder'),
- 'gettext': ('intl', 'MessageCatalogBuilder'),
+ 'gettext': ('gettext', 'MessageCatalogBuilder'),
}
diff --git a/sphinx/builders/intl.py b/sphinx/builders/gettext.py
index 74ba03b5..1ff92360 100644
--- a/sphinx/builders/intl.py
+++ b/sphinx/builders/gettext.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
"""
- sphinx.builders.intl
- ~~~~~~~~~~~~~~~~~~~~
+ sphinx.builders.gettext
+ ~~~~~~~~~~~~~~~~~~~~~~~
The MessageCatalogBuilder class.
@@ -48,6 +48,7 @@ class I18nBuilder(Builder):
General i18n builder.
"""
name = 'i18n'
+ versioning_method = 'text'
def init(self):
Builder.init(self)
diff --git a/sphinx/builders/websupport.py b/sphinx/builders/websupport.py
index e8f6aef3..b7757309 100644
--- a/sphinx/builders/websupport.py
+++ b/sphinx/builders/websupport.py
@@ -26,6 +26,7 @@ class WebSupportBuilder(PickleHTMLBuilder):
Builds documents for the web support package.
"""
name = 'websupport'
+ versioning_method = 'commentable'
def init(self):
PickleHTMLBuilder.init(self)
diff --git a/sphinx/environment.py b/sphinx/environment.py
index 32cc44a8..75292299 100644
--- a/sphinx/environment.py
+++ b/sphinx/environment.py
@@ -43,6 +43,7 @@ from sphinx.util.nodes import clean_astext, make_refnode, extract_messages
from sphinx.util.osutil import movefile, SEP, ustrftime
from sphinx.util.matching import compile_matchers
from sphinx.util.pycompat import all, class_types
+from sphinx.util.websupport import is_commentable
from sphinx.errors import SphinxError, ExtensionError
from sphinx.locale import _, init as init_locale
from sphinx.versioning import add_uids, merge_doctrees
@@ -79,6 +80,12 @@ default_substitutions = set([
dummy_reporter = Reporter('', 4, 4)
+versioning_methods = {
+ 'none': False,
+ 'text': nodes.TextElement,
+ 'commentable': is_commentable,
+}
+
class WarningStream(object):
def __init__(self, warnfunc):
@@ -313,6 +320,9 @@ class BuildEnvironment:
self.srcdir = srcdir
self.config = config
+ # the method of doctree versioning; see set_versioning_method
+ self.versioning_method = None
+
# the application object; only set while update() runs
self.app = None
@@ -380,6 +390,23 @@ class BuildEnvironment:
self._warnfunc = func
self.settings['warning_stream'] = WarningStream(func)
+ def set_versioning_method(self, method):
+ """This sets the doctree versioning method for this environment.
+
+ Versioning methods are a builder property; only builders with the same
+ versioning method can share the same doctree directory. Therefore, we
+ raise an exception if the user tries to use an environment with an
+ incompatible versioning method.
+ """
+ if method not in versioning_methods:
+ raise ValueError('invalid versioning method: %r' % method)
+ method = versioning_methods[method]
+ if self.versioning_method not in (None, method):
+ raise SphinxError('This environment is incompatible with the '
+ 'selected builder, please choose another '
+ 'doctree directory.')
+ self.versioning_method = method
+
def warn(self, docname, msg, lineno=None):
# strange argument order is due to backwards compatibility
self._warnfunc(msg, (docname, lineno))
@@ -754,25 +781,24 @@ class BuildEnvironment:
# 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')
+ if self.versioning_method:
+ # get old doctree
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))
+ f = open(self.doc2path(docname,
+ self.doctreedir, '.doctree'), 'rb')
+ try:
+ old_doctree = pickle.load(f)
+ finally:
+ f.close()
+ 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, self.versioning_method))
# make it picklable
doctree.reporter = None
diff --git a/sphinx/quickstart.py b/sphinx/quickstart.py
index 4d7e2db3..0818ad0a 100644
--- a/sphinx/quickstart.py
+++ b/sphinx/quickstart.py
@@ -361,6 +361,8 @@ PAPEROPT_a4 = -D latex_paper_size=a4
PAPEROPT_letter = -D latex_paper_size=letter
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) \
$(SPHINXOPTS) %(rsrcdir)s
+# the i18n builder cannot share the environment and doctrees with the others
+I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) %(rsrcdir)s
.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp \
epub latex latexpdf text man changes linkcheck doctest gettext
@@ -483,7 +485,7 @@ info:
\t@echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."
gettext:
-\t$(SPHINXBUILD) -b gettext $(ALLSPHINXOPTS) $(BUILDDIR)/locale
+\t$(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
\t@echo
\t@echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
@@ -514,8 +516,10 @@ if "%%SPHINXBUILD%%" == "" (
)
set BUILDDIR=%(rbuilddir)s
set ALLSPHINXOPTS=-d %%BUILDDIR%%/doctrees %%SPHINXOPTS%% %(rsrcdir)s
+set I18NSPHINXOPTS=%%SPHINXOPTS%% %(rsrcdir)s
if NOT "%%PAPER%%" == "" (
\tset ALLSPHINXOPTS=-D latex_paper_size=%%PAPER%% %%ALLSPHINXOPTS%%
+\tset I18NSPHINXOPTS=-D latex_paper_size=%%PAPER%% %%I18NSPHINXOPTS%%
)
if "%%1" == "" goto help
@@ -659,7 +663,7 @@ if "%%1" == "texinfo" (
)
if "%%1" == "gettext" (
-\t%%SPHINXBUILD%% -b gettext %%ALLSPHINXOPTS%% %%BUILDDIR%%/locale
+\t%%SPHINXBUILD%% -b gettext %%I18NSPHINXOPTS%% %%BUILDDIR%%/locale
\tif errorlevel 1 exit /b 1
\techo.
\techo.Build finished. The message catalogs are in %%BUILDDIR%%/locale.
@@ -991,4 +995,3 @@ def main(argv=sys.argv):
print
print '[Interrupted.]'
return
-