本文整理汇总了Python中sphinx.application.Sphinx类的典型用法代码示例。如果您正苦于以下问题:Python Sphinx类的具体用法?Python Sphinx怎么用?Python Sphinx使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Sphinx类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:Lemma1,项目名称:MINAMI,代码行数:31,代码来源:utils.py
示例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
开发者ID:torcolvin,项目名称:sphinx-contrib,代码行数:28,代码来源:test_builder.py
示例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
开发者ID:evildmp,项目名称:sphinxcontrib-issuetracker,代码行数:31,代码来源:conftest.py
示例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
开发者ID:Nassty,项目名称:mezzanine-meze,代码行数:35,代码来源:meze.py
示例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
开发者ID:quanpower,项目名称:django-cms,代码行数:29,代码来源:test_docs.py
示例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
开发者ID:SurfasJones,项目名称:icecream-info,代码行数:32,代码来源:setup_command.py
示例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
开发者ID:torcolvin,项目名称:sphinx-contrib,代码行数:26,代码来源:test_builder.py
示例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
开发者ID:vinci1it2000,项目名称:dispatcher,代码行数:30,代码来源:setup.py
示例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
开发者ID:sphinx-gallery,项目名称:sphinx-gallery,代码行数:26,代码来源:test_full.py
示例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()
开发者ID:alfonsodiecko,项目名称:PYTHON_DIST,代码行数:27,代码来源:__init__.py
示例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
开发者ID:runyaga,项目名称:ptah,代码行数:25,代码来源:rst.py
示例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()
开发者ID:sbennett18,项目名称:dotfiles,代码行数:28,代码来源:run.py
示例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()
开发者ID:skurfuerst,项目名称:ReST-summary,代码行数:8,代码来源:test_functional.py
示例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()
开发者ID:nihlaeth,项目名称:lilyflower,代码行数:8,代码来源:setup.py
示例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()
开发者ID:Lemma1,项目名称:MINAMI,代码行数:9,代码来源:test_functional.py
示例16: test_html
def test_html(self):
nullout = StringIO()
with TemporaryDirectory() as OUT_DIR:
app = Sphinx(DOCS_DIR, DOCS_DIR, OUT_DIR, OUT_DIR, "html", warningiserror=True, status=nullout)
try:
app.build()
except:
print nullout.getvalue()
raise
开发者ID:philippbosch,项目名称:django-cms,代码行数:9,代码来源:docs.py
示例17: test_html_documentation
def test_html_documentation(self):
app = Sphinx(
self.source_dir,
self.config_dir,
self.output_dir,
self.doctree_dir,
buildername='html',
warningiserror=True,
)
app.build(force_all=self.all_files)
开发者ID:zsdonghao,项目名称:tensorlayer,代码行数:10,代码来源:test_documentation.py
示例18: sphinx_worker
def sphinx_worker(base_path, work_queue, output_queue):
"A background worker thread performing Sphinx compilations"
# Set up the Sphinx instance
srcdir = base_path
confdir = srcdir
outdir = os.path.join(srcdir, '_build', 'json')
freshenv = False
warningiserror = False
buildername = 'json'
# verbosity = 0
# parallel = 0
status = SphinxStatusHandler(output_queue)
warning = SphinxWarningHandler(output_queue)
# error = sys.stderr
# warnfile = None
confoverrides = {}
tags = []
doctreedir = os.path.join(outdir, '.doctrees')
output_queue.put(InitializationStart())
sphinx = Sphinx(srcdir, confdir, outdir, doctreedir, buildername,
confoverrides, status, warning, freshenv,
warningiserror, tags)
output_queue.put(InitializationEnd(extension=sphinx.config.source_suffix))
quit = False
while not quit:
# Get the next command off the work queue
cmd = work_queue.get(block=True)
if isinstance(cmd, Quit):
quit = True
elif isinstance(cmd, ReloadConfig):
output_queue.put(InitializationStart())
freshenv = True
sphinx = Sphinx(srcdir, confdir, outdir, doctreedir, buildername,
confoverrides, status, warning, freshenv,
warningiserror, tags)
output_queue.put(InitializationEnd(extension=sphinx.config.source_suffix))
elif isinstance(cmd, BuildAll):
output_queue.put(BuildStart(filenames=None))
sphinx.builder.build_all()
output_queue.put(BuildEnd(filenames=None))
elif isinstance(cmd, BuildSpecific):
output_queue.put(BuildStart(filenames=cmd.filenames))
sphinx.builder.build_specific(cmd.filenames)
output_queue.put(BuildEnd(filenames=cmd.filenames))
# Reset the warning count so that they don't accumulate between builds.
sphinx._warncount = 0
开发者ID:adamchainz,项目名称:galley,代码行数:55,代码来源:worker.py
示例19: test_text_documentation
def test_text_documentation(self):
# The same, but with different buildername
app = Sphinx(
self.source_dir,
self.config_dir,
self.output_dir,
self.doctree_dir,
buildername='text',
warningiserror=False,
)
app.build(force_all=self.all_files)
开发者ID:zsdonghao,项目名称:tensorlayer,代码行数:11,代码来源:test_documentation.py
示例20: __convertReSTSphinx
def __convertReSTSphinx(self, text):
"""
Private method to convert ReST text into HTML using 'sphinx'.
@param text text to be processed (string)
@return processed HTML (string)
"""
try:
from sphinx.application import Sphinx # __IGNORE_EXCEPTION__
except ImportError:
return self.tr(
"""<p>ReStructuredText preview requires the"""
""" <b>sphinx</b> package.<br/>Install it with"""
""" your package manager,'pip install Sphinx' or see"""
""" <a href="http://pypi.python.org/pypi/Sphinx">"""
"""this page.</a></p>"""
"""<p>Alternatively you may disable Sphinx usage"""
""" on the Editor, Filehandling configuration page.</p>""")
tempDir = tempfile.mkdtemp(prefix='eric-rest-')
try:
filename = 'sphinx_preview'
basePath = os.path.join(tempDir, filename)
fh = open(basePath + '.rst', 'w', encoding='utf-8')
fh.write(text)
fh.close()
overrides = {'html_add_permalinks': False,
'html_copy_source': False,
'html_title': 'Sphinx preview',
'html_use_index': False,
'html_use_modindex': False,
'html_use_smartypants': True,
'master_doc': filename}
app = Sphinx(srcdir=tempDir, confdir=None, outdir=tempDir,
doctreedir=tempDir, buildername='html',
confoverrides=overrides, status=None,
warning=io.StringIO())
app.build(force_all=True, filenames=None)
fh = open(basePath + '.html', 'r', encoding='utf-8')
html = fh.read()
fh.close()
finally:
shutil.rmtree(tempDir)
# Replace the "_static/..." references inserted by Sphinx with absolute
# links to the specified DefaultStaticPath replacement.
def replace(m):
return '{0}="file://{1}{2}"'.format(
m.group(1), self.DefaultStaticPath, m.group(2))
html = re.sub(self.StaticRegexp, replace, html)
return html
开发者ID:pycom,项目名称:EricShort,代码行数:54,代码来源:PreviewerHTML.py
注:本文中的sphinx.application.Sphinx类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论