# Buggy code
def write(self, *ignored):
    # type: (Any) -> None
    docwriter = ManualPageWriter(self)
    docsettings = OptionParser(
        defaults=self.env.settings, components=(docwriter,), read_config_files=True
    ).get_default_values()

    logger.info(bold("writing... "), nonl=True)

    for info in self.config.man_pages:
        docname, name, description, authors, section = info
        if isinstance(authors, string_types):
            if authors:
                authors = [authors]
            else:
                authors = []

        targetname = "%s.%s" % (name, section)
        logger.info(darkgreen(targetname) + " { ", nonl=True)
        destination = FileOutput(
            destination_path=path.join(self.outdir, targetname), encoding="utf-8"
        )

        tree = self.env.get_doctree(docname)
        docnames = set()  # type: Set[unicode]
        largetree = inline_all_toctrees(
            self, docnames, docname, tree, darkgreen, [docname]
        )
        logger.info("} ", nonl=True)
        self.env.resolve_references(largetree, docname, self)
        # remove pending_xref nodes
        for pendingnode in largetree.traverse(addnodes.pending_xref):
            pendingnode.replace_self(pendingnode.children)

        largetree.settings = docsettings
        largetree.settings.title = name
        largetree.settings.subtitle = description
        largetree.settings.authors = authors
        largetree.settings.section = section

        docwriter.write(largetree, destination)
    logger.info("")


# Traceback (FileNotFoundError)
# Sphinx version: 1.7.7
# Python version: 3.6.5 (CPython)
# Docutils version: 0.14
# Jinja2 version: 2.10
# Last messages:
#   done
#
#   checking consistency...
#
#   done
#
#   writing...
#
#   pip.1 {
#
# Loaded extensions:
#   alabaster (0.7.11) from /Users/pradyunsg/Projects/pip/.tox/docs/lib/python3.6/site-packages/alabaster/__init__.py
#   sphinx.ext.extlinks (1.7.7) from /Users/pradyunsg/Projects/pip/.tox/docs/lib/python3.6/site-packages/sphinx/ext/extlinks.py
#   pip_sphinxext (unknown version) from /Users/pradyunsg/Projects/pip/docs/pip_sphinxext.py
#   sphinx.ext.intersphinx (1.7.7) from /Users/pradyunsg/Projects/pip/.tox/docs/lib/python3.6/site-packages/sphinx/ext/intersphinx.py
Traceback (most recent call last):
File "/Users/pradyunsg/Projects/pip/.tox/docs/lib/python3.6/site-packages/sphinx/cmdline.py", line 304, in main
app.build(args.force_all, filenames)
File "/Users/pradyunsg/Projects/pip/.tox/docs/lib/python3.6/site-packages/sphinx/application.py", line 331, in build
self.builder.build_update()
File "/Users/pradyunsg/Projects/pip/.tox/docs/lib/python3.6/site-packages/sphinx/builders/__init__.py", line 337, in build_update
self.build(['__all__'], to_build)
File "/Users/pradyunsg/Projects/pip/.tox/docs/lib/python3.6/site-packages/sphinx/builders/__init__.py", line 403, in build
self.write(docnames, list(updated_docnames), method)
File "/Users/pradyunsg/Projects/pip/.tox/docs/lib/python3.6/site-packages/sphinx/builders/manpage.py", line 87, in write
tree = self.env.get_doctree(docname)
File "/Users/pradyunsg/Projects/pip/.tox/docs/lib/python3.6/site-packages/sphinx/environment/__init__.py", line 786, in get_doctree
with open(doctree_filename, 'rb') as f:
FileNotFoundError: [Errno 2] No such file or directory: '/Users/pradyunsg/Projects/pip/.tox/docs/tmp/doctrees/man/man/index.doctree'

# Fixed code
def write(self, *ignored):
    # type: (Any) -> None
    docwriter = ManualPageWriter(self)
    docsettings = OptionParser(
        defaults=self.env.settings, components=(docwriter,), read_config_files=True
    ).get_default_values()

    logger.info(bold("writing... "), nonl=True)

    for info in self.config.man_pages:
        docname, name, description, authors, section = info
        if docname not in self.env.all_docs:
            logger.warning(
                __('"man_pages" config value references unknown document %s'), docname
            )
            continue
        if isinstance(authors, string_types):
            if authors:
                authors = [authors]
            else:
                authors = []

        targetname = "%s.%s" % (name, section)
        logger.info(darkgreen(targetname) + " { ", nonl=True)
        destination = FileOutput(
            destination_path=path.join(self.outdir, targetname), encoding="utf-8"
        )

        tree = self.env.get_doctree(docname)
        docnames = set()  # type: Set[unicode]
        largetree = inline_all_toctrees(
            self, docnames, docname, tree, darkgreen, [docname]
        )
        logger.info("} ", nonl=True)
        self.env.resolve_references(largetree, docname, self)
        # remove pending_xref nodes
        for pendingnode in largetree.traverse(addnodes.pending_xref):
            pendingnode.replace_self(pendingnode.children)

        largetree.settings = docsettings
        largetree.settings.title = name
        largetree.settings.subtitle = description
        largetree.settings.authors = authors
        largetree.settings.section = section

        docwriter.write(largetree, destination)
    logger.info("")