mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Remove use of deprecated APIs
This commit is contained in:
parent
30e51bf3ce
commit
a0e1390472
@ -62,11 +62,13 @@ class ChangesBuilder(Builder):
|
|||||||
libchanges = {} # type: Dict[str, List[Tuple[str, str, int]]]
|
libchanges = {} # type: Dict[str, List[Tuple[str, str, int]]]
|
||||||
apichanges = [] # type: List[Tuple[str, str, int]]
|
apichanges = [] # type: List[Tuple[str, str, int]]
|
||||||
otherchanges = {} # type: Dict[Tuple[str, str], List[Tuple[str, str, int]]]
|
otherchanges = {} # type: Dict[Tuple[str, str], List[Tuple[str, str, int]]]
|
||||||
if version not in self.env.versionchanges:
|
|
||||||
|
changesets = domain.get_changesets_for(version)
|
||||||
|
if not changesets:
|
||||||
logger.info(bold(__('no changes in version %s.') % version))
|
logger.info(bold(__('no changes in version %s.') % version))
|
||||||
return
|
return
|
||||||
logger.info(bold('writing summary file...'))
|
logger.info(bold('writing summary file...'))
|
||||||
for changeset in domain.get_changesets_for(version):
|
for changeset in changesets:
|
||||||
if isinstance(changeset.descname, tuple):
|
if isinstance(changeset.descname, tuple):
|
||||||
descname = changeset.descname[0]
|
descname = changeset.descname[0]
|
||||||
else:
|
else:
|
||||||
|
@ -253,11 +253,9 @@ class Autosummary(SphinxDirective):
|
|||||||
docname = posixpath.normpath(posixpath.join(dirname, docname))
|
docname = posixpath.normpath(posixpath.join(dirname, docname))
|
||||||
if docname not in self.env.found_docs:
|
if docname not in self.env.found_docs:
|
||||||
if excluded(self.env.doc2path(docname, None)):
|
if excluded(self.env.doc2path(docname, None)):
|
||||||
self.warn('toctree references excluded document %r'
|
logger.warning('toctree references excluded document %r' % docname)
|
||||||
% docname)
|
|
||||||
else:
|
else:
|
||||||
self.warn('toctree references unknown document %r'
|
logger.warning('toctree references unknown document %r' % docname)
|
||||||
% docname)
|
|
||||||
docnames.append(docname)
|
docnames.append(docname)
|
||||||
|
|
||||||
tocnode = addnodes.toctree()
|
tocnode = addnodes.toctree()
|
||||||
@ -290,7 +288,7 @@ class Autosummary(SphinxDirective):
|
|||||||
try:
|
try:
|
||||||
real_name, obj, parent, modname = import_by_name(name, prefixes=prefixes)
|
real_name, obj, parent, modname = import_by_name(name, prefixes=prefixes)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
self.warn('failed to import %s' % name)
|
logger.warning('failed to import %s' % name)
|
||||||
items.append((name, '', '', name))
|
items.append((name, '', '', name))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@ -305,11 +303,11 @@ class Autosummary(SphinxDirective):
|
|||||||
doccls = get_documenter(self.env.app, obj, parent)
|
doccls = get_documenter(self.env.app, obj, parent)
|
||||||
documenter = doccls(self.bridge, full_name)
|
documenter = doccls(self.bridge, full_name)
|
||||||
if not documenter.parse_name():
|
if not documenter.parse_name():
|
||||||
self.warn('failed to parse name %s' % real_name)
|
logger.warning('failed to parse name %s' % real_name)
|
||||||
items.append((display_name, '', '', real_name))
|
items.append((display_name, '', '', real_name))
|
||||||
continue
|
continue
|
||||||
if not documenter.import_object():
|
if not documenter.import_object():
|
||||||
self.warn('failed to import object %s' % real_name)
|
logger.warning('failed to import object %s' % real_name)
|
||||||
items.append((display_name, '', '', real_name))
|
items.append((display_name, '', '', real_name))
|
||||||
continue
|
continue
|
||||||
if documenter.options.members and not documenter.check_module():
|
if documenter.options.members and not documenter.check_module():
|
||||||
|
@ -194,7 +194,7 @@ _unicode_literals_re = re.compile(r'u(".*?")|u(\'.*?\')')
|
|||||||
def remove_unicode_literals(s):
|
def remove_unicode_literals(s):
|
||||||
# type: (str) -> str
|
# type: (str) -> str
|
||||||
warnings.warn('remove_unicode_literals() is deprecated.',
|
warnings.warn('remove_unicode_literals() is deprecated.',
|
||||||
RemovedInSphinx40Warning)
|
RemovedInSphinx40Warning, stacklevel=2)
|
||||||
return _unicode_literals_re.sub(lambda x: x.group(1) or x.group(2), s)
|
return _unicode_literals_re.sub(lambda x: x.group(1) or x.group(2), s)
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,7 +13,6 @@ from collections import namedtuple
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from sphinx.ext.apidoc import main as apidoc_main
|
from sphinx.ext.apidoc import main as apidoc_main
|
||||||
from sphinx.testing.util import remove_unicode_literals
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
@ -278,11 +277,10 @@ def test_multibyte_parameters(make_app, apidoc):
|
|||||||
assert (outdir / 'index.rst').isfile()
|
assert (outdir / 'index.rst').isfile()
|
||||||
|
|
||||||
conf_py = (outdir / 'conf.py').text()
|
conf_py = (outdir / 'conf.py').text()
|
||||||
conf_py_ = remove_unicode_literals(conf_py)
|
assert "project = 'プロジェクト名'" in conf_py
|
||||||
assert "project = 'プロジェクト名'" in conf_py_
|
assert "author = '著者名'" in conf_py
|
||||||
assert "author = '著者名'" in conf_py_
|
assert "version = 'バージョン'" in conf_py
|
||||||
assert "version = 'バージョン'" in conf_py_
|
assert "release = 'リリース'" in conf_py
|
||||||
assert "release = 'リリース'" in conf_py_
|
|
||||||
|
|
||||||
app = make_app('text', srcdir=outdir)
|
app = make_app('text', srcdir=outdir)
|
||||||
app.build()
|
app.build()
|
||||||
|
118
tests/test_io.py
118
tests/test_io.py
@ -1,118 +0,0 @@
|
|||||||
"""
|
|
||||||
test_sphinx_io
|
|
||||||
~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
Tests io modules.
|
|
||||||
|
|
||||||
:copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
|
|
||||||
:license: BSD, see LICENSE for details.
|
|
||||||
"""
|
|
||||||
|
|
||||||
from io import StringIO
|
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
from sphinx.io import SphinxRSTFileInput
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.sphinx(testroot='basic')
|
|
||||||
def test_SphinxRSTFileInput(app):
|
|
||||||
app.env.temp_data['docname'] = 'index'
|
|
||||||
|
|
||||||
# normal case
|
|
||||||
text = ('hello Sphinx world\n'
|
|
||||||
'Sphinx is a document generator')
|
|
||||||
source = SphinxRSTFileInput(app, app.env, source=StringIO(text),
|
|
||||||
source_path='dummy.rst', encoding='utf-8')
|
|
||||||
result = source.read()
|
|
||||||
assert result.data == ['hello Sphinx world',
|
|
||||||
'Sphinx is a document generator']
|
|
||||||
assert result.info(0) == ('dummy.rst', 0)
|
|
||||||
assert result.info(1) == ('dummy.rst', 1)
|
|
||||||
assert result.info(2) == ('dummy.rst', None) # out of range
|
|
||||||
|
|
||||||
# having rst_prolog ends without CR
|
|
||||||
app.env.config.rst_prolog = 'this is rst_prolog\nhello reST!'
|
|
||||||
source = SphinxRSTFileInput(app, app.env, source=StringIO(text),
|
|
||||||
source_path='dummy.rst', encoding='utf-8')
|
|
||||||
result = source.read()
|
|
||||||
assert result.data == ['this is rst_prolog',
|
|
||||||
'hello reST!',
|
|
||||||
'',
|
|
||||||
'hello Sphinx world',
|
|
||||||
'Sphinx is a document generator']
|
|
||||||
assert result.info(0) == ('<rst_prolog>', 0)
|
|
||||||
assert result.info(1) == ('<rst_prolog>', 1)
|
|
||||||
assert result.info(2) == ('<generated>', 0)
|
|
||||||
assert result.info(3) == ('dummy.rst', 0)
|
|
||||||
assert result.info(4) == ('dummy.rst', 1)
|
|
||||||
|
|
||||||
# having rst_prolog ends with CR
|
|
||||||
app.env.config.rst_prolog = 'this is rst_prolog\nhello reST!\n'
|
|
||||||
source = SphinxRSTFileInput(app, app.env, source=StringIO(text),
|
|
||||||
source_path='dummy.rst', encoding='utf-8')
|
|
||||||
result = source.read()
|
|
||||||
assert result.data == ['this is rst_prolog',
|
|
||||||
'hello reST!',
|
|
||||||
'',
|
|
||||||
'hello Sphinx world',
|
|
||||||
'Sphinx is a document generator']
|
|
||||||
|
|
||||||
# having docinfo and rst_prolog
|
|
||||||
docinfo_text = (':title: test of SphinxFileInput\n'
|
|
||||||
':author: Sphinx team\n'
|
|
||||||
'\n'
|
|
||||||
'hello Sphinx world\n'
|
|
||||||
'Sphinx is a document generator\n')
|
|
||||||
app.env.config.rst_prolog = 'this is rst_prolog\nhello reST!'
|
|
||||||
source = SphinxRSTFileInput(app, app.env, source=StringIO(docinfo_text),
|
|
||||||
source_path='dummy.rst', encoding='utf-8')
|
|
||||||
result = source.read()
|
|
||||||
assert result.data == [':title: test of SphinxFileInput',
|
|
||||||
':author: Sphinx team',
|
|
||||||
'',
|
|
||||||
'this is rst_prolog',
|
|
||||||
'hello reST!',
|
|
||||||
'',
|
|
||||||
'',
|
|
||||||
'hello Sphinx world',
|
|
||||||
'Sphinx is a document generator']
|
|
||||||
assert result.info(0) == ('dummy.rst', 0)
|
|
||||||
assert result.info(1) == ('dummy.rst', 1)
|
|
||||||
assert result.info(2) == ('<generated>', 0)
|
|
||||||
assert result.info(3) == ('<rst_prolog>', 0)
|
|
||||||
assert result.info(4) == ('<rst_prolog>', 1)
|
|
||||||
assert result.info(5) == ('<generated>', 0)
|
|
||||||
assert result.info(6) == ('dummy.rst', 2)
|
|
||||||
assert result.info(7) == ('dummy.rst', 3)
|
|
||||||
assert result.info(8) == ('dummy.rst', 4)
|
|
||||||
assert result.info(9) == ('dummy.rst', None) # out of range
|
|
||||||
|
|
||||||
# having rst_epilog
|
|
||||||
app.env.config.rst_prolog = None
|
|
||||||
app.env.config.rst_epilog = 'this is rst_epilog\ngood-bye reST!'
|
|
||||||
source = SphinxRSTFileInput(app, app.env, source=StringIO(text),
|
|
||||||
source_path='dummy.rst', encoding='utf-8')
|
|
||||||
result = source.read()
|
|
||||||
assert result.data == ['hello Sphinx world',
|
|
||||||
'Sphinx is a document generator',
|
|
||||||
'',
|
|
||||||
'this is rst_epilog',
|
|
||||||
'good-bye reST!']
|
|
||||||
assert result.info(0) == ('dummy.rst', 0)
|
|
||||||
assert result.info(1) == ('dummy.rst', 1)
|
|
||||||
assert result.info(2) == ('<generated>', 0)
|
|
||||||
assert result.info(3) == ('<rst_epilog>', 0)
|
|
||||||
assert result.info(4) == ('<rst_epilog>', 1)
|
|
||||||
assert result.info(5) == ('<rst_epilog>', None) # out of range
|
|
||||||
|
|
||||||
# expandtabs / convert whitespaces
|
|
||||||
app.env.config.rst_prolog = None
|
|
||||||
app.env.config.rst_epilog = None
|
|
||||||
text = ('\thello Sphinx world\n'
|
|
||||||
'\v\fSphinx is a document generator')
|
|
||||||
source = SphinxRSTFileInput(app, app.env, source=StringIO(text),
|
|
||||||
source_path='dummy.rst', encoding='utf-8')
|
|
||||||
result = source.read()
|
|
||||||
assert result.data == [' hello Sphinx world',
|
|
||||||
' Sphinx is a document generator']
|
|
@ -77,7 +77,7 @@ class ForgivingLaTeXTranslator(LaTeXTranslator, ForgivingTranslator):
|
|||||||
def verify_re_html(app, parse):
|
def verify_re_html(app, parse):
|
||||||
def verify(rst, html_expected):
|
def verify(rst, html_expected):
|
||||||
document = parse(rst)
|
document = parse(rst)
|
||||||
html_translator = ForgivingHTMLTranslator(app.builder, document)
|
html_translator = ForgivingHTMLTranslator(document, app.builder)
|
||||||
document.walkabout(html_translator)
|
document.walkabout(html_translator)
|
||||||
html_translated = ''.join(html_translator.fragment).strip()
|
html_translated = ''.join(html_translator.fragment).strip()
|
||||||
assert re.match(html_expected, html_translated), 'from ' + rst
|
assert re.match(html_expected, html_translated), 'from ' + rst
|
||||||
|
Loading…
Reference in New Issue
Block a user