latex: Move ExtBabel to sphinx.builders.latex.util package

This commit is contained in:
Takeshi KOMIYA 2018-10-07 15:16:35 +09:00
parent 2b1512749a
commit 45d04703fe
5 changed files with 85 additions and 56 deletions

View File

@ -100,6 +100,7 @@ Deprecated
* ``sphinx.util.PeekableIterator``
* ``sphinx.util.pycompat.UnicodeMixin``
* ``sphinx.util.pycompat.u``
* ``sphinx.writers.latex.ExtBabel``
* ``sphinx.writers.latex.LaTeXTranslator._make_visit_admonition()``
* ``sphinx.writers.latex.LaTeXTranslator.babel_defmacro()``
* ``sphinx.writers.latex.LaTeXTranslator.collect_footnotes()``

View File

@ -394,6 +394,11 @@ The following is a list of deprecated interfaces.
- 4.0
- ``IndexBuilder.feed(docname, filename, title, doctree)``
* - ``sphinx.writers.latex.ExtBabel``
- 2.0
- 4.0
- ``sphinx.builders.latex.util.ExtBabel``
* - ``sphinx.writers.latex.LaTeXTranslator.babel_defmacro()``
- 2.0
- 4.0

View File

@ -11,7 +11,10 @@
"""
from sphinx.builders.latex.transforms import URI_SCHEMES, ShowUrlsTransform
from sphinx.deprecation import RemovedInSphinx30Warning, deprecated_alias
from sphinx.builders.latex.util import ExtBabel
from sphinx.deprecation import (
RemovedInSphinx30Warning, RemovedInSphinx40Warning, deprecated_alias
)
deprecated_alias('sphinx.writers.latex',
@ -20,3 +23,9 @@ deprecated_alias('sphinx.writers.latex',
'URI_SCHEMES': URI_SCHEMES,
},
RemovedInSphinx30Warning)
deprecated_alias('sphinx.writers.latex',
{
'ExtBabel': ExtBabel,
},
RemovedInSphinx40Warning)

View File

@ -0,0 +1,68 @@
"""
sphinx.builders.latex.util
~~~~~~~~~~~~~~~~~~~~~~~~~~
Utilities for LaTeX builder.
:copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
import warnings
from docutils.writers.latex2e import Babel
from sphinx.deprecation import RemovedInSphinx30Warning
class ExtBabel(Babel):
cyrillic_languages = ('bulgarian', 'kazakh', 'mongolian', 'russian', 'ukrainian')
def __init__(self, language_code, use_polyglossia=False):
# type: (str, bool) -> None
self.language_code = language_code
self.use_polyglossia = use_polyglossia
self.supported = True
super().__init__(language_code or '')
def get_shorthandoff(self):
# type: () -> str
warnings.warn('ExtBabel.get_shorthandoff() is deprecated.',
RemovedInSphinx30Warning, stacklevel=2)
from sphinx.writers.latex import SHORTHANDOFF
return SHORTHANDOFF
def uses_cyrillic(self):
# type: () -> bool
return self.language in self.cyrillic_languages
def is_supported_language(self):
# type: () -> bool
return self.supported
def language_name(self, language_code):
# type: (str) -> str
language = super().language_name(language_code)
if language == 'ngerman' and self.use_polyglossia:
# polyglossia calls new orthography (Neue Rechtschreibung) as
# german (with new spelling option).
return 'german'
elif not language:
self.supported = False
return 'english' # fallback to english
else:
return language
def get_mainlanguage_options(self):
# type: () -> str
"""Return options for polyglossia's ``\\setmainlanguage``."""
if self.use_polyglossia is False:
return None
elif self.language == 'german':
language = super().language_name(self.language_code)
if language == 'ngerman':
return 'spelling=new'
else:
return 'spelling=old'
else:
return None

View File

@ -19,7 +19,6 @@ from os import path
from typing import Iterable, cast
from docutils import nodes, writers
from docutils.writers.latex2e import Babel
from sphinx import addnodes
from sphinx import highlighting
@ -259,58 +258,6 @@ class LaTeXWriter(writers.Writer):
# Helper classes
class ExtBabel(Babel):
cyrillic_languages = ('bulgarian', 'kazakh', 'mongolian', 'russian', 'ukrainian')
def __init__(self, language_code, use_polyglossia=False):
# type: (str, bool) -> None
self.language_code = language_code
self.use_polyglossia = use_polyglossia
self.supported = True
super().__init__(language_code or '')
def get_shorthandoff(self):
# type: () -> str
warnings.warn('ExtBabel.get_shorthandoff() is deprecated.',
RemovedInSphinx30Warning, stacklevel=2)
return SHORTHANDOFF
def uses_cyrillic(self):
# type: () -> bool
return self.language in self.cyrillic_languages
def is_supported_language(self):
# type: () -> bool
return self.supported
def language_name(self, language_code):
# type: (str) -> str
language = super().language_name(language_code)
if language == 'ngerman' and self.use_polyglossia:
# polyglossia calls new orthography (Neue Rechtschreibung) as
# german (with new spelling option).
return 'german'
elif not language:
self.supported = False
return 'english' # fallback to english
else:
return language
def get_mainlanguage_options(self):
# type: () -> str
"""Return options for polyglossia's ``\\setmainlanguage``."""
if self.use_polyglossia is False:
return None
elif self.language == 'german':
language = super().language_name(self.language_code)
if language == 'ngerman':
return 'spelling=new'
else:
return 'spelling=old'
else:
return None
class Table:
"""A table data"""
@ -586,8 +533,7 @@ class LaTeXTranslator(SphinxTranslator):
'\\sffamily}\n\\ChTitleVar{\\Large'
'\\normalfont\\sffamily}')
self.babel = ExtBabel(self.config.language,
not self.elements['babel'])
self.babel = self.builder.babel
if self.config.language and not self.babel.is_supported_language():
# emit warning if specified language is invalid
# (only emitting, nothing changed to processing)