Example #1
0
def _build(argv, config, versions, current_name, is_root):
    """Build Sphinx docs via multiprocessing for isolation.

    :param tuple argv: Arguments to pass to Sphinx.
    :param sphinxcontrib.versioning.lib.Config config: Runtime configuration.
    :param sphinxcontrib.versioning.versions.Versions versions: Versions class instance.
    :param str current_name: The ref name of the current version being built.
    :param bool is_root: Is this build in the web root?
    """
    # Patch.
    old_init = application.Config.__init__

    def init_override(self, *args):
        old_init(self, *args)
        self.extensions.append('sphinxcontrib.versioning.sphinx_')

    application.Config.__init__ = init_override

    if config.show_banner:
        EventHandlers.BANNER_GREATEST_TAG = config.banner_greatest_tag
        EventHandlers.BANNER_MAIN_VERSION = config.banner_main_ref
        EventHandlers.BANNER_RECENT_TAG = config.banner_recent_tag
        EventHandlers.SHOW_BANNER = True
    EventHandlers.CURRENT_VERSION = current_name
    EventHandlers.IS_ROOT = is_root
    EventHandlers.VERSIONS = versions
    SC_VERSIONING_VERSIONS[:] = [
        p for r in versions.remotes for p in sorted(r.items())
        if p[0] not in ('sha', 'date')
    ]

    # Update argv.
    if config.verbose > 1:
        argv += ('-v', ) * (config.verbose - 1)
    if config.no_colors:
        argv += ('-N', )
    if config.overflow:
        argv += config.overflow

    # Build.
    result = build_main(argv)

    if result != 0:
        raise SphinxError

    # Build pdf if required
    if config.pdf_file:
        args = list(argv)
        args.insert(0, "latexpdf")  # Builder type
        args.insert(0, "ignore")  # Will be ignored
        result = make_main(args)
        # Copy to _static dir of src
        latexDir = argv[1] + "/latex/"
        copyfile(latexDir + config.pdf_file,
                 argv[1] + "/_static/" + config.pdf_file)
        rmtree(latexDir)

    if result != 0:
        raise SphinxError
import sys
from sphinx.cmd import build

first_sphinx_arg = sys.argv.index('-M')
build.make_main(sys.argv[first_sphinx_arg:])