本文整理汇总了Python中sphinx.quickstart.ask_user函数的典型用法代码示例。如果您正苦于以下问题:Python ask_user函数的具体用法?Python ask_user怎么用?Python ask_user使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ask_user函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_quickstart_defaults
def test_quickstart_defaults(tempdir):
answers = {
'Root path': tempdir,
'Project name': 'Sphinx Test',
'Author name': 'Georg Brandl',
'Project version': '0.1',
}
qs.term_input = mock_input(answers)
d = {}
qs.ask_user(d)
qs.generate(d)
conffile = tempdir / 'conf.py'
assert conffile.isfile()
ns = {}
execfile_(conffile, ns)
assert ns['extensions'] == []
assert ns['templates_path'] == ['_templates']
assert ns['source_suffix'] == '.rst'
assert ns['master_doc'] == 'index'
assert ns['project'] == 'Sphinx Test'
assert ns['copyright'] == '%s, Georg Brandl' % time.strftime('%Y')
assert ns['version'] == '0.1'
assert ns['release'] == '0.1'
assert ns['todo_include_todos'] is False
assert ns['html_static_path'] == ['_static']
assert ns['latex_documents'] == [
('index', 'SphinxTest.tex', 'Sphinx Test Documentation',
'Georg Brandl', 'manual')]
assert (tempdir / '_static').isdir()
assert (tempdir / '_templates').isdir()
assert (tempdir / 'index.rst').isfile()
assert (tempdir / 'Makefile').isfile()
assert (tempdir / 'make.bat').isfile()
示例2: test_quickstart_all_answers
def test_quickstart_all_answers(tempdir):
answers = {
'Root path': tempdir,
'Separate source and build': 'y',
'Name prefix for templates': '.',
'Project name': u'STASI™'.encode('utf-8'),
'Author name': u'Wolfgang Schäuble & G\'Beckstein'.encode('utf-8'),
'Project version': '2.0',
'Project release': '2.0.1',
'Source file suffix': '.txt',
'Name of your master document': 'contents',
'autodoc': 'y',
'doctest': 'yes',
'intersphinx': 'no',
'todo': 'n',
'coverage': 'no',
'pngmath': 'N',
'mathjax': 'no',
'ifconfig': 'no',
'viewcode': 'no',
'Create Makefile': 'no',
'Create Windows command file': 'no',
'Do you want to use the epub builder': 'yes',
}
qs.term_input = mock_raw_input(answers, needanswer=True)
qs.TERM_ENCODING = 'utf-8'
d = {}
qs.ask_user(d)
qs.generate(d)
conffile = tempdir / 'source' / 'conf.py'
assert conffile.isfile()
ns = {}
execfile_(conffile, ns)
assert ns['extensions'] == ['sphinx.ext.autodoc', 'sphinx.ext.doctest']
assert ns['templates_path'] == ['.templates']
assert ns['source_suffix'] == '.txt'
assert ns['master_doc'] == 'contents'
assert ns['project'] == u'STASI™'
assert ns['copyright'] == u'%s, Wolfgang Schäuble & G\'Beckstein' % \
time.strftime('%Y')
assert ns['version'] == '2.0'
assert ns['release'] == '2.0.1'
assert ns['html_static_path'] == ['.static']
assert ns['latex_documents'] == [
('contents', 'STASI.tex', u'STASI™ Documentation',
u'Wolfgang Schäuble \\& G\'Beckstein', 'manual')]
assert ns['epub_author'] == u'Wolfgang Schäuble & G\'Beckstein'
assert ns['man_pages'] == [
('contents', 'stasi', u'STASI™ Documentation',
[u'Wolfgang Schäuble & G\'Beckstein'], 1)]
assert ns['texinfo_documents'] == [
('contents', 'STASI', u'STASI™ Documentation',
u'Wolfgang Schäuble & G\'Beckstein', 'STASI',
'One line description of project.', 'Miscellaneous'),]
assert (tempdir / 'build').isdir()
assert (tempdir / 'source' / '.static').isdir()
assert (tempdir / 'source' / '.templates').isdir()
assert (tempdir / 'source' / 'contents.txt').isfile()
示例3: sphinx
def sphinx(self):
"""
Initialize Sphinx documentation for this project.
Return: None
Exceptions: None
"""
try:
from sphinx import quickstart
except ImportError:
print "Can't import Sphinx. Skipping"
return
sphinxopts = dict(dotfile.items("sphinx"))
for f in sphinxopts:
if sphinxopts[f] in ["False"]:
sphinxopts[f] = False
if sphinxopts[f] in ["True"]:
sphinxopts[f] = True
sphinxopts["path"] = self.root + "doc"
sphinxopts["project"] = args.name
if variable("author", None, ask="Project Author"):
sphinxopts["author"] = variable("author", None)
sphinxopts["version"] = self.version
sphinxopts["release"] = self.version
quickstart.ask_user(sphinxopts)
quickstart.generate(sphinxopts)
return
示例4: test_generated_files_eol
def test_generated_files_eol(tempdir):
answers = {
'Root path': tempdir,
'Project name': 'Sphinx Test',
'Author name': 'Georg Brandl',
'Project version': '0.1',
}
qs.term_input = mock_input(answers)
d = {}
qs.ask_user(d)
qs.generate(d)
def assert_eol(filename, eol):
content = filename.bytes().decode('unicode-escape')
assert all([l[-len(eol):] == eol for l in content.splitlines(True)])
assert_eol(tempdir / 'make.bat', '\r\n')
assert_eol(tempdir / 'Makefile', '\n')
示例5: test_default_filename
def test_default_filename(tempdir):
answers = {
'Root path': tempdir,
'Project name': u'\u30c9\u30a4\u30c4', # Fullwidth characters only
'Author name': 'Georg Brandl',
'Project version': '0.1',
}
qs.term_input = mock_input(answers)
d = {}
qs.ask_user(d)
qs.generate(d)
conffile = tempdir / 'conf.py'
assert conffile.isfile()
ns = {}
execfile_(conffile, ns)
assert ns['latex_documents'][0][1] == 'sphinx.tex'
assert ns['man_pages'][0][1] == 'sphinx'
assert ns['texinfo_documents'][0][1] == 'sphinx'
示例6: test_quickstart_defaults
def test_quickstart_defaults(tempdir):
answers = {
'Root path': tempdir,
'Project name': 'Sphinx Test',
'Author name': 'Georg Brandl',
'Project version': '0.1',
}
qs.term_input = mock_raw_input(answers)
d = {}
qs.ask_user(d)
qs.generate(d)
conffile = tempdir / 'conf.py'
assert conffile.isfile()
ns = {}
f = open(conffile, 'rbU')
try:
code = compile(f.read(), conffile, 'exec')
finally:
f.close()
exec code in ns
assert ns['extensions'] == []
assert ns['templates_path'] == ['_templates']
assert ns['source_suffix'] == '.rst'
assert ns['master_doc'] == 'index'
assert ns['project'] == 'Sphinx Test'
assert ns['copyright'] == '%s, Georg Brandl' % time.strftime('%Y')
assert ns['version'] == '0.1'
assert ns['release'] == '0.1'
assert ns['html_static_path'] == ['_static']
assert ns['latex_documents'] == [
('index', 'SphinxTest.tex', 'Sphinx Test Documentation',
'Georg Brandl', 'manual')]
assert (tempdir / '_static').isdir()
assert (tempdir / '_templates').isdir()
assert (tempdir / 'index.rst').isfile()
assert (tempdir / 'Makefile').isfile()
assert (tempdir / 'make.bat').isfile()
示例7: test_quickstart_and_build
def test_quickstart_and_build(tempdir):
answers = {
'Root path': tempdir,
'Project name': u'Fullwidth characters: \u30c9\u30a4\u30c4',
'Author name': 'Georg Brandl',
'Project version': '0.1',
}
qs.term_input = mock_input(answers)
d = {}
qs.ask_user(d)
qs.generate(d)
app = application.Sphinx(
tempdir, # srcdir
tempdir, # confdir
(tempdir / '_build' / 'html'), # outdir
(tempdir / '_build' / '.doctree'), # doctreedir
'html', # buildername
status=StringIO(),
warning=warnfile)
app.builder.build_all()
warnings = warnfile.getvalue()
assert not warnings
示例8: test_quickstart_defaults
def test_quickstart_defaults(tempdir):
answers = {
"Root path": tempdir,
"Project name": "Sphinx Test",
"Author name": "Georg Brandl",
"Project version": "0.1",
}
qs.term_input = mock_raw_input(answers)
d = {}
qs.ask_user(d)
qs.generate(d)
conffile = tempdir / "conf.py"
assert conffile.isfile()
ns = {}
f = open(conffile, "U")
try:
code = compile(f.read(), conffile, "exec")
finally:
f.close()
exec code in ns
assert ns["extensions"] == []
assert ns["templates_path"] == ["_templates"]
assert ns["source_suffix"] == ".rst"
assert ns["master_doc"] == "index"
assert ns["project"] == "Sphinx Test"
assert ns["copyright"] == "%s, Georg Brandl" % time.strftime("%Y")
assert ns["version"] == "0.1"
assert ns["release"] == "0.1"
assert ns["html_static_path"] == ["_static"]
assert ns["latex_documents"] == [("index", "SphinxTest.tex", "Sphinx Test Documentation", "Georg Brandl", "manual")]
assert (tempdir / "_static").isdir()
assert (tempdir / "_templates").isdir()
assert (tempdir / "index.rst").isfile()
assert (tempdir / "Makefile").isfile()
assert (tempdir / "make.bat").isfile()
示例9: test_quickstart_all_answers
def test_quickstart_all_answers(tempdir):
answers = {
"Root path": tempdir,
"Separate source and build": "y",
"Name prefix for templates": ".",
"Project name": u"STASI™".encode("utf-8"),
"Author name": u"Wolfgang Schäuble & G'Beckstein".encode("utf-8"),
"Project version": "2.0",
"Project release": "2.0.1",
"Source file suffix": ".txt",
"Name of your master document": "contents",
"autodoc": "y",
"doctest": "yes",
"intersphinx": "no",
"todo": "n",
"coverage": "no",
"pngmath": "N",
"mathjax": "no",
"ifconfig": "no",
"viewcode": "no",
"Create Makefile": "no",
"Create Windows command file": "no",
"Do you want to use the epub builder": "yes",
}
qs.term_input = mock_raw_input(answers, needanswer=True)
qs.TERM_ENCODING = "utf-8"
d = {}
qs.ask_user(d)
qs.generate(d)
conffile = tempdir / "source" / "conf.py"
assert conffile.isfile()
ns = {}
f = open(conffile, "U")
try:
code = compile(f.read(), conffile, "exec")
finally:
f.close()
exec code in ns
assert ns["extensions"] == ["sphinx.ext.autodoc", "sphinx.ext.doctest"]
assert ns["templates_path"] == [".templates"]
assert ns["source_suffix"] == ".txt"
assert ns["master_doc"] == "contents"
assert ns["project"] == u"STASI™"
assert ns["copyright"] == u"%s, Wolfgang Schäuble & G'Beckstein" % time.strftime("%Y")
assert ns["version"] == "2.0"
assert ns["release"] == "2.0.1"
assert ns["html_static_path"] == [".static"]
assert ns["latex_documents"] == [
("contents", "STASI.tex", u"STASI™ Documentation", u"Wolfgang Schäuble \\& G'Beckstein", "manual")
]
assert ns["epub_author"] == u"Wolfgang Schäuble & G'Beckstein"
assert ns["man_pages"] == [("contents", "stasi", u"STASI™ Documentation", [u"Wolfgang Schäuble & G'Beckstein"], 1)]
assert ns["texinfo_documents"] == [
(
"contents",
"STASI",
u"STASI™ Documentation",
u"Wolfgang Schäuble & G'Beckstein",
"STASI",
"One line description of project.",
"Miscellaneous",
)
]
assert (tempdir / "build").isdir()
assert (tempdir / "source" / ".static").isdir()
assert (tempdir / "source" / ".templates").isdir()
assert (tempdir / "source" / "contents.txt").isfile()
示例10: post_render
def post_render(config):
target_directory = os.path.abspath(config.target_directory)
pkg = config.variables['package.directory']
pkg_dir = os.path.join(target_directory, pkg)
if not test.d(pkg_dir):
mkdir(pkg_dir)
with open(os.path.join(pkg_dir, '__init__.py'), 'wb') as fd:
fd.write('# package\n')
doc_root = os.path.join(target_directory, 'docs')
vars = config.variables
d = dict(path=doc_root, author=vars['author.name'],
project=vars['package.name'],
version='', ext_autodoc='y', ext_viewcode='y',
batchfile=False)
quickstart_do_prompt = quickstart.do_prompt
def do_prompt(d, key, text, default=None, validator=quickstart.nonempty):
print(key)
if key in use_defaults:
if default == 'y':
default = True
elif default == 'n':
default = False
d[key] = default
elif key not in d:
quickstart_do_prompt(d, key, text, default, validator)
quickstart.do_prompt = do_prompt
if not os.path.isdir(doc_root):
# launch sphinx
quickstart.ask_user(d)
quickstart.generate(d)
filename = os.path.join(doc_root, 'conf.py')
# patch some files
with open(filename, 'ab') as fd:
fd.write('''
html_theme = 'nature'
import pkg_resources
version = pkg_resources.get_distribution("%s").version
release = version
''' % vars['package.name'])
filename = os.path.join(doc_root, 'Makefile')
with open(filename, 'rb') as fd:
data = fd.read()
data = data.replace('sphinx-build', '../bin/sphinx-build')
with open(filename, 'wb') as fd:
fd.write(data)
# launch buildout
cd(target_directory)
if not test.f('bootstrap.py'):
wget('-O bootstrap.py',
'https://bootstrap.pypa.io/bootstrap-buildout.py') > 1
chmod('+x bootstrap.py')
sh.python('bootstrap.py --allow-site-packages') > 1
if test.f('bin/buildout'):
sh.python('bin/buildout') > 1
示例11: color_terminal
"ext_pngmath": true,
"sep": true,
"ext_todo": false,
"ext_coverage": false,
"ext_viewcode": false,
"batchfile": true,
"master": "index",
"epub": false,
"ext_intersphinx": false,
"dot": "_",
"ext_doctest": false
}'''
# Load the options from the json string into a Python dict
options = json.loads(json_conf)
# Everything below is copied from quickstart.py: you need not understand it
# unless noted
if not color_terminal():
nocolor()
try:
#Ask the user for the rest of the options
qs.ask_user(options)
except (KeyboardInterrupt, EOFError):
print
print '[Interrupted.]'
exit()
qs.generate(options)