我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用sphinx.main()。
def run(self): metadata = self.distribution.metadata src_dir = (self.distribution.package_dir or {'': ''})[''] src_dir = os.path.join(os.getcwd(), src_dir) sys.path.append('src') print('pwd=', os.getcwd(), ' src-dir=', src_dir) # Run sphinx by calling the main method, '--full' also adds a # conf.py sphinx.apidoc.main( ['', '--private', '-H', metadata.name, '-A', metadata.author, '-V', metadata.version, '-R', metadata.version, '-o', os.path.join('doc', 'source'), src_dir] ) # build the doc sources sphinx.main(['', os.path.join('doc', 'source'), os.path.join('doc', 'build', 'html')])
def _init_builder(self, buildername): if buildername is None: print('No builder selected, using default: html', file=self._status) buildername = 'html' if buildername not in self.builderclasses: raise SphinxError('Builder name %s not registered' % buildername) builderclass = self.builderclasses[buildername] if isinstance(builderclass, tuple): # builtin builder mod, cls = builderclass builderclass = getattr( __import__('sphinx.builders.' + mod, None, None, [cls]), cls) self.builder = builderclass(self) self.emit('builder-inited') # ---- main "build" method -------------------------------------------------
def run(self): import sphinx_autobuild oldsysargv = sys.argv # sphinx-autobuild's main function does not take parameters sys.argv = self._get_sphinx_args() sys.argv.extend([ '-z', '.', # Watch source directory '-i', '*.goutputstream*', # Ignore gedit temp files '-i', '.idea/*', # Ignore PyCharm files '-i', '.git/*' # Ignore git directory ]) try: sphinx_autobuild.main() except SystemExit: # Prevent sphinx from exiting pass sys.argv = oldsysargv
def write(self, build_docnames, updated_docnames, method='update'): if build_docnames is None or build_docnames == ['__all__']: # build_all build_docnames = self.env.found_docs if method == 'update': # build updated ones as well docnames = set(build_docnames) | set(updated_docnames) else: docnames = set(build_docnames) self.app.debug('docnames to write: %s', ', '.join(sorted(docnames))) # add all toctree-containing files that may have changed for docname in list(docnames): for tocdocname in self.env.files_to_rebuild.get(docname, []): if tocdocname in self.env.found_docs: docnames.add(tocdocname) docnames.add(self.config.master_doc) self.info(bold('preparing documents... '), nonl=True) self.prepare_writing(docnames) self.info('done') warnings = [] self.env.set_warnfunc(lambda *args: warnings.append(args)) if self.parallel_ok: # number of subprocesses is parallel-1 because the main process # is busy loading doctrees and doing write_doc_serialized() self._write_parallel(sorted(docnames), warnings, nproc=self.app.parallel - 1) else: self._write_serial(sorted(docnames), warnings) self.env.set_warnfunc(self.warn)
def write_doc_serialized(self, docname, doctree): """Handle parts of write_doc that must be called in the main process if parallel build is active. """ pass
def run(self): import sphinx try: sphinx.main(self._get_sphinx_args()) except SystemExit: # Prevent sphinx from exiting pass
def run_tests(self): import pytest errno = pytest.main(self.pytest_args) sys.exit(errno)
def run(self): import sphinx metadata = self.distribution.metadata docs = os.path.join(os.getcwd(), 'docs') sphinx.main(['', '-D', 'project='+metadata.name, '-D', 'copyright={}, {}'.format(datetime.now().year, metadata.author), '-D', 'version='+metadata.version, '-D', 'release='+metadata.version, docs, os.path.join(docs, '_build')])