gminick / sphinx-gsoc2009
fork of sphinx
A support for per-paragraph comments and user/developer interface for submitting/committing fixes.
Clone this repository (size: 8.4 MB): HTTPS / SSH
$ hg clone http://bitbucket.org/gminick/sphinx-gsoc2009/
| commit 1604: | 86c93db9ac31 |
| parent 1603: | 9fe02ac5ee25 |
| parent 1602: | 5be2fe52a100 |
| branch: | default |
merge
Changed (Δ2.2 KB):
raw changeset »
sphinx/builders/__init__.py (5 lines added, 57 lines removed)
sphinx/builders/html.py (14 lines added, 9 lines removed)
Up to file-list sphinx/builders/__init__.py:
| … | … | @@ -15,9 +15,7 @@ from os import path |
15 |
15 |
|
16 |
16 |
from docutils import nodes |
17 |
17 |
|
18 |
from sphinx import package_dir, locale |
|
19 |
18 |
from sphinx.util import SEP, relative_uri |
20 |
from sphinx.environment import BuildEnvironment |
|
21 |
19 |
from sphinx.util.console import bold, purple, darkgreen, term_width_line |
22 |
20 |
|
23 |
21 |
# side effect: registers roles and directives |
| … | … | @@ -25,9 +23,6 @@ from sphinx import roles |
25 |
23 |
from sphinx import directives |
26 |
24 |
|
27 |
25 |
|
28 |
ENV_PICKLE_FILENAME = 'environment.pickle' |
|
29 |
||
30 |
||
31 |
26 |
class Builder(object): |
32 |
27 |
""" |
33 |
28 |
Builds target formats from the reST sources. |
| … | … | @@ -38,7 +33,8 @@ class Builder(object): |
38 |
33 |
# builder's output format, or '' if no document output is produced |
39 |
34 |
format = '' |
40 |
35 |
|
41 |
def __init__(self, app |
|
36 |
def __init__(self, app): |
|
37 |
self.env = app.env |
|
42 |
38 |
self.srcdir = app.srcdir |
43 |
39 |
self.confdir = app.confdir |
44 |
40 |
self.outdir = app.outdir |
| … | … | @@ -50,18 +46,13 @@ class Builder(object): |
50 |
46 |
self.warn = app.warn |
51 |
47 |
self.info = app.info |
52 |
48 |
self.config = app.config |
53 |
||
54 |
self.load_i18n() |
|
49 |
self.tags = app.tags |
|
50 |
self.tags.add(self.format) |
|
55 |
51 |
|
56 |
52 |
# images that need to be copied over (source -> dest) |
57 |
53 |
self.images = {} |
58 |
54 |
|
59 |
# if None, this is set in load_env() |
|
60 |
self.env = env |
|
61 |
self.freshenv = freshenv |
|
62 |
||
63 |
55 |
self.init() |
64 |
self.load_env() |
|
65 |
56 |
|
66 |
57 |
# helper methods |
67 |
58 |
|
| … | … | @@ -167,50 +158,6 @@ class Builder(object): |
167 |
158 |
|
168 |
159 |
# build methods |
169 |
160 |
|
170 |
def load_i18n(self): |
|
171 |
""" |
|
172 |
Load translated strings from the configured localedirs if |
|
173 |
enabled in the configuration. |
|
174 |
""" |
|
175 |
if self.config.language is not None: |
|
176 |
self.info(bold('loading translations [%s]... ' % |
|
177 |
self.config.language), nonl=True) |
|
178 |
locale_dirs = [None, path.join(package_dir, 'locale')] + \ |
|
179 |
[path.join(self.srcdir, x) for x in self.config.locale_dirs] |
|
180 |
else: |
|
181 |
locale_dirs = [] |
|
182 |
self.translator, has_translation = locale.init(locale_dirs, |
|
183 |
self.config.language) |
|
184 |
if self.config.language is not None: |
|
185 |
if has_translation: |
|
186 |
self.info('done') |
|
187 |
else: |
|
188 |
self.info('locale not available') |
|
189 |
||
190 |
def load_env(self): |
|
191 |
"""Set up the build environment.""" |
|
192 |
if self.env: |
|
193 |
return |
|
194 |
if not self.freshenv: |
|
195 |
try: |
|
196 |
self.info(bold('loading pickled environment... '), nonl=True) |
|
197 |
self.env = BuildEnvironment.frompickle(self.config, |
|
198 |
path.join(self.doctreedir, ENV_PICKLE_FILENAME)) |
|
199 |
self.info('done') |
|
200 |
except Exception, err: |
|
201 |
if type(err) is IOError and err.errno == 2: |
|
202 |
self.info('not found') |
|
203 |
else: |
|
204 |
self.info('failed: %s' % err) |
|
205 |
self.env = BuildEnvironment(self.srcdir, self.doctreedir, |
|
206 |
self.config) |
|
207 |
self.env.find_files(self.config) |
|
208 |
else: |
|
209 |
self.env = BuildEnvironment(self.srcdir, self.doctreedir, |
|
210 |
self.config) |
|
211 |
self.env.find_files(self.config) |
|
212 |
self.env.set_warnfunc(self.warn) |
|
213 |
||
214 |
161 |
def build_all(self): |
215 |
162 |
"""Build all source files.""" |
216 |
163 |
self.build(None, summary='all source files', method='all') |
| … | … | @@ -290,6 +237,7 @@ class Builder(object): |
290 |
237 |
|
291 |
238 |
if updated_docnames: |
292 |
239 |
# save the environment |
240 |
from sphinx.application import ENV_PICKLE_FILENAME |
|
293 |
241 |
self.info(bold('pickling environment... '), nonl=True) |
294 |
242 |
self.env.topickle(path.join(self.doctreedir, ENV_PICKLE_FILENAME)) |
295 |
243 |
self.info('done') |
Up to file-list sphinx/builders/html.py:
| … | … | @@ -33,7 +33,8 @@ from sphinx.util import SEP, os_path, re |
33 |
33 |
from sphinx.errors import SphinxError |
34 |
34 |
from sphinx.search import js_index |
35 |
35 |
from sphinx.theming import Theme |
36 |
from sphinx.builders import Builder |
|
36 |
from sphinx.builders import Builder |
|
37 |
from sphinx.application import ENV_PICKLE_FILENAME |
|
37 |
38 |
from sphinx.highlighting import PygmentsBridge |
38 |
39 |
from sphinx.util.console import bold |
39 |
40 |
from sphinx.writers.html import HTMLWriter, HTMLTranslator, \ |
| … | … | @@ -239,7 +240,9 @@ class StandaloneHTMLBuilder(Builder): |
239 |
240 |
rellinks = [] |
240 |
241 |
if self.config.html_use_index: |
241 |
242 |
rellinks.append(('genindex', _('General Index'), 'I', _('index'))) |
242 |
|
|
243 |
# XXX generalization of modindex? |
|
244 |
if self.config.html_use_modindex and \ |
|
245 |
self.env.domaindata['py']['modules']: |
|
243 |
246 |
rellinks.append(('modindex', _('Global Module Index'), |
244 |
247 |
'M', _('modules'))) |
245 |
248 |
|
| … | … | @@ -404,12 +407,13 @@ class StandaloneHTMLBuilder(Builder): |
404 |
407 |
|
405 |
408 |
# the global module index |
406 |
409 |
|
407 |
|
|
410 |
moduleindex = self.env.domaindata['py']['modules'] |
|
411 |
if self.config.html_use_modindex and moduleindex: |
|
408 |
412 |
# the sorted list of all modules, for the global module index |
409 |
413 |
modules = sorted(((mn, (self.get_relative_uri('modindex', fn) + |
410 |
414 |
'#module-' + mn, sy, pl, dep)) |
411 |
415 |
for (mn, (fn, sy, pl, dep)) in |
412 |
|
|
416 |
moduleindex.iteritems()), |
|
413 |
417 |
key=lambda x: x[0].lower()) |
414 |
418 |
# collect all platforms |
415 |
419 |
platforms = set() |
| … | … | @@ -709,14 +713,15 @@ class StandaloneHTMLBuilder(Builder): |
709 |
713 |
self.info(bold('dumping object inventory... '), nonl=True) |
710 |
714 |
f = open(path.join(self.outdir, INVENTORY_FILENAME), 'w') |
711 |
715 |
try: |
716 |
# XXX inventory version 2 |
|
712 |
717 |
f.write('# Sphinx inventory version 1\n') |
713 |
718 |
f.write('# Project: %s\n' % self.config.project.encode('utf-8')) |
714 |
719 |
f.write('# Version: %s\n' % self.config.version) |
715 |
for modname, info in self.env.modules.iteritems(): |
|
716 |
f.write('%s mod %s\n' % (modname, self.get_target_uri(info[0]))) |
|
717 |
for refname, (docname, desctype) in self.env.descrefs.iteritems(): |
|
718 |
f.write('%s %s %s\n' % (refname, desctype, |
|
719 |
|
|
720 |
#for modname, info in self.env.modules.iteritems(): |
|
721 |
# f.write('%s mod %s\n' % (modname, self.get_target_uri(info[0]))) |
|
722 |
#for refname, (docname, desctype) in self.env.descrefs.iteritems(): |
|
723 |
# f.write('%s %s %s\n' % (refname, desctype, |
|
724 |
# self.get_target_uri(docname))) |
|
720 |
725 |
finally: |
721 |
726 |
f.close() |
722 |
727 |
self.info('done') |
