# Buggy code
def validate_config_values(app):
    if app.config.latex_toplevel_sectioning not in (None, "part", "chapter", "section"):
        app.warn(
            "invalid latex_toplevel_sectioning, ignored: %s"
            % app.config.latex_toplevel_sectioning
        )
        app.config.latex_toplevel_sectioning = None

    if app.config.latex_use_parts:
        if app.config.latex_toplevel_sectioning:
            app.warn(
                "latex_use_parts conflicts with latex_toplevel_sectioning, ignored."
            )
        else:
            app.warn(
                "latex_use_parts is deprecated. Use latex_toplevel_sectioning instead."
            )
            app.config.latex_toplevel_sectioning = "parts"

    if app.config.latex_use_modindex is not True:  # changed by user
        app.warn("latex_use_modindex is deprecated. Use latex_domain_indices instead.")

    if app.config.latex_preamble:
        if app.config.latex_elements.get("preamble"):
            app.warn(
                "latex_preamble conflicts with latex_elements['preamble'], ignored."
            )
        else:
            app.warn(
                "latex_preamble is deprecated. Use latex_elements['preamble'] instead."
            )
            app.config.latex_elements["preamble"] = app.config.latex_preamble

    if app.config.latex_paper_size != "letter":
        if app.config.latex_elements.get("papersize"):
            app.warn(
                "latex_paper_size conflicts with latex_elements['papersize'], ignored."
            )
        else:
            app.warn(
                "latex_paper_size is deprecated. "
                "Use latex_elements['papersize'] instead."
            )
            if app.config.latex_paper_size:
                app.config.latex_elements["papersize"] = (
                    app.config.latex_paper_size + "paper"
                )

    if app.config.latex_font_size != "10pt":
        if app.config.latex_elements.get("pointsize"):
            app.warn(
                "latex_font_size conflicts with latex_elements['pointsize'], ignored."
            )
        else:
            app.warn(
                "latex_font_size is deprecated. Use latex_elements['pointsize'] instead."
            )
            app.config.latex_elements["pointsize"] = app.config.latex_font_size

    if "footer" in app.config.latex_elements:
        if "postamble" in app.config.latex_elements:
            app.warn(
                "latex_elements['footer'] conflicts with "
                "latex_elements['postamble'], ignored."
            )
        else:
            app.warn(
                "latex_elements['footer'] is deprecated. "
                "Use latex_elements['preamble'] instead."
            )
            app.config.latex_elements["postamble"] = app.config.latex_elements["footer"]


# Traceback (ValueError)
# Sphinx version: 1.5
# Python version: 2.7.12 (CPython)
# Docutils version: 0.13.1 release
# Jinja2 version: 2.8
# Last messages:
#   api-kivy.uix.textinput
#   api-kivy.uix.togglebutton
#   api-kivy.uix.treeview
#   api-kivy.uix.video
#   api-kivy.uix.videoplayer
#   api-kivy.uix.vkeyboard
#   api-kivy.uix.widget
#
#   resolving references...
#   writing...
# Loaded extensions:
#   sphinx.domains.cpp (unknown version) from /usr/local/lib/python2.7/dist-packages/sphinx/domains/cpp.pyc
#   sphinx.builders.applehelp (unknown version) from /usr/local/lib/python2.7/dist-packages/sphinx/builders/applehelp.pyc
#   sphinx.ext.mathjax (1.5) from /usr/local/lib/python2.7/dist-packages/sphinx/ext/mathjax.pyc
#   sphinx.directives (unknown version) from /usr/local/lib/python2.7/dist-packages/sphinx/directives/__init__.pyc
#   sphinx.builders.changes (unknown version) from /usr/local/lib/python2.7/dist-packages/sphinx/builders/changes.pyc
#   sphinx.builders.websupport (unknown version) from /usr/local/lib/python2.7/dist-packages/sphinx/builders/websupport.pyc
#   sphinx.domains.c (unknown version) from /usr/local/lib/python2.7/dist-packages/sphinx/domains/c.pyc
#   sphinx.builders.dummy (unknown version) from /usr/local/lib/python2.7/dist-packages/sphinx/builders/dummy.pyc
#   sphinx.builders.texinfo (unknown version) from /usr/local/lib/python2.7/dist-packages/sphinx/builders/texinfo.pyc
#   sphinx.builders.epub (unknown version) from /usr/local/lib/python2.7/dist-packages/sphinx/builders/epub.pyc
#   sphinx.builders.linkcheck (unknown version) from /usr/local/lib/python2.7/dist-packages/sphinx/builders/linkcheck.pyc
#   sphinx.ext.viewcode (1.5) from /usr/local/lib/python2.7/dist-packages/sphinx/ext/viewcode.pyc
#   sphinx.domains.std (unknown version) from /usr/local/lib/python2.7/dist-packages/sphinx/domains/std.pyc
#   sphinx.directives.other (unknown version) from /usr/local/lib/python2.7/dist-packages/sphinx/directives/other.pyc
#   sphinx.builders.epub3 (unknown version) from /usr/local/lib/python2.7/dist-packages/sphinx/builders/epub3.pyc
#   preprocess (unknown version) from /media/usradm/brzdc7900_N/kivyptbr/doc/sources/sphinxext/preprocess.pyc
#   sphinx.ext.todo (1.5) from /usr/local/lib/python2.7/dist-packages/sphinx/ext/todo.pyc
#   sphinx.domains.javascript (unknown version) from /usr/local/lib/python2.7/dist-packages/sphinx/domains/javascript.pyc
#   sphinx.directives.code (unknown version) from /usr/local/lib/python2.7/dist-packages/sphinx/directives/code.pyc
#   alabaster (0.7.9) from /usr/local/lib/python2.7/dist-packages/alabaster/__init__.pyc
#   sphinx.builders.text (unknown version) from /usr/local/lib/python2.7/dist-packages/sphinx/builders/text.pyc
#   sphinx.builders.qthelp (unknown version) from /usr/local/lib/python2.7/dist-packages/sphinx/builders/qthelp.pyc
#   autodoc (unknown version) from /media/usradm/brzdc7900_N/kivyptbr/doc/sources/sphinxext/autodoc.pyc
#   sphinx.roles (unknown version) from /usr/local/lib/python2.7/dist-packages/sphinx/roles.pyc
#   sphinx.builders.htmlhelp (unknown version) from /usr/local/lib/python2.7/dist-packages/sphinx/builders/htmlhelp.pyc
#   sphinx.directives.patches (unknown version) from /usr/local/lib/python2.7/dist-packages/sphinx/directives/patches.pyc
#   sphinx.ext.ifconfig (1.5) from /usr/local/lib/python2.7/dist-packages/sphinx/ext/ifconfig.pyc
#   sphinx.builders.latex (unknown version) from /usr/local/lib/python2.7/dist-packages/sphinx/builders/latex.pyc
#   sphinx.builders.html (unknown version) from /usr/local/lib/python2.7/dist-packages/sphinx/builders/html.pyc
#   sphinx.builders.devhelp (unknown version) from /usr/local/lib/python2.7/dist-packages/sphinx/builders/devhelp.pyc
#   sphinx.builders.gettext (unknown version) from /usr/local/lib/python2.7/dist-packages/sphinx/builders/gettext.pyc
#   sphinx.builders.xml (unknown version) from /usr/local/lib/python2.7/dist-packages/sphinx/builders/xml.pyc
#   sphinx.builders.manpage (unknown version) from /usr/local/lib/python2.7/dist-packages/sphinx/builders/manpage.pyc
#   sphinx.domains.rst (unknown version) from /usr/local/lib/python2.7/dist-packages/sphinx/domains/rst.pyc
#   sphinx.domains.python (unknown version) from /usr/local/lib/python2.7/dist-packages/sphinx/domains/python.pyc
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/sphinx/cmdline.py", line 296, in main
app.build(opts.force_all, filenames)
File "/usr/local/lib/python2.7/dist-packages/sphinx/application.py", line 333, in build
self.builder.build_update()
File "/usr/local/lib/python2.7/dist-packages/sphinx/builders/__init__.py", line 246, in build_update
self.build(['__all__'], to_build)
File "/usr/local/lib/python2.7/dist-packages/sphinx/builders/__init__.py", line 322, in build
self.write(docnames, list(updated_docnames), method)
File "/usr/local/lib/python2.7/dist-packages/sphinx/builders/latex.py", line 130, in write
docwriter.write(doctree, destination)
File "/usr/local/lib/python2.7/dist-packages/docutils/writers/__init__.py", line 80, in write
self.translate()
File "/usr/local/lib/python2.7/dist-packages/sphinx/writers/latex.py", line 159, in translate
visitor = self.translator_class(self.document, self.builder)
File "/usr/local/lib/python2.7/dist-packages/sphinx/writers/latex.py", line 366, in __init__
self.sectionnames.index(builder.config.latex_toplevel_sectioning)
ValueError: 'parts' is not in list

# Fixed code
def validate_config_values(app):
    if app.config.latex_toplevel_sectioning not in (None, "part", "chapter", "section"):
        app.warn(
            "invalid latex_toplevel_sectioning, ignored: %s"
            % app.config.latex_toplevel_sectioning
        )
        app.config.latex_toplevel_sectioning = None

    if app.config.latex_use_parts:
        if app.config.latex_toplevel_sectioning:
            app.warn(
                "latex_use_parts conflicts with latex_toplevel_sectioning, ignored."
            )
        else:
            app.warn(
                "latex_use_parts is deprecated. Use latex_toplevel_sectioning instead."
            )
            app.config.latex_toplevel_sectioning = "part"

    if app.config.latex_use_modindex is not True:  # changed by user
        app.warn("latex_use_modindex is deprecated. Use latex_domain_indices instead.")

    if app.config.latex_preamble:
        if app.config.latex_elements.get("preamble"):
            app.warn(
                "latex_preamble conflicts with latex_elements['preamble'], ignored."
            )
        else:
            app.warn(
                "latex_preamble is deprecated. Use latex_elements['preamble'] instead."
            )
            app.config.latex_elements["preamble"] = app.config.latex_preamble

    if app.config.latex_paper_size != "letter":
        if app.config.latex_elements.get("papersize"):
            app.warn(
                "latex_paper_size conflicts with latex_elements['papersize'], ignored."
            )
        else:
            app.warn(
                "latex_paper_size is deprecated. "
                "Use latex_elements['papersize'] instead."
            )
            if app.config.latex_paper_size:
                app.config.latex_elements["papersize"] = (
                    app.config.latex_paper_size + "paper"
                )

    if app.config.latex_font_size != "10pt":
        if app.config.latex_elements.get("pointsize"):
            app.warn(
                "latex_font_size conflicts with latex_elements['pointsize'], ignored."
            )
        else:
            app.warn(
                "latex_font_size is deprecated. Use latex_elements['pointsize'] instead."
            )
            app.config.latex_elements["pointsize"] = app.config.latex_font_size

    if "footer" in app.config.latex_elements:
        if "postamble" in app.config.latex_elements:
            app.warn(
                "latex_elements['footer'] conflicts with "
                "latex_elements['postamble'], ignored."
            )
        else:
            app.warn(
                "latex_elements['footer'] is deprecated. "
                "Use latex_elements['preamble'] instead."
            )
            app.config.latex_elements["postamble"] = app.config.latex_elements["footer"]