From 728e1904ec24784534f46fdaf652f0f539e39bad Mon Sep 17 00:00:00 2001
From: Georg Brandl
Date: Wed, 17 Jun 2009 08:48:19 +0200
Subject: [PATCH 1/7] Make check happy.
---
sphinx/__init__.py | 6 +++---
sphinx/builders/qthelp.py | 3 ++-
sphinx/ext/pngmath.py | 3 ++-
sphinx/util/pycompat.py | 3 ++-
sphinx/writers/latex.py | 14 ++++++++------
5 files changed, 17 insertions(+), 12 deletions(-)
diff --git a/sphinx/__init__.py b/sphinx/__init__.py
index 2d9ad8c3d..730d61c82 100644
--- a/sphinx/__init__.py
+++ b/sphinx/__init__.py
@@ -43,9 +43,9 @@ def main(argv=sys.argv):
'first.')
else:
whichmod += ' module'
- print >>sys.stderr, \
- 'Error: The %s cannot be found. Did you install Sphinx '\
- 'and its dependencies correctly?' % whichmod
+ print >>sys.stderr, ('Error: The %s cannot be found. '
+ 'Did you install Sphinx and its dependencies '
+ 'correctly?' % whichmod)
if hint:
print >> sys.stderr, hint
return 1
diff --git a/sphinx/builders/qthelp.py b/sphinx/builders/qthelp.py
index 1020bc186..62a55ee89 100644
--- a/sphinx/builders/qthelp.py
+++ b/sphinx/builders/qthelp.py
@@ -150,7 +150,8 @@ class QtHelpBuilder(StandaloneHTMLBuilder):
staticdir = path.join(outdir, '_static')
imagesdir = path.join(outdir, '_images')
for root, dirs, files in os.walk(outdir):
- resourcedir = root.startswith(staticdir) or root.startswith(imagesdir)
+ resourcedir = root.startswith(staticdir) or \
+ root.startswith(imagesdir)
for fn in files:
if (resourcedir and not fn.endswith('.js')) or \
fn.endswith('.html'):
diff --git a/sphinx/ext/pngmath.py b/sphinx/ext/pngmath.py
index cc6d9a9b3..8816e5bb9 100644
--- a/sphinx/ext/pngmath.py
+++ b/sphinx/ext/pngmath.py
@@ -237,7 +237,8 @@ def setup(app):
app.add_config_value('pngmath_dvipng', 'dvipng', 'html')
app.add_config_value('pngmath_latex', 'latex', 'html')
app.add_config_value('pngmath_use_preview', False, 'html')
- app.add_config_value('pngmath_dvipng_args', ['-gamma 1.5', '-D 110'], 'html')
+ app.add_config_value('pngmath_dvipng_args',
+ ['-gamma 1.5', '-D 110'], 'html')
app.add_config_value('pngmath_latex_args', [], 'html')
app.add_config_value('pngmath_latex_preamble', '', 'html')
app.connect('build-finished', cleanup_tempdir)
diff --git a/sphinx/util/pycompat.py b/sphinx/util/pycompat.py
index 137c35c87..49af46829 100644
--- a/sphinx/util/pycompat.py
+++ b/sphinx/util/pycompat.py
@@ -27,7 +27,8 @@ if sys.version_info < (2, 5):
# begin code copied from utf_8_sig.py in Python 2.6
def encode(input, errors='strict'):
- return (codecs.BOM_UTF8 + codecs.utf_8_encode(input, errors)[0], len(input))
+ return (codecs.BOM_UTF8 +
+ codecs.utf_8_encode(input, errors)[0], len(input))
def decode(input, errors='strict'):
prefix = 0
diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py
index 2ef92e244..1b6d4026f 100644
--- a/sphinx/writers/latex.py
+++ b/sphinx/writers/latex.py
@@ -633,13 +633,15 @@ class LaTeXTranslator(nodes.NodeVisitor):
if self.table.longtable:
self.body.append('\\hline\n')
self.body.append('\\endfirsthead\n\n')
- self.body.append('\multicolumn{%s}{c}%%\n' % self.table.colcount)
- self.body.append('{{\\bfseries \\tablename\\ \\thetable{} -- %s}} \\\\\n' % _('continued from previous page'))
- self.body.append('\\hline\n')
+ self.body.append('\\multicolumn{%s}{c}%%\n' % self.table.colcount)
+ self.body.append(r'{{\bfseries \tablename\ \thetable{} -- %s}} \\'
+ % _('continued from previous page'))
+ self.body.append('\n\\hline\n')
self.body.append('\\endhead\n\n')
- self.body.append('\\hline \multicolumn{%s}{|r|}{{%s}} \\\\ \\hline\n' % (
- self.table.colcount, _('Continued on next page')))
- self.body.append('\\endfoot\n\n')
+ self.body.append(r'\hline \multicolumn{%s}{|r|}{{%s}} \\ \hline'
+ % (self.table.colcount,
+ _('Continued on next page')))
+ self.body.append('\n\\endfoot\n\n')
self.body.append('\\hline\n')
self.body.append('\\endlastfoot\n\n')
else:
From f2b4f9a43a44aaab29aa19618b1ea2a748465ecc Mon Sep 17 00:00:00 2001
From: Georg Brandl
Date: Thu, 2 Jul 2009 19:41:25 +0200
Subject: [PATCH 2/7] Remove parsetree after collecting attributes.
---
sphinx/pycode/__init__.py | 1 +
1 file changed, 1 insertion(+)
diff --git a/sphinx/pycode/__init__.py b/sphinx/pycode/__init__.py
index de1c3dbe1..1187b6a43 100644
--- a/sphinx/pycode/__init__.py
+++ b/sphinx/pycode/__init__.py
@@ -234,6 +234,7 @@ class ModuleAnalyzer(object):
attr_visitor = AttrDocVisitor(number2name, scope, self.encoding)
attr_visitor.visit(self.parsetree)
self.attr_docs = attr_visitor.collected
+ self.parsetree = None
return attr_visitor.collected
def find_tags(self):
From 3e4599a4a1076864dbb9a037564f94907bbfdf1b Mon Sep 17 00:00:00 2001
From: Georg Brandl
Date: Thu, 2 Jul 2009 20:32:15 +0200
Subject: [PATCH 3/7] Add some exception guards for strange objects.
---
sphinx/ext/autodoc.py | 33 ++++++++++++++++++++++++---------
1 file changed, 24 insertions(+), 9 deletions(-)
diff --git a/sphinx/ext/autodoc.py b/sphinx/ext/autodoc.py
index 3d3782b83..c9a248a70 100644
--- a/sphinx/ext/autodoc.py
+++ b/sphinx/ext/autodoc.py
@@ -194,10 +194,21 @@ def between(marker, what=None, keepempty=False):
return process
+def safe_getattr(obj, name, *defargs):
+ try:
+ return getattr(obj, name, *defargs)
+ except Exception:
+ # this is a catch-all for all the weird things that some modules do
+ # with attribute access
+ if defargs:
+ return defargs[0]
+ raise AttributeError
+
+
def isdescriptor(x):
"""Check if the object is some kind of descriptor."""
for item in '__get__', '__set__', '__delete__':
- if hasattr(getattr(x, item, None), '__call__'):
+ if hasattr(safe_getattr(x, item, None), '__call__'):
return True
return False
@@ -235,7 +246,7 @@ class Documenter(object):
for typ, func in AutoDirective._special_attrgetters.iteritems():
if isinstance(obj, typ):
return func(obj, name, *defargs)
- return getattr(obj, name, *defargs)
+ return safe_getattr(obj, name, *defargs)
@classmethod
def can_document_member(cls, member, membername, isattr, parent):
@@ -725,11 +736,12 @@ class ModuleDocumenter(Documenter):
ret = []
for mname in memberlist:
try:
- ret.append((mname, getattr(self.object, mname)))
+ ret.append((mname, safe_getattr(self.object, mname)))
except AttributeError:
- self.directive.warn('missing attribute mentioned in :members: '
- 'or __all__: module %s, attribute %s' %
- (self.object.__name__, mname))
+ self.directive.warn(
+ 'missing attribute mentioned in :members: or __all__: '
+ 'module %s, attribute %s' % (
+ safe_getattr(self.object, '__name__', '???'), mname))
return False, ret
@@ -916,9 +928,12 @@ class ClassDocumenter(ModuleLevelDocumenter):
def add_content(self, more_content, no_docstring=False):
if self.doc_as_attr:
- content = ViewList(
- [_('alias of :class:`%s`') % self.object.__name__], source='')
- ModuleLevelDocumenter.add_content(self, content, no_docstring=True)
+ classname = safe_getattr(self.object, '__name__', None)
+ if classname:
+ content = ViewList(
+ [_('alias of :class:`%s`') % classname], source='')
+ ModuleLevelDocumenter.add_content(self, content,
+ no_docstring=True)
else:
ModuleLevelDocumenter.add_content(self, more_content)
From b809740f6613cf2810e8f935749b2beb456f1b95 Mon Sep 17 00:00:00 2001
From: Leandro Lucarella
Date: Thu, 9 Jul 2009 11:57:01 +0200
Subject: [PATCH 4/7] Fix sphinx.sty \includegraphics command redefinition
---
sphinx/ext/graphviz.py | 2 +-
sphinx/texinputs/sphinx.sty | 4 +++-
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/sphinx/ext/graphviz.py b/sphinx/ext/graphviz.py
index 6f365e30b..2dabd5e7e 100644
--- a/sphinx/ext/graphviz.py
+++ b/sphinx/ext/graphviz.py
@@ -169,7 +169,7 @@ def render_dot_latex(self, node, code, options, prefix='graphviz'):
raise nodes.SkipNode
if fname is not None:
- self.body.append('\\includegraphics[]{%s}' % fname)
+ self.body.append('\\includegraphics{%s}' % fname)
raise nodes.SkipNode
diff --git a/sphinx/texinputs/sphinx.sty b/sphinx/texinputs/sphinx.sty
index 8d88f0871..7525126e1 100644
--- a/sphinx/texinputs/sphinx.sty
+++ b/sphinx/texinputs/sphinx.sty
@@ -695,8 +695,10 @@
\image@width\wd\image@box%
\ifdim \image@width>\linewidth%
\setbox\image@box=\hbox{\py@Oldincludegraphics[width=\linewidth]{#2}}%
+ \box\image@box%
+ \else%
+ \py@Oldincludegraphics{#2}%
\fi%
- \box\image@box%
\else%
\py@Oldincludegraphics[#1]{#2}%
\fi%
From 536476287e1c4e4332cf160ade3b72150611a127 Mon Sep 17 00:00:00 2001
From: Georg Brandl
Date: Thu, 9 Jul 2009 11:59:52 +0200
Subject: [PATCH 5/7] Restore docutils compatibility.
---
sphinx/writers/html.py | 6 +++---
sphinx/writers/latex.py | 2 +-
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/sphinx/writers/html.py b/sphinx/writers/html.py
index 81df395bd..76c03c7b1 100644
--- a/sphinx/writers/html.py
+++ b/sphinx/writers/html.py
@@ -303,11 +303,11 @@ class HTMLTranslator(BaseTranslator):
if node['uri'].lower().endswith('svg') or \
node['uri'].lower().endswith('svgz'):
atts = {'data': node['uri'], 'type': 'image/svg+xml'}
- if 'width' in node:
+ if node.has_key('width'):
atts['width'] = node['width']
- if 'height' in node:
+ if node.has_key('height'):
atts['height'] = node['height']
- if 'align' in node:
+ if node.has_key('align'):
self.body.append('' %
(node['align'], node['align']))
self.context.append('
\n')
diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py
index 1b6d4026f..3ebdb3df2 100644
--- a/sphinx/writers/latex.py
+++ b/sphinx/writers/latex.py
@@ -254,7 +254,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
# ... and all others are the appendices
self.body.append('\n\\appendix\n')
self.first_document = -1
- if 'docname' in node:
+ if node.has_key('docname'):
self.body.append('\\hypertarget{--doc-%s}{}' % node['docname'])
# "- 1" because the level is increased before the title is visited
self.sectionlevel = self.top_sectionlevel - 1
From 852cdf6a2068f75639b557e9b2a4d036e4cc219e Mon Sep 17 00:00:00 2001
From: Georg Brandl
Date: Thu, 9 Jul 2009 12:01:44 +0200
Subject: [PATCH 6/7] Add a few changelog items.
---
CHANGES | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/CHANGES b/CHANGES
index b85924f86..8ba49d5f4 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,11 @@
Release 0.6.3 (in development)
==============================
+* #213: Fix centering of images in LaTeX output.
+
+* #211: Fix compatibility with docutils 0.5.
+
+
Release 0.6.2 (Jun 16, 2009)
============================
From 5569f89de24e86b37a050065a61f27217861b5f4 Mon Sep 17 00:00:00 2001
From: Georg Brandl
Date: Thu, 9 Jul 2009 12:08:42 +0200
Subject: [PATCH 7/7] #210: Fix nesting of HTML tags for displayed math from
pngmath extension.
---
CHANGES | 3 +++
sphinx/ext/pngmath.py | 5 ++---
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/CHANGES b/CHANGES
index 8ba49d5f4..13b096f4c 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,9 @@
Release 0.6.3 (in development)
==============================
+* #210: Fix nesting of HTML tags for displayed math from pngmath
+ extension.
+
* #213: Fix centering of images in LaTeX output.
* #211: Fix compatibility with docutils 0.5.
diff --git a/sphinx/ext/pngmath.py b/sphinx/ext/pngmath.py
index 8816e5bb9..b9353d7f5 100644
--- a/sphinx/ext/pngmath.py
+++ b/sphinx/ext/pngmath.py
@@ -223,12 +223,11 @@ def html_visit_displaymath(self, node):
self.body.append('(%s)' % node['number'])
if fname is None:
# something failed -- use text-only as a bad substitute
- self.body.append('%s' %
+ self.body.append('%s
\n' %
self.encode(node['latex']).strip())
else:
- self.body.append('
\n' %
+ self.body.append('
\n' %
(fname, self.encode(node['latex']).strip()))
- self.body.append('')
raise nodes.SkipNode