Make the _ gettext alias an explicit import instead of installing into builtins.

This commit is contained in:
Georg Brandl 2010-01-17 19:33:23 +01:00
parent 1bce0d7e6a
commit 98bcd2fab4
23 changed files with 30 additions and 24 deletions

View File

@ -15,6 +15,7 @@ from cgi import escape
from sphinx import package_dir from sphinx import package_dir
from sphinx.util import copy_static_entry from sphinx.util import copy_static_entry
from sphinx.locale import _
from sphinx.theming import Theme from sphinx.theming import Theme
from sphinx.builders import Builder from sphinx.builders import Builder
from sphinx.util.osutil import ensuredir, os_path from sphinx.util.osutil import ensuredir, os_path

View File

@ -11,10 +11,7 @@
:license: BSD, see LICENSE for details. :license: BSD, see LICENSE for details.
""" """
import os
import re import re
import cgi
import sys
from os import path from os import path
from docutils import nodes from docutils import nodes

View File

@ -36,6 +36,7 @@ from sphinx.util.nodes import inline_all_toctrees
from sphinx.util.matching import patmatch, compile_matchers from sphinx.util.matching import patmatch, compile_matchers
from sphinx.util.pycompat import any from sphinx.util.pycompat import any
from sphinx.errors import SphinxError from sphinx.errors import SphinxError
from sphinx.locale import _
from sphinx.search import js_index from sphinx.search import js_index
from sphinx.theming import Theme from sphinx.theming import Theme
from sphinx.builders import Builder from sphinx.builders import Builder

View File

@ -18,6 +18,7 @@ from os import path
from docutils import nodes from docutils import nodes
from sphinx import addnodes from sphinx import addnodes
from sphinx.locale import _
from sphinx.builders.html import StandaloneHTMLBuilder from sphinx.builders.html import StandaloneHTMLBuilder

View File

@ -19,6 +19,7 @@ from docutils.frontend import OptionParser
from sphinx import package_dir, addnodes from sphinx import package_dir, addnodes
from sphinx.util import texescape from sphinx.util import texescape
from sphinx.locale import _
from sphinx.builders import Builder from sphinx.builders import Builder
from sphinx.environment import NoUri from sphinx.environment import NoUri
from sphinx.util.nodes import inline_all_toctrees from sphinx.util.nodes import inline_all_toctrees

View File

@ -18,6 +18,7 @@ from os import path
from docutils import nodes from docutils import nodes
from sphinx import addnodes from sphinx import addnodes
from sphinx.locale import _
from sphinx.builders.html import StandaloneHTMLBuilder from sphinx.builders.html import StandaloneHTMLBuilder
_idpattern = re.compile( _idpattern = re.compile(
@ -233,7 +234,7 @@ class QtHelpBuilder(StandaloneHTMLBuilder):
shortname = shortname[:-2] shortname = shortname[:-2]
id = '%s.%s' % (id, shortname) id = '%s.%s' % (id, shortname)
else: else:
id = descr = None id = None
if id: if id:
item = ' '*12 + '<keyword name="%s" id="%s" ref="%s"/>' % ( item = ' '*12 + '<keyword name="%s" id="%s" ref="%s"/>' % (

View File

@ -11,7 +11,7 @@ from docutils import nodes
from docutils.parsers.rst import Directive, directives from docutils.parsers.rst import Directive, directives
from sphinx import addnodes from sphinx import addnodes
from sphinx.locale import pairindextypes from sphinx.locale import pairindextypes, _
from sphinx.util import url_re, docname_join from sphinx.util import url_re, docname_join
from sphinx.util.nodes import explicit_title_re from sphinx.util.nodes import explicit_title_re
from sphinx.util.compat import make_admonition from sphinx.util.compat import make_admonition

View File

@ -16,7 +16,7 @@ from docutils import nodes
from sphinx import addnodes from sphinx import addnodes
from sphinx.roles import XRefRole from sphinx.roles import XRefRole
from sphinx.locale import l_ from sphinx.locale import l_, _
from sphinx.domains import Domain, ObjType from sphinx.domains import Domain, ObjType
from sphinx.directives import ObjectDescription from sphinx.directives import ObjectDescription
from sphinx.util.nodes import make_refnode from sphinx.util.nodes import make_refnode

View File

@ -16,7 +16,7 @@ from docutils.parsers.rst import directives
from sphinx import addnodes from sphinx import addnodes
from sphinx.roles import XRefRole from sphinx.roles import XRefRole
from sphinx.locale import l_ from sphinx.locale import l_, _
from sphinx.domains import Domain, ObjType from sphinx.domains import Domain, ObjType
from sphinx.directives import ObjectDescription from sphinx.directives import ObjectDescription
from sphinx.util.nodes import make_refnode from sphinx.util.nodes import make_refnode

View File

@ -16,7 +16,7 @@ from docutils.parsers.rst import directives
from sphinx import addnodes from sphinx import addnodes
from sphinx.roles import XRefRole from sphinx.roles import XRefRole
from sphinx.locale import l_ from sphinx.locale import l_, _
from sphinx.domains import Domain, ObjType from sphinx.domains import Domain, ObjType
from sphinx.directives import ObjectDescription from sphinx.directives import ObjectDescription
from sphinx.util import ws_re from sphinx.util import ws_re

View File

@ -40,6 +40,7 @@ from sphinx.util.nodes import clean_astext, make_refnode
from sphinx.util.osutil import movefile, SEP, ustrftime from sphinx.util.osutil import movefile, SEP, ustrftime
from sphinx.util.matching import compile_matchers from sphinx.util.matching import compile_matchers
from sphinx.errors import SphinxError, ExtensionError from sphinx.errors import SphinxError, ExtensionError
from sphinx.locale import _
orig_role_function = roles.role orig_role_function = roles.role

View File

@ -21,6 +21,7 @@ from docutils.utils import assemble_option_dict
from docutils.statemachine import ViewList from docutils.statemachine import ViewList
from sphinx.util import rpartition, force_decode from sphinx.util import rpartition, force_decode
from sphinx.locale import _
from sphinx.pycode import ModuleAnalyzer, PycodeError from sphinx.pycode import ModuleAnalyzer, PycodeError
from sphinx.application import ExtensionError from sphinx.application import ExtensionError
from sphinx.util.nodes import nested_parse_with_titles from sphinx.util.nodes import nested_parse_with_titles
@ -868,7 +869,6 @@ class ClassDocumenter(ModuleLevelDocumenter):
return ret return ret
def format_args(self): def format_args(self):
args = None
# for classes, the relevant signature is the __init__ method's # for classes, the relevant signature is the __init__ method's
initmeth = self.get_attr(self.object, '__init__', None) initmeth = self.get_attr(self.object, '__init__', None)
# classes without __init__ method, default __init__ or # classes without __init__ method, default __init__ or

View File

@ -63,7 +63,7 @@ from docutils.parsers.rst import directives
from docutils.statemachine import ViewList from docutils.statemachine import ViewList
from docutils import nodes from docutils import nodes
from sphinx import addnodes, roles from sphinx import addnodes
from sphinx.util.compat import Directive from sphinx.util.compat import Directive
@ -192,7 +192,6 @@ class Autosummary(Directive):
if 'toctree' in self.options: if 'toctree' in self.options:
suffix = env.config.source_suffix suffix = env.config.source_suffix
all_docnames = env.found_docs.copy()
dirname = posixpath.dirname(env.docname) dirname = posixpath.dirname(env.docname)
tree_prefix = self.options['toctree'].strip() tree_prefix = self.options['toctree'].strip()

View File

@ -96,7 +96,7 @@ class InheritanceGraph(object):
# two possibilities: either it is a module, then import it # two possibilities: either it is a module, then import it
try: try:
module = __import__(fullname) __import__(fullname)
todoc = sys.modules[fullname] todoc = sys.modules[fullname]
except ImportError: except ImportError:
# else it is a class, then import the module # else it is a class, then import the module
@ -109,7 +109,7 @@ class InheritanceGraph(object):
'Could not import class %r specified for ' 'Could not import class %r specified for '
'inheritance diagram' % base) 'inheritance diagram' % base)
try: try:
module = __import__(path) __import__(path)
todoc = getattr(sys.modules[path], base) todoc = getattr(sys.modules[path], base)
except (ImportError, AttributeError): except (ImportError, AttributeError):
raise InheritanceException( raise InheritanceException(

View File

@ -14,6 +14,7 @@
from docutils import nodes from docutils import nodes
from sphinx.locale import _
from sphinx.environment import NoUri from sphinx.environment import NoUri
from sphinx.util.compat import Directive, make_admonition from sphinx.util.compat import Directive, make_admonition

View File

@ -12,6 +12,7 @@
from docutils import nodes from docutils import nodes
from sphinx import addnodes from sphinx import addnodes
from sphinx.locale import _
from sphinx.pycode import ModuleAnalyzer from sphinx.pycode import ModuleAnalyzer
from sphinx.util.nodes import make_refnode from sphinx.util.nodes import make_refnode

View File

@ -11,8 +11,6 @@
import gettext import gettext
import UserString import UserString
from sphinx import package_dir
class _TranslationProxy(UserString.UserString, object): class _TranslationProxy(UserString.UserString, object):
"""Class for proxy strings from gettext translations. This is a helper """Class for proxy strings from gettext translations. This is a helper
@ -163,10 +161,14 @@ pairindextypes = {
'builtin': l_('built-in function'), 'builtin': l_('built-in function'),
} }
translator = None
def _(message):
return translator.gettext(message)
def init(locale_dirs, language): def init(locale_dirs, language):
global translator
# the None entry is the system's default locale path # the None entry is the system's default locale path
translator = None
has_translation = True has_translation = True
for dir_ in locale_dirs: for dir_ in locale_dirs:
try: try:
@ -182,5 +184,4 @@ def init(locale_dirs, language):
if translator is None: if translator is None:
translator = gettext.NullTranslations() translator = gettext.NullTranslations()
has_translation = False has_translation = False
translator.install(unicode=True)
return translator, has_translation return translator, has_translation

View File

@ -16,7 +16,7 @@ fallback token code OP, but the parser needs the actual token code.
import pickle import pickle
# Local imports # Local imports
from sphinx.pycode.pgen2 import token, tokenize from sphinx.pycode.pgen2 import token
class Grammar(object): class Grammar(object):

View File

@ -157,9 +157,9 @@ class ParserGenerator(object):
#self.dump_nfa(name, a, z) #self.dump_nfa(name, a, z)
dfa = self.make_dfa(a, z) dfa = self.make_dfa(a, z)
#self.dump_dfa(name, dfa) #self.dump_dfa(name, dfa)
oldlen = len(dfa) #oldlen = len(dfa)
self.simplify_dfa(dfa) self.simplify_dfa(dfa)
newlen = len(dfa) #newlen = len(dfa)
dfas[name] = dfa dfas[name] = dfa
#print name, oldlen, newlen #print name, oldlen, newlen
if startsymbol is None: if startsymbol is None:

View File

@ -16,6 +16,7 @@ from docutils import nodes, utils
from docutils.parsers.rst import roles from docutils.parsers.rst import roles
from sphinx import addnodes from sphinx import addnodes
from sphinx.locale import _
from sphinx.util import ws_re from sphinx.util import ws_re
from sphinx.util.nodes import split_explicit_title from sphinx.util.nodes import split_explicit_title
@ -105,7 +106,7 @@ class XRefRole(object):
# if the first character is a bang, don't cross-reference at all # if the first character is a bang, don't cross-reference at all
if text[0:1] == '!': if text[0:1] == '!':
if self.fix_parens: if self.fix_parens:
text, _ = self._fix_parens(env, False, text[1:], "") text, tgt = self._fix_parens(env, False, text[1:], "")
innernode = self.innernodeclass(rawtext, text, classes=['xref']) innernode = self.innernodeclass(rawtext, text, classes=['xref'])
return self.result_nodes(inliner.document, env, innernode, return self.result_nodes(inliner.document, env, innernode,
is_ref=False) is_ref=False)

View File

@ -16,7 +16,7 @@ import os
from docutils import nodes from docutils import nodes
from docutils.writers.html4css1 import Writer, HTMLTranslator as BaseTranslator from docutils.writers.html4css1 import Writer, HTMLTranslator as BaseTranslator
from sphinx.locale import admonitionlabels, versionlabels from sphinx.locale import admonitionlabels, versionlabels, _
from sphinx.util.smartypants import sphinx_smarty_pants from sphinx.util.smartypants import sphinx_smarty_pants
try: try:

View File

@ -22,7 +22,7 @@ from docutils.writers.latex2e import Babel
from sphinx import addnodes from sphinx import addnodes
from sphinx import highlighting from sphinx import highlighting
from sphinx.errors import SphinxError from sphinx.errors import SphinxError
from sphinx.locale import admonitionlabels, versionlabels from sphinx.locale import admonitionlabels, versionlabels, _
from sphinx.util.osutil import ustrftime from sphinx.util.osutil import ustrftime
from sphinx.util.texescape import tex_escape_map from sphinx.util.texescape import tex_escape_map
from sphinx.util.smartypants import educateQuotesLatex from sphinx.util.smartypants import educateQuotesLatex

View File

@ -15,7 +15,7 @@ import textwrap
from docutils import nodes, writers from docutils import nodes, writers
from sphinx import addnodes from sphinx import addnodes
from sphinx.locale import admonitionlabels, versionlabels from sphinx.locale import admonitionlabels, versionlabels, _
class TextWriter(writers.Writer): class TextWriter(writers.Writer):