我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用sphinx.build_main()。
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. application.Config = ConfigInject 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
def call_sphinx(builder, workdir): import sphinx if options['--check']: extraopts = ['-W'] else: extraopts = [] if not options['--cache'] and files is None: extraopts.append('-E') docpath = os.path.join(throot, 'doc') inopt = [docpath, workdir] if files is not None: inopt.extend(files) ret = sphinx.build_main(['', '-b', builder] + extraopts + inopt) if ret != 0: sys.exit(ret)
def add_test(cls, builder): def _test(self): with utils.mock.patch('sys.stderr', six.moves.StringIO()) as stderr: with utils.mock.patch('sys.stdout', six.moves.StringIO()) as stdout: self.assertEquals(0, sphinx.build_main([ "-b{}".format(builder), "-d{}".format(os.path.join(self.build_dir, 'doctrees')), self.source_dir, os.path.join(self.build_dir, builder)]) ) setattr(cls, "test_{}".format(builder), _test)