diff options
Diffstat (limited to 'sphinx')
| -rw-r--r-- | sphinx/addnodes.py | 2 | ||||
| -rw-r--r-- | sphinx/cmdline.py | 102 | ||||
| -rw-r--r-- | sphinx/config.py | 2 | ||||
| -rw-r--r-- | sphinx/environment.py | 2 | ||||
| -rw-r--r-- | sphinx/ext/autosummary/__init__.py | 2 | ||||
| -rw-r--r-- | sphinx/ext/intersphinx.py | 2 | ||||
| -rw-r--r-- | sphinx/pycode/__init__.py | 2 | ||||
| -rw-r--r-- | sphinx/setup_command.py | 38 | ||||
| -rw-r--r-- | sphinx/themes/epub/layout.html | 11 | ||||
| -rw-r--r-- | sphinx/util/pycompat.py | 2 |
10 files changed, 76 insertions, 89 deletions
diff --git a/sphinx/addnodes.py b/sphinx/addnodes.py index c5ce4e296..124c9b6e4 100644 --- a/sphinx/addnodes.py +++ b/sphinx/addnodes.py @@ -14,7 +14,7 @@ import warnings from docutils import nodes -class translatable: +class translatable(object): """Node which supports translation. The translation goes forward with following steps: diff --git a/sphinx/cmdline.py b/sphinx/cmdline.py index baa797fff..ef80ed5b3 100644 --- a/sphinx/cmdline.py +++ b/sphinx/cmdline.py @@ -55,6 +55,56 @@ class MyFormatter(optparse.IndentedHelpFormatter): return "\n".join(result) +def handle_exception(app, opts, exception, stderr=sys.stderr): + if opts.pdb: + import pdb + print(red('Exception occurred while building, starting debugger:'), + file=stderr) + traceback.print_exc() + pdb.post_mortem(sys.exc_info()[2]) + else: + print(file=stderr) + if opts.verbosity or opts.traceback: + traceback.print_exc(None, stderr) + print(file=stderr) + if isinstance(exception, KeyboardInterrupt): + print('interrupted!', file=stderr) + elif isinstance(exception, SystemMessage): + print(red('reST markup error:'), file=stderr) + print(terminal_safe(exception.args[0]), file=stderr) + elif isinstance(exception, SphinxError): + print(red('%s:' % exception.category), file=stderr) + print(terminal_safe(text_type(exception)), file=stderr) + elif isinstance(exception, UnicodeError): + print(red('Encoding error:'), file=stderr) + print(terminal_safe(text_type(exception)), file=stderr) + tbpath = save_traceback(app) + print(red('The full traceback has been saved in %s, if you want ' + 'to report the issue to the developers.' % tbpath), + file=stderr) + elif isinstance(exception, RuntimeError) and 'recursion depth' in str(exception): + print(red('Recursion error:'), file=stderr) + print(terminal_safe(text_type(exception)), file=stderr) + print(file=stderr) + print('This can happen with very large or deeply nested source ' + 'files. You can carefully increase the default Python ' + 'recursion limit of 1000 in conf.py with e.g.:', file=stderr) + print(' import sys; sys.setrecursionlimit(1500)', file=stderr) + else: + print(red('Exception occurred:'), file=stderr) + print(format_exception_cut_frames().rstrip(), file=stderr) + tbpath = save_traceback(app) + print(red('The full traceback has been saved in %s, if you ' + 'want to report the issue to the developers.' % tbpath), + file=stderr) + print('Please also report this if it was a user error, so ' + 'that a better error message can be provided next time.', + file=stderr) + print('A bug report can be filed in the tracker at ' + '<https://github.com/sphinx-doc/sphinx/issues>. Thanks!', + file=stderr) + + def main(argv): if not color_terminal(): nocolor() @@ -243,52 +293,6 @@ def main(argv): opts.warningiserror, opts.tags, opts.verbosity, opts.jobs) app.build(opts.force_all, filenames) return app.statuscode - except (Exception, KeyboardInterrupt) as err: - if opts.pdb: - import pdb - print(red('Exception occurred while building, starting debugger:'), - file=error) - traceback.print_exc() - pdb.post_mortem(sys.exc_info()[2]) - else: - print(file=error) - if opts.verbosity or opts.traceback: - traceback.print_exc(None, error) - print(file=error) - if isinstance(err, KeyboardInterrupt): - print('interrupted!', file=error) - elif isinstance(err, SystemMessage): - print(red('reST markup error:'), file=error) - print(terminal_safe(err.args[0]), file=error) - elif isinstance(err, SphinxError): - print(red('%s:' % err.category), file=error) - print(terminal_safe(text_type(err)), file=error) - elif isinstance(err, UnicodeError): - print(red('Encoding error:'), file=error) - print(terminal_safe(text_type(err)), file=error) - tbpath = save_traceback(app) - print(red('The full traceback has been saved in %s, if you want ' - 'to report the issue to the developers.' % tbpath), - file=error) - elif isinstance(err, RuntimeError) and 'recursion depth' in str(err): - print(red('Recursion error:'), file=error) - print(terminal_safe(text_type(err)), file=error) - print(file=error) - print('This can happen with very large or deeply nested source ' - 'files. You can carefully increase the default Python ' - 'recursion limit of 1000 in conf.py with e.g.:', file=error) - print(' import sys; sys.setrecursionlimit(1500)', file=error) - else: - print(red('Exception occurred:'), file=error) - print(format_exception_cut_frames().rstrip(), file=error) - tbpath = save_traceback(app) - print(red('The full traceback has been saved in %s, if you ' - 'want to report the issue to the developers.' % tbpath), - file=error) - print('Please also report this if it was a user error, so ' - 'that a better error message can be provided next time.', - file=error) - print('A bug report can be filed in the tracker at ' - '<https://github.com/sphinx-doc/sphinx/issues>. Thanks!', - file=error) - return 1 + except (Exception, KeyboardInterrupt) as exc: + handle_exception(app, opts, exc, error) + return 1 diff --git a/sphinx/config.py b/sphinx/config.py index f22d03be6..fdf341268 100644 --- a/sphinx/config.py +++ b/sphinx/config.py @@ -34,7 +34,7 @@ CONFIG_TYPE_WARNING = "The config value `{name}' has type `{current.__name__}', "defaults to `{default.__name__}.'" -class ENUM: +class ENUM(object): """represents the config value should be a one of candidates. Example: diff --git a/sphinx/environment.py b/sphinx/environment.py index 7947838f4..61df10237 100644 --- a/sphinx/environment.py +++ b/sphinx/environment.py @@ -92,7 +92,7 @@ class NoUri(Exception): pass -class BuildEnvironment: +class BuildEnvironment(object): """ The environment in which the ReST files are translated. Stores an inventory of cross-file targets and provides doctree diff --git a/sphinx/ext/autosummary/__init__.py b/sphinx/ext/autosummary/__init__.py index 8e784b3fd..030fec301 100644 --- a/sphinx/ext/autosummary/__init__.py +++ b/sphinx/ext/autosummary/__init__.py @@ -137,7 +137,7 @@ def autosummary_table_visit_html(self, node): # -- autodoc integration ------------------------------------------------------- -class FakeDirective: +class FakeDirective(object): env = {} genopt = Options() diff --git a/sphinx/ext/intersphinx.py b/sphinx/ext/intersphinx.py index 6155c2e49..4ef7e4b9b 100644 --- a/sphinx/ext/intersphinx.py +++ b/sphinx/ext/intersphinx.py @@ -332,7 +332,7 @@ def missing_reference(app, env, node, contnode): proj, version, uri, dispname = inventory[objtype][target] if '://' not in uri and node.get('refdoc'): # get correct path in case of subdirectories - uri = path.join(relative_path(node['refdoc'], env.srcdir), uri) + uri = path.join(relative_path(node['refdoc'], '.'), uri) newnode = nodes.reference('', '', internal=False, refuri=uri, reftitle=_('(in %s v%s)') % (proj, version)) if node.get('refexplicit'): diff --git a/sphinx/pycode/__init__.py b/sphinx/pycode/__init__.py index 3da887d6c..7353eacdc 100644 --- a/sphinx/pycode/__init__.py +++ b/sphinx/pycode/__init__.py @@ -33,7 +33,7 @@ pydriver = driver.Driver(pygrammar, convert=nodes.convert) # an object with attributes corresponding to token and symbol names -class sym: +class sym(object): pass for k, v in iteritems(pygrammar.symbol2number): setattr(sym, k, v) diff --git a/sphinx/setup_command.py b/sphinx/setup_command.py index 7df8bd6e8..ffcd5ba70 100644 --- a/sphinx/setup_command.py +++ b/sphinx/setup_command.py @@ -15,15 +15,14 @@ from __future__ import print_function import sys import os -import traceback +from six import StringIO, string_types from distutils.cmd import Command from distutils.errors import DistutilsOptionError, DistutilsExecError -from six import StringIO, string_types - from sphinx.application import Sphinx -from sphinx.util.console import darkred, nocolor, color_terminal +from sphinx.cmdline import handle_exception +from sphinx.util.console import nocolor, color_terminal from sphinx.util.osutil import abspath @@ -99,6 +98,8 @@ class BuildDoc(Command): self.config_dir = None self.link_index = False self.copyright = '' + self.verbosity = 0 + self.traceback = False def _guess_source_dir(self): for guess in ('doc', 'docs'): @@ -162,32 +163,21 @@ class BuildDoc(Command): confoverrides['today'] = self.today if self.copyright: confoverrides['copyright'] = self.copyright - app = Sphinx(self.source_dir, self.config_dir, - self.builder_target_dir, self.doctree_dir, - self.builder, confoverrides, status_stream, - freshenv=self.fresh_env, - warningiserror=self.warning_is_error) try: + app = Sphinx(self.source_dir, self.config_dir, + self.builder_target_dir, self.doctree_dir, + self.builder, confoverrides, status_stream, + freshenv=self.fresh_env, + warningiserror=self.warning_is_error) app.build(force_all=self.all_files) if app.statuscode: raise DistutilsExecError( 'caused by %s builder.' % app.builder.name) - except Exception as err: - if self.pdb: - import pdb - print(darkred('Exception occurred while building, starting debugger:'), - file=sys.stderr) - traceback.print_exc() - pdb.post_mortem(sys.exc_info()[2]) - else: - from docutils.utils import SystemMessage - if isinstance(err, SystemMessage): - print(darkred('reST markup error:'), file=sys.stderr) - print(err.args[0].encode('ascii', 'backslashreplace'), - file=sys.stderr) - else: - raise + except Exception as exc: + handle_exception(app, self, exc, sys.stderr) + if not self.pdb: + raise SystemExit(1) if self.link_index: src = app.config.master_doc + app.builder.out_suffix diff --git a/sphinx/themes/epub/layout.html b/sphinx/themes/epub/layout.html index 541fcdba5..051d789c3 100644 --- a/sphinx/themes/epub/layout.html +++ b/sphinx/themes/epub/layout.html @@ -15,14 +15,7 @@ {# add only basic navigation links #} {% block sidebar1 %}{% endblock %} {% block sidebar2 %}{% endblock %} +{% block relbar1 %}{% endblock %} {% block relbar2 %}{% endblock %} {% block linktags %}{% endblock %} - -{# redefine relbar1 and footer to only call super if options are true #} -{%- block relbar1 %} -{% if theme_relbar1|tobool %}{{ super() }}{% endif %} -{%- endblock %} -{%- block footer %} -{% if theme_footer|tobool %}{{ super() }}{% endif %} -{%- endblock %} - +{% block footer %}{% endblock %} diff --git a/sphinx/util/pycompat.py b/sphinx/util/pycompat.py index 0f7980e82..6ff5e3567 100644 --- a/sphinx/util/pycompat.py +++ b/sphinx/util/pycompat.py @@ -55,7 +55,7 @@ if PY3: return text_type(tree) from html import escape as htmlescape # noqa: >= Python 3.2 - class UnicodeMixin: + class UnicodeMixin(object): """Mixin class to handle defining the proper __str__/__unicode__ methods in Python 2 or 3.""" |
