diff options
author | Georg Brandl <georg@python.org> | 2009-02-24 19:15:39 +0100 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2009-02-24 19:15:39 +0100 |
commit | 9ed275c868c97786c25668cd87ed3fbc8e862f15 (patch) | |
tree | 1b2aea56342f65c6bc202b9824ed7b2c93f583d0 | |
parent | fb511a015aa47c943c5dc1286f58743fca307b1c (diff) | |
download | sphinx-git-9ed275c868c97786c25668cd87ed3fbc8e862f15.tar.gz |
#109: fix circular import problems by moving exceptions into their own module.
-rw-r--r-- | sphinx/application.py | 43 | ||||
-rw-r--r-- | sphinx/builders/html.py | 2 | ||||
-rw-r--r-- | sphinx/cmdline.py | 3 | ||||
-rw-r--r-- | sphinx/environment.py | 2 | ||||
-rw-r--r-- | sphinx/errors.py | 48 | ||||
-rw-r--r-- | sphinx/ext/pngmath.py | 2 | ||||
-rw-r--r-- | sphinx/theming.py | 6 | ||||
-rw-r--r-- | sphinx/writers/latex.py | 2 |
8 files changed, 60 insertions, 48 deletions
diff --git a/sphinx/application.py b/sphinx/application.py index e82182258..76c8f3c96 100644 --- a/sphinx/application.py +++ b/sphinx/application.py @@ -19,47 +19,10 @@ from cStringIO import StringIO from docutils import nodes from docutils.parsers.rst import directives, roles -# Directive is either new-style or old-style -clstypes = (type, types.ClassType) - -# create the error classes before importing the rest of Sphinx, so that -# they can be imported in a circular fashion - -class SphinxError(Exception): - """ - Base class for Sphinx errors that are shown to the user in a nicer - way than normal exceptions. - """ - category = 'Sphinx error' - -class SphinxWarning(SphinxError): - """Raised for warnings if warnings are treated as errors.""" - category = 'Warning, treated as error' - -class ExtensionError(SphinxError): - """Raised if something's wrong with the configuration.""" - category = 'Extension error' - - def __init__(self, message, orig_exc=None): - super(ExtensionError, self).__init__(message) - self.orig_exc = orig_exc - - def __repr__(self): - if self.orig_exc: - return '%s(%r, %r)' % (self.__class__.__name__, - self.message, self.orig_exc) - return '%s(%r)' % (self.__class__.__name__, self.message) - - def __str__(self): - parent_str = super(ExtensionError, self).__str__() - if self.orig_exc: - return '%s (exception: %s)' % (parent_str, self.orig_exc) - return parent_str - - import sphinx from sphinx.roles import xfileref_role, innernodetypes from sphinx.config import Config +from sphinx.errors import SphinxError, SphinxWarning, ExtensionError from sphinx.builders import BUILTIN_BUILDERS from sphinx.directives import GenericDesc, Target, additional_xref_types from sphinx.environment import SphinxStandaloneReader @@ -68,6 +31,9 @@ from sphinx.util.compat import Directive, directive_dwim from sphinx.util.console import bold +# Directive is either new-style or old-style +clstypes = (type, types.ClassType) + # List of all known core events. Maps name to arguments description. events = { 'builder-inited': '', @@ -83,6 +49,7 @@ events = { CONFIG_FILENAME = 'conf.py' + class Sphinx(object): def __init__(self, srcdir, confdir, outdir, doctreedir, buildername, diff --git a/sphinx/builders/html.py b/sphinx/builders/html.py index 4a26eed86..6c2593ba1 100644 --- a/sphinx/builders/html.py +++ b/sphinx/builders/html.py @@ -31,10 +31,10 @@ from docutils.readers.doctree import Reader as DoctreeReader from sphinx import package_dir, __version__ from sphinx.util import SEP, os_path, relative_uri, ensuredir, \ movefile, ustrftime, copy_static_entry +from sphinx.errors import SphinxError from sphinx.search import js_index from sphinx.theming import Theme from sphinx.builders import Builder, ENV_PICKLE_FILENAME -from sphinx.application import SphinxError from sphinx.highlighting import PygmentsBridge from sphinx.util.console import bold from sphinx.writers.html import HTMLWriter, HTMLTranslator, \ diff --git a/sphinx/cmdline.py b/sphinx/cmdline.py index cd2c4008d..497c118ec 100644 --- a/sphinx/cmdline.py +++ b/sphinx/cmdline.py @@ -18,7 +18,8 @@ from os import path from docutils.utils import SystemMessage from sphinx import __version__ -from sphinx.application import Sphinx, SphinxError +from sphinx.errors import SphinxError +from sphinx.application import Sphinx from sphinx.util import Tee, format_exception_cut_frames, save_traceback from sphinx.util.console import darkred, nocolor, color_terminal diff --git a/sphinx/environment.py b/sphinx/environment.py index 6deea1d5d..de2b24306 100644 --- a/sphinx/environment.py +++ b/sphinx/environment.py @@ -44,8 +44,8 @@ from docutils.transforms.parts import ContentsFilter from sphinx import addnodes from sphinx.util import movefile, get_matching_docs, SEP, ustrftime, \ docname_join, FilenameUniqDict, url_re +from sphinx.errors import SphinxError from sphinx.directives import additional_xref_types -from sphinx.application import SphinxError default_settings = { 'embed_stylesheet': False, diff --git a/sphinx/errors.py b/sphinx/errors.py new file mode 100644 index 000000000..d9b8b6b87 --- /dev/null +++ b/sphinx/errors.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +""" + sphinx.errors + ~~~~~~~~~~~~~ + + Contains SphinxError and a few subclasses (in an extra module to avoid + circular import problems). + + :copyright: Copyright 2007-2009 by the Sphinx team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +class SphinxError(Exception): + """ + Base class for Sphinx errors that are shown to the user in a nicer + way than normal exceptions. + """ + category = 'Sphinx error' + + +class SphinxWarning(SphinxError): + """Raised for warnings if warnings are treated as errors.""" + category = 'Warning, treated as error' + + +class ExtensionError(SphinxError): + """Raised if something's wrong with the configuration.""" + category = 'Extension error' + + def __init__(self, message, orig_exc=None): + super(ExtensionError, self).__init__(message) + self.orig_exc = orig_exc + + def __repr__(self): + if self.orig_exc: + return '%s(%r, %r)' % (self.__class__.__name__, + self.message, self.orig_exc) + return '%s(%r)' % (self.__class__.__name__, self.message) + + def __str__(self): + parent_str = super(ExtensionError, self).__str__() + if self.orig_exc: + return '%s (exception: %s)' % (parent_str, self.orig_exc) + return parent_str + + +class ThemeError(SphinxError): + category = 'Theme error' diff --git a/sphinx/ext/pngmath.py b/sphinx/ext/pngmath.py index 1ec64639f..f779a64f8 100644 --- a/sphinx/ext/pngmath.py +++ b/sphinx/ext/pngmath.py @@ -22,9 +22,9 @@ except ImportError: from docutils import nodes +from sphinx.errors import SphinxError from sphinx.util import ensuredir from sphinx.util.png import read_png_depth, write_png_depth -from sphinx.application import SphinxError from sphinx.ext.mathbase import setup as mathbase_setup, wrap_displaymath class MathExtError(SphinxError): diff --git a/sphinx/theming.py b/sphinx/theming.py index e25498e14..97b052332 100644 --- a/sphinx/theming.py +++ b/sphinx/theming.py @@ -16,16 +16,12 @@ import tempfile import ConfigParser from os import path -from sphinx.application import SphinxError +from sphinx.errors import ThemeError NODEFAULT = object() THEMECONF = 'theme.conf' -class ThemeError(SphinxError): - category = 'Theme error' - - class Theme(object): """ Represents the theme chosen in the configuration. diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index 2ff242036..9954350f3 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -21,8 +21,8 @@ from docutils.writers.latex2e import Babel from sphinx import addnodes from sphinx import highlighting +from sphinx.errors import SphinxError from sphinx.locale import admonitionlabels, versionlabels -from sphinx.application import SphinxError from sphinx.util import ustrftime from sphinx.util.texescape import tex_escape_map from sphinx.util.smartypants import educateQuotesLatex |