diff --git a/CHANGES b/CHANGES index 613321268..794caa1ac 100644 --- a/CHANGES +++ b/CHANGES @@ -7,6 +7,7 @@ Bugs fixed * Fix line numbers was not shown on warnings in LaTeX and texinfo builders * Fix filenames were not shown on warnings of citations * Fix line numbers was not shown on warnings in LaTeX and texinfo builders +* Fix line numbers was not shown on warnings of indecies Release 1.3.4 (released Jan 12, 2016) ===================================== diff --git a/sphinx/environment.py b/sphinx/environment.py index 355901cc9..c65e6279d 100644 --- a/sphinx/environment.py +++ b/sphinx/environment.py @@ -38,7 +38,7 @@ from docutils.frontend import OptionParser from sphinx import addnodes from sphinx.util import url_re, get_matching_docs, docname_join, split_into, \ - FilenameUniqDict, get_figtype, import_object + FilenameUniqDict, get_figtype, import_object, split_index_msg from sphinx.util.nodes import clean_astext, make_refnode, WarningStream, is_translatable from sphinx.util.osutil import SEP, getcwd, fs_encoding from sphinx.util.i18n import find_catalog_files @@ -1123,7 +1123,14 @@ class BuildEnvironment: def note_indexentries_from(self, docname, document): entries = self.indexentries[docname] = [] for node in document.traverse(addnodes.index): - entries.extend(node['entries']) + try: + for type, value, tid, main in node['entries']: + split_index_msg(type, value) + except ValueError as exc: + self.warn_node(exc, node) + node.parent.remove(node) + else: + entries.extend(node['entries']) def note_citations_from(self, docname, document): for node in document.traverse(nodes.citation): diff --git a/sphinx/util/__init__.py b/sphinx/util/__init__.py index bd7f564f7..177098d1c 100644 --- a/sphinx/util/__init__.py +++ b/sphinx/util/__init__.py @@ -421,23 +421,21 @@ def split_into(n, type, value): def split_index_msg(type, value): # new entry types must be listed in directives/other.py! - result = [] - try: - if type == 'single': - try: - result = split_into(2, 'single', value) - except ValueError: - result = split_into(1, 'single', value) - elif type == 'pair': - result = split_into(2, 'pair', value) - elif type == 'triple': - result = split_into(3, 'triple', value) - elif type == 'see': - result = split_into(2, 'see', value) - elif type == 'seealso': - result = split_into(2, 'see', value) - except ValueError: - pass + if type == 'single': + try: + result = split_into(2, 'single', value) + except ValueError: + result = split_into(1, 'single', value) + elif type == 'pair': + result = split_into(2, 'pair', value) + elif type == 'triple': + result = split_into(3, 'triple', value) + elif type == 'see': + result = split_into(2, 'see', value) + elif type == 'seealso': + result = split_into(2, 'see', value) + else: + raise ValueError('invalid %s index entry %r' % (type, value)) return result diff --git a/tests/test_build_html.py b/tests/test_build_html.py index ef84bbcb4..34b987852 100644 --- a/tests/test_build_html.py +++ b/tests/test_build_html.py @@ -31,6 +31,7 @@ http://www.python.org/logo.png reading included file u'.*?wrongenc.inc' seems to be wrong, try giving an \ :encoding: option\\n? %(root)s/includes.txt:4: WARNING: download file not readable: .*?nonexisting.png +(%(root)s/markup.txt:351: WARNING: invalid single index entry u'')? (%(root)s/undecodable.txt:3: WARNING: undecodable source characters, replacing \ with "\\?": b?'here: >>>(\\\\|/)xbb<<<' )?""" @@ -39,9 +40,6 @@ HTML_WARNINGS = ENV_WARNINGS + """\ %(root)s/images.txt:20: WARNING: no matching candidate for image URI u'foo.\\*' %(root)s/footnote.txt:60: WARNING: citation not found: missing %(root)s/markup.txt:158: WARNING: unknown option: &option -%(root)s/markup.txt:: WARNING: invalid single index entry u'' -%(root)s/markup.txt:: WARNING: invalid pair index entry u'' -%(root)s/markup.txt:: WARNING: invalid pair index entry u'keyword; ' """ if PY3: @@ -376,7 +374,7 @@ def check_extra_entries(outdir): assert (outdir / 'robots.txt').isfile() -@gen_with_app(buildername='html', +@gen_with_app(buildername='html', freshenv=True, # use freshenv to check warnings confoverrides={'html_context.hckey_co': 'hcval_co'}, tags=['testtag']) def test_html_output(app, status, warning): diff --git a/tests/test_build_latex.py b/tests/test_build_latex.py index 509a19d4e..18e1063fb 100644 --- a/tests/test_build_latex.py +++ b/tests/test_build_latex.py @@ -27,15 +27,13 @@ LATEX_WARNINGS = ENV_WARNINGS + """\ %(root)s/markup.txt:158: WARNING: unknown option: &option %(root)s/footnote.txt:60: WARNING: citation not found: missing %(root)s/images.txt:20: WARNING: no matching candidate for image URI u'foo.\\*' -WARNING: invalid pair index entry u'' -WARNING: invalid pair index entry u'keyword; ' """ if PY3: LATEX_WARNINGS = remove_unicode_literals(LATEX_WARNINGS) -@with_app(buildername='latex') +@with_app(buildername='latex', freshenv=True) # use freshenv to check warnings def test_latex(app, status, warning): LaTeXTranslator.ignore_missing_images = True app.builder.build_all() @@ -94,7 +92,7 @@ def test_latex(app, status, warning): os.chdir(cwd) -@with_app(buildername='latex', +@with_app(buildername='latex', freshenv=True, # use freshenv to check warnings confoverrides={'latex_documents': [ ('contents', 'SphinxTests.tex', 'Sphinx Tests Documentation', 'Georg Brandl \\and someone else', 'howto'), diff --git a/tests/test_build_texinfo.py b/tests/test_build_texinfo.py index 9b264a3fb..65b873238 100644 --- a/tests/test_build_texinfo.py +++ b/tests/test_build_texinfo.py @@ -33,7 +33,7 @@ if PY3: TEXINFO_WARNINGS = remove_unicode_literals(TEXINFO_WARNINGS) -@with_app('texinfo') +@with_app('texinfo', freshenv=True) # use freshenv to check warnings def test_texinfo(app, status, warning): TexinfoTranslator.ignore_missing_images = True app.builder.build_all()