'Build the documentation in C{docDir} with Sphinx.
@param docDir: The directory of the documentation.  This is a directory
which contains another directory called "source" which contains the
Sphinx "conf.py" file and sphinx source documents.
@type docDir: L{twisted.python.filepath.FilePath}
@param buildDir: The directory to build the documentation in.  By
default this will be a child directory of {docDir} named "build".
@type buildDir: L{twisted.python.filepath.FilePath}
@param version: The version of Twisted to set in the docs.
@type version: C{str}
@return: the output produced by running the command
@rtype: L{str}'

def build(self, docDir, buildDir=None, version=''):

    if (buildDir is None):
        buildDir = docDir.parent().child('doc')
    doctreeDir = buildDir.child('doctrees')
    output = runCommand(['sphinx-build', '-q', '-b', 'html', '-d', doctreeDir.path, docDir.path, buildDir.path]).decode('utf-8')
    doctreeDir.remove()
    for path in docDir.walk():
        if (path.basename() == 'man'):
            segments = path.segmentsFrom(docDir)
            dest = buildDir
            while segments:
                dest = dest.child(segments.pop(0))
            if (not dest.parent().isdir()):
                dest.parent().makedirs()
            path.copyTo(dest)
    return output
