[Python-checkins] r61555 - in doctools/trunk: doc/config.rst sphinx/builder.py sphinx/config.py sphinx/latexwriter.py sphinx/quickstart.py sphinx/templates/layout.html

georg.brandl python-checkins at python.org
Tue Mar 18 20:54:48 CET 2008


Author: georg.brandl
Date: Tue Mar 18 20:54:45 2008
New Revision: 61555

Modified:
   doctools/trunk/doc/config.rst
   doctools/trunk/sphinx/builder.py
   doctools/trunk/sphinx/config.py
   doctools/trunk/sphinx/latexwriter.py
   doctools/trunk/sphinx/quickstart.py
   doctools/trunk/sphinx/templates/layout.html
Log:
Make it possible to deactivate the module index.


Modified: doctools/trunk/doc/config.rst
==============================================================================
--- doctools/trunk/doc/config.rst	(original)
+++ doctools/trunk/doc/config.rst	Tue Mar 18 20:54:45 2008
@@ -167,6 +167,10 @@
    Additional templates that should be rendered to HTML pages, must be a
    dictionary that maps document names to template names.
 
+.. confval:: html_use_modindex
+
+   If true, add a module index to the HTML documents.   Default is ``True``.
+
 .. confval:: html_copy_source
 
    If true, the reST sources are included in the HTML build as
@@ -217,3 +221,7 @@
 .. confval:: latex_preamble
 
    Additional LaTeX markup for the preamble.
+
+.. confval:: latex_use_modindex
+
+   If true, add a module index to LaTeX documents.   Default is ``True``.

Modified: doctools/trunk/sphinx/builder.py
==============================================================================
--- doctools/trunk/sphinx/builder.py	(original)
+++ doctools/trunk/sphinx/builder.py	Tue Mar 18 20:54:45 2008
@@ -315,6 +315,7 @@
             version = self.config.version,
             last_updated = self.last_updated,
             style = self.config.html_style,
+            use_modindex = self.config.html_use_modindex,
             builder = self.name,
             parents = [],
             titles = {},
@@ -387,46 +388,47 @@
 
         # the global module index
 
-        # the sorted list of all modules, for the global module index
-        modules = sorted(((mn, (self.get_relative_uri('modindex', fn) +
-                                '#module-' + mn, sy, pl, dep))
-                          for (mn, (fn, sy, pl, dep)) in self.env.modules.iteritems()),
-                         key=lambda x: x[0].lower())
-        # collect all platforms
-        platforms = set()
-        # sort out collapsable modules
-        modindexentries = []
-        pmn = ''
-        cg = 0 # collapse group
-        fl = '' # first letter
-        for mn, (fn, sy, pl, dep) in modules:
-            pl = pl and pl.split(', ') or []
-            platforms.update(pl)
-            if fl != mn[0].lower() and mn[0] != '_':
-                modindexentries.append(['', False, 0, False,
-                                        mn[0].upper(), '', [], False])
-            tn = mn.split('.')[0]
-            if tn != mn:
-                # submodule
-                if pmn == tn:
-                    # first submodule - make parent collapsable
-                    modindexentries[-1][1] = True
-                elif not pmn.startswith(tn):
-                    # submodule without parent in list, add dummy entry
+        if self.config.html_use_modindex:
+            # the sorted list of all modules, for the global module index
+            modules = sorted(((mn, (self.get_relative_uri('modindex', fn) +
+                                    '#module-' + mn, sy, pl, dep))
+                              for (mn, (fn, sy, pl, dep)) in self.env.modules.iteritems()),
+                             key=lambda x: x[0].lower())
+            # collect all platforms
+            platforms = set()
+            # sort out collapsable modules
+            modindexentries = []
+            pmn = ''
+            cg = 0 # collapse group
+            fl = '' # first letter
+            for mn, (fn, sy, pl, dep) in modules:
+                pl = pl and pl.split(', ') or []
+                platforms.update(pl)
+                if fl != mn[0].lower() and mn[0] != '_':
+                    modindexentries.append(['', False, 0, False,
+                                            mn[0].upper(), '', [], False])
+                tn = mn.split('.')[0]
+                if tn != mn:
+                    # submodule
+                    if pmn == tn:
+                        # first submodule - make parent collapsable
+                        modindexentries[-1][1] = True
+                    elif not pmn.startswith(tn):
+                        # submodule without parent in list, add dummy entry
+                        cg += 1
+                        modindexentries.append([tn, True, cg, False, '', '', [], False])
+                else:
                     cg += 1
-                    modindexentries.append([tn, True, cg, False, '', '', [], False])
-            else:
-                cg += 1
-            modindexentries.append([mn, False, cg, (tn != mn), fn, sy, pl, dep])
-            pmn = mn
-            fl = mn[0].lower()
-        platforms = sorted(platforms)
-
-        modindexcontext = dict(
-            modindexentries = modindexentries,
-            platforms = platforms,
-        )
-        self.handle_page('modindex', modindexcontext, 'modindex.html')
+                modindexentries.append([mn, False, cg, (tn != mn), fn, sy, pl, dep])
+                pmn = mn
+                fl = mn[0].lower()
+            platforms = sorted(platforms)
+
+            modindexcontext = dict(
+                modindexentries = modindexentries,
+                platforms = platforms,
+            )
+            self.handle_page('modindex', modindexcontext, 'modindex.html')
 
         # the search page
         self.handle_page('search', {}, 'search.html')

Modified: doctools/trunk/sphinx/config.py
==============================================================================
--- doctools/trunk/sphinx/config.py	(original)
+++ doctools/trunk/sphinx/config.py	Tue Mar 18 20:54:45 2008
@@ -53,6 +53,7 @@
         html_index = ('', False),
         html_sidebars = ({}, False),
         html_additional_pages = ({}, False),
+        html_use_modindex = (True, False),
         html_copy_source = (True, False),
 
         # HTML help options
@@ -64,6 +65,7 @@
         latex_documents = ([], False),
         latex_preamble = ('', False),
         latex_appendices = ([], False),
+        latex_use_modindex = (True, False),
     )
 
     def __init__(self, dirname, filename):

Modified: doctools/trunk/sphinx/latexwriter.py
==============================================================================
--- doctools/trunk/sphinx/latexwriter.py	(original)
+++ doctools/trunk/sphinx/latexwriter.py	Tue Mar 18 20:54:45 2008
@@ -33,11 +33,9 @@
 \author{%(author)s}
 %(preamble)s
 \makeindex
-\makemodindex
 '''
 
 FOOTER = r'''
-\printmodindex
 \printindex
 \end{document}
 '''
@@ -57,15 +55,9 @@
         self.builder = builder
 
     def translate(self):
-        try:
-            visitor = LaTeXTranslator(self.document, self.builder)
-            self.document.walkabout(visitor)
-            self.output = visitor.astext()
-        except:
-            import pdb, sys, traceback
-            traceback.print_exc()
-            tb = sys.exc_info()[2]
-            pdb.post_mortem(tb)
+        visitor = LaTeXTranslator(self.document, self.builder)
+        self.document.walkabout(visitor)
+        self.output = visitor.astext()
 
 
 # Helper classes
@@ -100,6 +92,7 @@
                         'papersize': paper,
                         'pointsize': builder.config.latex_font_size,
                         'preamble': builder.config.latex_preamble,
+                        'modindex': builder.config.latex_use_modindex,
                         'author': document.settings.author,
                         'docname': document.settings.docname,
                         # if empty, the title is set to the first section title
@@ -127,8 +120,10 @@
 
     def astext(self):
         return (HEADER % self.options) + \
+               (self.options['modindex'] and '\\makemodindex\n' or '') + \
                self.highlighter.get_stylesheet() + '\n\n' + \
                u''.join(self.body) + \
+               (self.options['modindex'] and '\\printmodindex\n' or '') + \
                (FOOTER % self.options)
 
     def visit_document(self, node):

Modified: doctools/trunk/sphinx/quickstart.py
==============================================================================
--- doctools/trunk/sphinx/quickstart.py	(original)
+++ doctools/trunk/sphinx/quickstart.py	Tue Mar 18 20:54:45 2008
@@ -117,6 +117,9 @@
 # template names.
 #html_additional_pages = {}
 
+# If false, no module index is generated.
+#html_use_modindex = True
+
 # If true, the reST sources are included in the HTML build as _sources/<name>.
 #html_copy_source = True
 
@@ -142,6 +145,9 @@
 
 # Documents to append as an appendix to all manuals.
 #latex_appendices = []
+
+# If false, no module index is generated.
+#latex_use_modindex = True
 '''
 
 MASTER_FILE = '''\

Modified: doctools/trunk/sphinx/templates/layout.html
==============================================================================
--- doctools/trunk/sphinx/templates/layout.html	(original)
+++ doctools/trunk/sphinx/templates/layout.html	Tue Mar 18 20:54:45 2008
@@ -9,7 +9,9 @@
       <h3>Navigation</h3>
       <ul>
         <li class="right" style="margin-right: 10px"><a href="{{ pathto('genindex') }}" title="General Index" accesskey="I">index</a></li>
+        {%- if use_modindex %}
         <li class="right"><a href="{{ pathto('modindex') }}" title="Global Module Index" accesskey="M">modules</a> |</li>
+        {%- endif %}
         {%- if next %}
           <li class="right"><a href="{{ next.link|e }}" title="{{ next.title|striptags }}" accesskey="N">next</a> |</li>
         {%- endif %}


More information about the Python-checkins mailing list