[Python-checkins] r67116 - in doctools/trunk/sphinx: __init__.py builder.py config.py directives/desc.py directives/other.py htmlwriter.py latexwriter.py texinputs/sphinx.sty textwriter.py util/compat.py util/texescape.py
georg.brandl
python-checkins at python.org
Thu Nov 6 10:10:57 CET 2008
Author: georg.brandl
Date: Thu Nov 6 10:10:57 2008
New Revision: 67116
Log:
Copy changes from Hg until r720:23cba1770f48.
Modified:
doctools/trunk/sphinx/__init__.py
doctools/trunk/sphinx/builder.py
doctools/trunk/sphinx/config.py
doctools/trunk/sphinx/directives/desc.py
doctools/trunk/sphinx/directives/other.py
doctools/trunk/sphinx/htmlwriter.py
doctools/trunk/sphinx/latexwriter.py
doctools/trunk/sphinx/texinputs/sphinx.sty
doctools/trunk/sphinx/textwriter.py
doctools/trunk/sphinx/util/compat.py
doctools/trunk/sphinx/util/texescape.py
Modified: doctools/trunk/sphinx/__init__.py
==============================================================================
--- doctools/trunk/sphinx/__init__.py (original)
+++ doctools/trunk/sphinx/__init__.py Thu Nov 6 10:10:57 2008
@@ -21,7 +21,7 @@
__revision__ = '$Revision$'
__version__ = '0.5'
-__released__ = '0.5 (SVN)'
+__released__ = '0.5 (hg)'
def usage(argv, msg=None):
@@ -39,8 +39,10 @@
-c <path> -- path where configuration file (conf.py) is located
(default: same as sourcedir)
-D <setting=value> -- override a setting in configuration
+ -A <name=value> -- pass a value into the templates, for HTML builder
-N -- do not do colored output
-q -- no output on stdout, just warnings on stderr
+ -Q -- no output at all, not even warnings
-P -- run Pdb on exception
Modi:
* without -a and without filenames, write new and changed files.
@@ -59,7 +61,7 @@
nocolor()
try:
- opts, args = getopt.getopt(argv[1:], 'ab:d:c:D:NEqP')
+ opts, args = getopt.getopt(argv[1:], 'ab:d:c:D:A:NEqP')
srcdir = confdir = path.abspath(args[0])
if not path.isdir(srcdir):
print >>sys.stderr, 'Error: Cannot find source directory.'
@@ -70,8 +72,8 @@
return 1
outdir = path.abspath(args[1])
if not path.isdir(outdir):
- print >>sys.stderr, 'Error: Cannot find output directory.'
- return 1
+ print >>sys.stderr, 'Making output directory...'
+ os.makedirs(outdir)
except (IndexError, getopt.error):
usage(argv)
return 1
@@ -88,7 +90,9 @@
buildername = all_files = None
freshenv = use_pdb = False
status = sys.stdout
+ warning = sys.stderr
confoverrides = {}
+ htmlcontext = {}
doctreedir = path.join(outdir, '.doctrees')
for opt, val in opts:
if opt == '-b':
@@ -107,24 +111,45 @@
'Error: Configuration directory doesn\'t contain conf.py file.'
return 1
elif opt == '-D':
- key, val = val.split('=')
+ try:
+ key, val = val.split('=')
+ except ValueError:
+ print >>sys.stderr, \
+ 'Error: -D option argument must be in the form name=value.'
+ return 1
try:
val = int(val)
except ValueError:
pass
confoverrides[key] = val
+ elif opt == '-A':
+ try:
+ key, val = val.split('=')
+ except ValueError:
+ print >>sys.stderr, \
+ 'Error: -A option argument must be in the form name=value.'
+ return 1
+ try:
+ val = int(val)
+ except ValueError:
+ pass
+ htmlcontext[key] = val
elif opt == '-N':
nocolor()
elif opt == '-E':
freshenv = True
elif opt == '-q':
status = StringIO()
+ elif opt == '-Q':
+ status = StringIO()
+ warning = StringIO()
elif opt == '-P':
use_pdb = True
+ confoverrides['html_context'] = htmlcontext
try:
app = Sphinx(srcdir, confdir, outdir, doctreedir, buildername,
- confoverrides, status, sys.stderr, freshenv)
+ confoverrides, status, warning, freshenv)
app.build(all_files, filenames)
except KeyboardInterrupt:
if use_pdb:
Modified: doctools/trunk/sphinx/builder.py
==============================================================================
--- doctools/trunk/sphinx/builder.py (original)
+++ doctools/trunk/sphinx/builder.py Thu Nov 6 10:10:57 2008
@@ -67,7 +67,7 @@
self.outdir = app.outdir
self.doctreedir = app.doctreedir
if not path.isdir(self.doctreedir):
- os.mkdir(self.doctreedir)
+ os.makedirs(self.doctreedir)
self.app = app
self.warn = app.warn
@@ -425,7 +425,7 @@
rellinks = []
if self.config.html_use_index:
rellinks.append(('genindex', _('General Index'), 'I', _('index')))
- if self.config.html_use_modindex:
+ if self.config.html_use_modindex and self.env.modules:
rellinks.append(('modindex', _('Global Module Index'), 'M', _('modules')))
self.globalcontext = dict(
@@ -449,6 +449,7 @@
logo = logo,
favicon = favicon,
)
+ self.globalcontext.update(self.config.html_context)
def get_doc_context(self, docname, body, metatags):
"""Collect items for the template context of a page."""
@@ -558,7 +559,7 @@
# the global module index
- if self.config.html_use_modindex:
+ if self.config.html_use_modindex and self.env.modules:
# 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))
Modified: doctools/trunk/sphinx/config.py
==============================================================================
--- doctools/trunk/sphinx/config.py (original)
+++ doctools/trunk/sphinx/config.py Thu Nov 6 10:10:57 2008
@@ -71,6 +71,7 @@
html_use_opensearch = ('', False),
html_file_suffix = (None, False),
html_show_sphinx = (True, False),
+ html_context = ({}, False),
# HTML help only options
htmlhelp_basename = ('pydoc', False),
Modified: doctools/trunk/sphinx/directives/desc.py
==============================================================================
--- doctools/trunk/sphinx/directives/desc.py (original)
+++ doctools/trunk/sphinx/directives/desc.py Thu Nov 6 10:10:57 2008
@@ -30,6 +30,8 @@
return _('%s (built-in variable)') % name
return _('%s (in module %s)') % (name, module)
elif desctype == 'class':
+ if not module:
+ return _('%s (built-in class)') % name
return _('%s (class in %s)') % (name, module)
elif desctype == 'exception':
return name
@@ -145,7 +147,7 @@
dlitem = nodes.list_item()
dlpar = nodes.paragraph()
dlpar += nodes.emphasis(obj, obj)
- dlpar += nodes.Text('', ' -- ')
+ dlpar += nodes.Text(' -- ', ' -- ')
dlpar += children
param_nodes[obj] = dlpar
dlitem += dlpar
Modified: doctools/trunk/sphinx/directives/other.py
==============================================================================
--- doctools/trunk/sphinx/directives/other.py (original)
+++ doctools/trunk/sphinx/directives/other.py Thu Nov 6 10:10:57 2008
@@ -229,13 +229,18 @@
def seealso_directive(name, arguments, options, content, lineno,
content_offset, block_text, state, state_machine):
- rv = make_admonition(
+ seealsonode = make_admonition(
addnodes.seealso, name, [_('See also')], options, content,
lineno, content_offset, block_text, state, state_machine)
- return rv
+ if arguments:
+ argnodes, msgs = state.inline_text(arguments[0], lineno)
+ para = nodes.paragraph()
+ para += argnodes
+ seealsonode[1:1] = [para] + msgs
+ return [seealsonode]
seealso_directive.content = 1
-seealso_directive.arguments = (0, 0, 0)
+seealso_directive.arguments = (0, 1, 1)
directives.register_directive('seealso', seealso_directive)
Modified: doctools/trunk/sphinx/htmlwriter.py
==============================================================================
--- doctools/trunk/sphinx/htmlwriter.py (original)
+++ doctools/trunk/sphinx/htmlwriter.py Thu Nov 6 10:10:57 2008
@@ -447,6 +447,13 @@
finally:
self.no_smarty -= 1
+ def visit_option(self, node):
+ self.no_smarty += 1
+ HTMLTranslator.visit_option(self, node)
+ def depart_option(self, node):
+ self.no_smarty -= 1
+ HTMLTranslator.depart_option(self, node)
+
def bulk_text_processor(self, text):
if self.no_smarty <= 0:
return sphinx_smarty_pants(text)
Modified: doctools/trunk/sphinx/latexwriter.py
==============================================================================
--- doctools/trunk/sphinx/latexwriter.py (original)
+++ doctools/trunk/sphinx/latexwriter.py Thu Nov 6 10:10:57 2008
@@ -1069,9 +1069,9 @@
pass
def visit_option_string(self, node):
- pass
- def depart_option_string(self, node):
- pass
+ ostring = node.astext()
+ self.body.append(self.encode(ostring.replace('--', u'--')))
+ raise nodes.SkipNode
def visit_description(self, node):
self.body.append( ' ' )
Modified: doctools/trunk/sphinx/texinputs/sphinx.sty
==============================================================================
--- doctools/trunk/sphinx/texinputs/sphinx.sty (original)
+++ doctools/trunk/sphinx/texinputs/sphinx.sty Thu Nov 6 10:10:57 2008
@@ -55,11 +55,10 @@
\fi\fi
% XeLaTeX can do colors, too
-\IfFileExists{ifxetex.sty}{\RequirePackage{ifxetex}}{}
-\ifx\ifxetex\undefined\else\ifxetex
+\ifx\XeTeXrevision\undefined\else
\def\py at NormalColor{\color[rgb]{0.0,0.0,0.0}}
\def\py at TitleColor{\color{TitleColor}}
-\fi\fi
+\fi
% Increase printable page size (copied from fullpage.sty)
\topmargin 0pt
Modified: doctools/trunk/sphinx/textwriter.py
==============================================================================
--- doctools/trunk/sphinx/textwriter.py (original)
+++ doctools/trunk/sphinx/textwriter.py Thu Nov 6 10:10:57 2008
@@ -284,6 +284,46 @@
def visit_label(self, node):
raise nodes.SkipNode
+ # XXX: option list could use some better styling
+
+ def visit_option_list(self, node):
+ pass
+ def depart_option_list(self, node):
+ pass
+
+ def visit_option_list_item(self, node):
+ self.new_state(0)
+ def depart_option_list_item(self, node):
+ self.end_state()
+
+ def visit_option_group(self, node):
+ self._firstoption = True
+ def depart_option_group(self, node):
+ self.add_text(' ')
+
+ def visit_option(self, node):
+ if self._firstoption:
+ self._firstoption = False
+ else:
+ self.add_text(', ')
+ def depart_option(self, node):
+ pass
+
+ def visit_option_string(self, node):
+ pass
+ def depart_option_string(self, node):
+ pass
+
+ def visit_option_argument(self, node):
+ self.add_text(node['delimiter'])
+ def depart_option_argument(self, node):
+ pass
+
+ def visit_description(self, node):
+ pass
+ def depart_description(self, node):
+ pass
+
def visit_tabular_col_spec(self, node):
raise nodes.SkipNode
Modified: doctools/trunk/sphinx/util/compat.py
==============================================================================
--- doctools/trunk/sphinx/util/compat.py (original)
+++ doctools/trunk/sphinx/util/compat.py Thu Nov 6 10:10:57 2008
@@ -33,5 +33,5 @@
classes = ['admonition-' + nodes.make_id(title_text)]
admonition_node['classes'] += classes
state.nested_parse(content, content_offset, admonition_node)
- return [admonition_node]
+ return admonition_node
Modified: doctools/trunk/sphinx/util/texescape.py
==============================================================================
--- doctools/trunk/sphinx/util/texescape.py (original)
+++ doctools/trunk/sphinx/util/texescape.py Thu Nov 6 10:10:57 2008
@@ -34,6 +34,8 @@
(u'±', ur'\(\pm\)'),
(u'→', ur'\(\rightarrow\)'),
(u'‣', ur'\(\rightarrow\)'),
+ # used to separate -- in options
+ (u'', ur'{}'),
# map some special Unicode characters to similar ASCII ones
(u'─', ur'-'),
(u'⎽', ur'\_'),
More information about the Python-checkins
mailing list