本文整理汇总了Python中sphinx.application.Sphinx类的典型用法代码示例。如果您正苦于以下问题:Python Sphinx类的具体用法?Python Sphinx怎么用?Python Sphinx使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Sphinx类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, srcdir=None, buildername='html', confoverrides={}):
self.cleanup_dirs = []
self.readonly = False
# source settings
if srcdir is None:
srcdir = tempfile.mkdtemp()
self.cleanup_dirs.append(srcdir)
open(os.path.join(srcdir, 'conf.py'), 'w').close()
else:
self.readonly = True
if not srcdir.startswith('/'):
srcdir = os.path.join(testdir, srcdir)
confdir = srcdir
# _build/ directory setings
self.builddir = tempfile.mkdtemp()
outdir = os.path.join(self.builddir, str(buildername))
doctreedir = os.path.join(self.builddir, 'doctrees')
os.mkdir(outdir)
self.cleanup_dirs.append(self.builddir)
# misc settings
status = sys.stdout
warning = sys.stdout
Sphinx.__init__(self, srcdir, confdir, outdir, doctreedir,
buildername, confoverrides, status, warning)
示例2: test_body
def test_body():
with open(os.path.join(_srcdir, 'conf.py'), 'w') as f:
f.write('''
extensions = [ 'sphinxcontrib.spelling' ]
''')
with open(os.path.join(_srcdir, 'contents.rst'), 'w') as f:
f.write('''
Welcome to Spelling Checker documentation!
==========================================
There are several mispelled words in this txt.
''')
stdout = StringIO()
stderr = StringIO()
app = Sphinx(_srcdir, _srcdir, _outdir, _outdir, 'spelling',
status=stdout, warning=stderr,
freshenv=True,
)
app.build()
print 'reading from %s' % app.builder.output_filename
with codecs.open(app.builder.output_filename, 'r') as f:
output_text = f.read()
def check_one(word):
assert word in output_text
for word in [ '(mispelled)', '(txt)' ]:
yield check_one, word
return
示例3: pytest_funcarg__app
def pytest_funcarg__app(request):
"""
A Sphinx application for testing.
The app uses the source directory from the ``srcdir`` funcarg, and writes
to the directories given by the ``outdir`` and ``doctreedir`` funcargs.
Additional configuration values can be inserted into this application
through the ``confoverrides`` funcarg.
If the marker ``mock_lookup`` is attached to the current test, the lookup
callback returned by the ``mock_lookup`` funcarg is automatically connected
to the ``issuetracker-lookup-issue`` event in the the created application.
If the marker ``build_app`` is attached to the current test, the app is
build before returning it. Otherwise you need to build explicitly in order
to get the output.
"""
srcdir = request.getfuncargvalue('srcdir')
outdir = request.getfuncargvalue('outdir')
doctreedir = request.getfuncargvalue('doctreedir')
confoverrides = request.getfuncargvalue('confoverrides')
app = Sphinx(str(srcdir), str(srcdir), str(outdir), str(doctreedir),
'html', confoverrides=confoverrides, status=None,
warning=None, freshenv=True)
request.addfinalizer(reset_global_state)
if 'mock_lookup' in request.keywords:
lookup_mock_issue = request.getfuncargvalue('mock_lookup')
app.connect(str('issuetracker-lookup-issue'), lookup_mock_issue)
if 'build_app' in request.keywords:
app.build()
return app
示例4: sphinx_build
def sphinx_build(self):
workdir = self._workdir
if not os.path.isdir(workdir):
os.makedirs(workdir)
conf = os.path.join(workdir, 'conf.py')
with codecs.open(conf, encoding='utf-8', mode='w') as out:
out.write(SPHINX_CONF)
out.write(SPHINX_CONF_APPEND)
start = time.time()
status = MezeStream(sys.stdout)
warning = MezeStream(sys.stderr)
app = Sphinx(srcdir=workdir, confdir=workdir, outdir=workdir,
doctreedir=workdir, buildername='meze',
confoverrides={}, status=status, warning=warning,
freshenv=False, warningiserror=False, tags=[])
rst = os.path.join(workdir, 'index' + app.config.source_suffix[0])
with codecs.open(rst, encoding='utf-8', mode='w') as out:
out.write(self._source)
app.build(False, [rst])
self._messages.append((messages.INFO, 'Source was converted '
'into HTML using Sphinx in {:.2f}'.
format(time.time() - start)))
for msg in warning.messages:
items = msg.split('WARNING: ')
if len(items) == 2:
msg = items[1]
self._messages.append((messages.WARNING, msg))
self._content, MezeBuilder.context = MezeBuilder.context['body'], None
示例5: test_spelling
def test_spelling(self):
status = StringIO()
with TemporaryDirectory() as OUT_DIR:
with tmp_list_append(sys.argv, 'spelling'):
try:
app = Sphinx(
srcdir=DOCS_DIR,
confdir=DOCS_DIR,
outdir=OUT_DIR,
doctreedir=OUT_DIR,
buildername="spelling",
warningiserror=True,
status=status,
confoverrides={
'extensions': [
'djangocms',
'sphinx.ext.intersphinx',
'sphinxcontrib.spelling'
]
}
)
app.build()
self.assertEqual(app.statuscode, 0, status.getvalue())
except SphinxWarning:
# while normally harmless, causes a test failure
pass
except:
print(status.getvalue())
raise
示例6: run
def run(self):
if not color_terminal():
# Windows' poor cmd box doesn't understand ANSI sequences
nocolor()
if not self.verbose:
status_stream = StringIO()
else:
status_stream = sys.stdout
confoverrides = {}
if self.project:
confoverrides['project'] = self.project
if self.version:
confoverrides['version'] = self.version
if self.release:
confoverrides['release'] = self.release
if self.today:
confoverrides['today'] = self.today
app = Sphinx(self.source_dir, self.config_dir,
self.builder_target_dir, self.doctree_dir,
self.builder, confoverrides, status_stream,
freshenv=self.fresh_env)
try:
app.build(force_all=self.all_files)
except Exception, err:
from docutils.utils import SystemMessage
if isinstance(err, SystemMessage):
print >>sys.stderr, darkred('reST markup error:')
print >>sys.stderr, err.args[0].encode('ascii',
'backslashreplace')
else:
raise
示例7: test_title
def test_title():
with open(os.path.join(_srcdir, 'conf.py'), 'w') as f:
f.write('''
extensions = [ 'sphinxcontrib.spelling' ]
''')
with open(os.path.join(_srcdir, 'contents.rst'), 'w') as f:
f.write('''
Welcome to Speeling Checker documentation!
==========================================
''')
stdout = StringIO()
stderr = StringIO()
app = Sphinx(_srcdir, _srcdir, _outdir, _outdir, 'spelling',
status=stdout, warning=stderr,
freshenv=True,
)
app.build()
with codecs.open(app.builder.output_filename, 'r') as f:
output_text = f.read()
def check_one(word):
print output_text
assert word in output_text
for word in [ '(Speeling)', ]:
yield check_one, word
return
示例8: get_long_description
def get_long_description(cleanup=True):
from sphinx.application import Sphinx
from sphinx.util.osutil import abspath
import tempfile
import shutil
from doc.conf import extensions
from sphinxcontrib.writers.rst import RstTranslator
from sphinx.ext.graphviz import text_visit_graphviz
RstTranslator.visit_dsp = text_visit_graphviz
outdir = tempfile.mkdtemp(prefix='setup-', dir='.')
exclude_patterns = os.listdir(mydir or '.')
exclude_patterns.remove('pypi.rst')
app = Sphinx(abspath(mydir), osp.join(mydir, 'doc/'), outdir,
outdir + '/.doctree', 'rst',
confoverrides={
'exclude_patterns': exclude_patterns,
'master_doc': 'pypi',
'dispatchers_out_dir': abspath(outdir + '/_dispatchers'),
'extensions': extensions + ['sphinxcontrib.restbuilder']
}, status=None, warning=None)
app.build(filenames=[osp.join(app.srcdir, 'pypi.rst')])
with open(outdir + '/pypi.rst') as file:
res = file.read()
if cleanup:
shutil.rmtree(outdir)
return res
示例9: sphinx_app
def sphinx_app(tmpdir_factory):
if LooseVersion(sphinx.__version__) < LooseVersion('1.8'):
# Previous versions throw an error trying to pickle the scraper
pytest.skip('Sphinx 1.8+ required')
temp_dir = (tmpdir_factory.getbasetemp() / 'root').strpath
src_dir = op.join(op.dirname(__file__), 'tinybuild')
def ignore(src, names):
return ('_build', 'gen_modules', 'auto_examples')
shutil.copytree(src_dir, temp_dir, ignore=ignore)
# For testing iteration, you can get similar behavior just doing `make`
# inside the tinybuild directory
src_dir = temp_dir
conf_dir = temp_dir
out_dir = op.join(temp_dir, '_build', 'html')
toctrees_dir = op.join(temp_dir, '_build', 'toctrees')
# Avoid warnings about re-registration, see:
# https://github.com/sphinx-doc/sphinx/issues/5038
with docutils_namespace():
app = Sphinx(src_dir, conf_dir, out_dir, toctrees_dir,
buildername='html', status=MixedEncodingStringIO())
# need to build within the context manager
# for automodule and backrefs to work
app.build(False, [])
return app
示例10: build
def build(self):
"""Build the documentation. Places the data into the `outdir`
directory. Use it like this::
support = WebSupport(srcdir, builddir, search='xapian')
support.build()
This will read reStructured text files from `srcdir`. Then it will
build the pickles and search index, placing them into `builddir`.
It will also save node data to the database.
"""
if not self.srcdir:
raise RuntimeError("No srcdir associated with WebSupport object")
app = Sphinx(
self.srcdir,
self.srcdir,
self.outdir,
self.doctreedir,
"websupport",
status=self.status,
warning=self.warning,
)
app.builder.set_webinfo(self.staticdir, self.staticroot, self.search, self.storage)
self.storage.pre_build()
app.build()
self.storage.post_build()
示例11: get_sphinx
def get_sphinx():
sphinx = getattr(local_data, 'sphinx', None)
if sphinx is None:
sphinx = Sphinx(tempdir, tempdir, tempdir,
tempdir, 'json', status=None, warning=None)
sphinx.builder.translator_class = CustomHTMLTranslator
sphinx.env.patch_lookup_functions()
sphinx.env.temp_data['docname'] = 'text'
sphinx.env.temp_data['default_domain'] = 'py'
pub = Publisher(reader=None,
parser=None,
writer=HTMLWriter(sphinx.builder),
source_class=io.StringInput,
destination_class=io.NullOutput)
pub.set_components('standalone', 'restructuredtext', None)
pub.process_programmatic_settings(None, sphinx.env.settings, None)
pub.set_destination(None, None)
sphinx.publisher = pub
local_data.sphinx = sphinx
return sphinx, sphinx.publisher
示例12: make_sphinx
def make_sphinx(docbase, buildername='html'):
docbase = os.path.abspath(docbase)
if not os.path.isdir(docbase):
cprint(bcolors.WARNING, "[%s] is not a valid directory" % docbase)
cprint(bcolors.OKBLUE, "Building %s..." % docbase[:67])
verbose_output = StringIO()
sphinx = Sphinx(
srcdir=os.path.join(docbase, 'source'),
confdir=os.path.join(docbase, 'source'),
outdir=os.path.join(docbase, '_build', 'html'),
doctreedir=os.path.join(docbase, '_build', 'doctrees'),
buildername='html',
#confoverrides=None,
status=verbose_output,
#warning=sys.stderr,
#freshenv=False,
#warningiserror=False,
#tags=None,
#verbosity=0,
#parallel=0
)
sphinx.build(
#force_all=False,
#filenames=None
)
vprint(verbose_output.getvalue())
verbose_output.close()
示例13: runsphinx
def runsphinx(text, builder, confoverrides):
f = open(os.path.join(_srcdir, "index.rst"), "w")
try:
f.write(text.encode("utf-8"))
finally:
f.close()
app = Sphinx(_srcdir, _fixturedir, _outdir, _outdir, builder, confoverrides)
app.build()
示例14: run
def run(self):
from sphinx.application import Sphinx
sph = Sphinx('./doc/source', # source directory
'./doc/source', # directory containing conf.py
self.output_dir, # output directory
'./doc/build/doctrees', # doctree directory
self.target) # finally, specify the doctest builder'
sph.build()
示例15: runsphinx
def runsphinx(text, builder, confoverrides):
f = open(os.path.join(_srcdir, 'index.rst'), 'w')
try:
f.write(text)
finally:
f.close()
app = Sphinx(_srcdir, _fixturedir, _outdir, _outdir, builder,
confoverrides)
app.build()