summaryrefslogtreecommitdiff
path: root/sphinx/quickstart.py
diff options
context:
space:
mode:
Diffstat (limited to 'sphinx/quickstart.py')
-rw-r--r--sphinx/quickstart.py401
1 files changed, 310 insertions, 91 deletions
diff --git a/sphinx/quickstart.py b/sphinx/quickstart.py
index dbb01c59..549a7d62 100644
--- a/sphinx/quickstart.py
+++ b/sphinx/quickstart.py
@@ -8,32 +8,61 @@
:copyright: Copyright 2007-2014 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
+from __future__ import print_function
-import sys, os, time, re
+import re
+import os
+import sys
+import optparse
+import time
from os import path
+from io import open
TERM_ENCODING = getattr(sys.stdin, 'encoding', None)
+# try to import readline, unix specific enhancement
+try:
+ import readline
+ if readline.__doc__ and 'libedit' in readline.__doc__:
+ readline.parse_and_bind("bind ^I rl_complete")
+ else:
+ readline.parse_and_bind("tab: complete")
+except ImportError:
+ pass
+
+from six import PY2, PY3, text_type
+from six.moves import input
from docutils.utils import column_width
from sphinx import __version__
from sphinx.util.osutil import make_filename
from sphinx.util.console import purple, bold, red, turquoise, \
- nocolor, color_terminal
+ nocolor, color_terminal
from sphinx.util import texescape
-from sphinx.util.pycompat import open
# function to get input from terminal -- overridden by the test suite
-try:
- # this raw_input is not converted by 2to3
- term_input = raw_input
-except NameError:
- term_input = input
-
+term_input = input
+
+DEFAULT_VALUE = {
+ 'path': '.',
+ 'sep': False,
+ 'dot': '_',
+ 'language': None,
+ 'suffix': '.rst',
+ 'master': 'index',
+ 'epub': False,
+ 'ext_autodoc': False,
+ 'ext_doctest': False,
+ 'makefile': True,
+ 'batchfile': True,
+ }
+
+EXTENSIONS = ('autodoc', 'doctest', 'intersphinx', 'todo', 'coverage',
+ 'pngmath', 'mathjax', 'ifconfig', 'viewcode')
PROMPT_PREFIX = '> '
-if sys.version_info >= (3, 0):
+if PY3:
# prevents that the file is checked for being written in Python 2.x syntax
QUICKSTART_CONF = u'#!/usr/bin/env python3\n'
else:
@@ -99,7 +128,10 @@ release = '%(release_str)s'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
-#language = None
+#
+# This is also used if you do content translation via gettext catalogs.
+# Usually you set "language" from the command line for these cases.
+language = %(language)r
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
@@ -217,10 +249,23 @@ html_static_path = ['%(dot)sstatic']
# This is the file name suffix for HTML files (e.g. ".xhtml").
#html_file_suffix = None
+# Language to be used for generating the HTML full-text search index.
+# Sphinx supports the following languages:
+# 'da', 'de', 'en', 'es', 'fi', 'fr', 'hu', 'it', 'ja'
+# 'nl', 'no', 'pt', 'ro', 'ru', 'sv', 'tr'
+#html_search_language = 'en'
+
+# A dictionary with options for the search language support, empty by default.
+# Now only 'ja' uses this config value
+#html_search_options = {'type': 'default'}
+
+# The name of a javascript file (relative to the configuration directory) that
+# implements a search results scorer. If empty, the default will be used.
+#html_search_scorer = 'scorer.js'
+
# Output file base name for HTML help builder.
htmlhelp_basename = '%(project_fn)sdoc'
-
# -- Options for LaTeX output ---------------------------------------------
latex_elements = {
@@ -232,6 +277,9 @@ latex_elements = {
# Additional stuff for the LaTeX preamble.
#'preamble': '',
+
+# Latex figure (float) alignment
+#'figure_align': 'htbp',
}
# Grouping the document tree into LaTeX files. List of tuples
@@ -320,7 +368,7 @@ epub_copyright = u'%(copyright_str)s'
#epub_theme = 'epub'
# The language of the text. It defaults to the language option
-# or en if the language is not set.
+# or 'en' if the language is not set.
#epub_language = ''
# The scheme of the identifier. Typical schemes are ISBN or URL.
@@ -359,7 +407,7 @@ epub_exclude_files = ['search.html']
# Choose between 'default' and 'includehidden'.
#epub_tocscope = 'default'
-# Fix unsupported image types using the PIL.
+# Fix unsupported image types using the Pillow.
#epub_fix_images = False
# Scale large images.
@@ -432,7 +480,7 @@ $(SPHINXOPTS) %(rsrcdir)s
I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) %(rsrcdir)s
.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp \
-epub latex latexpdf text man changes linkcheck doctest gettext
+epub latex latexpdf text man changes linkcheck doctest coverage gettext
help:
\t@echo "Please use \\`make <target>' where <target> is one of"
@@ -459,6 +507,7 @@ help:
\t@echo " linkcheck to check all external links for integrity"
\t@echo " doctest to run all doctests embedded in the documentation \
(if enabled)"
+\t@echo " coverage to run coverage check of the documentation (if enabled)"
clean:
\trm -rf $(BUILDDIR)/*
@@ -581,6 +630,11 @@ doctest:
\t@echo "Testing of doctests in the sources finished, look at the " \\
\t "results in $(BUILDDIR)/doctest/output.txt."
+coverage:
+\t$(SPHINXBUILD) -b coverage $(ALLSPHINXOPTS) $(BUILDDIR)/coverage
+\t@echo "Testing of coverage in the sources finished, look at the " \\
+\t "results in $(BUILDDIR)/coverage/python.txt."
+
xml:
\t$(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml
\t@echo
@@ -632,6 +686,7 @@ if "%%1" == "help" (
\techo. pseudoxml to make pseudoxml-XML files for display purposes
\techo. linkcheck to check all external links for integrity
\techo. doctest to run all doctests embedded in the documentation if enabled
+\techo. coverage to run coverage check of the documentation if enabled
\tgoto end
)
@@ -642,6 +697,14 @@ if "%%1" == "clean" (
)
+REM Check if sphinx-build is available and fallback to Python version if any
+%%SPHINXBUILD%% 2> nul
+if errorlevel 9009 goto sphinx_python
+goto sphinx_ok
+
+:sphinx_python
+
+set SPHINXBUILD=python -m sphinx.__init__
%%SPHINXBUILD%% 2> nul
if errorlevel 9009 (
\techo.
@@ -655,6 +718,9 @@ if errorlevel 9009 (
\texit /b 1
)
+:sphinx_ok
+
+
if "%%1" == "html" (
\t%%SPHINXBUILD%% -b html %%ALLSPHINXOPTS%% %%BUILDDIR%%/html
\tif errorlevel 1 exit /b 1
@@ -744,7 +810,7 @@ if "%%1" == "latexpdf" (
\t%%SPHINXBUILD%% -b latex %%ALLSPHINXOPTS%% %%BUILDDIR%%/latex
\tcd %%BUILDDIR%%/latex
\tmake all-pdf
-\tcd %%BUILDDIR%%/..
+\tcd %%~dp0
\techo.
\techo.Build finished; the PDF files are in %%BUILDDIR%%/latex.
\tgoto end
@@ -754,7 +820,7 @@ if "%%1" == "latexpdfja" (
\t%%SPHINXBUILD%% -b latex %%ALLSPHINXOPTS%% %%BUILDDIR%%/latex
\tcd %%BUILDDIR%%/latex
\tmake all-pdf-ja
-\tcd %%BUILDDIR%%/..
+\tcd %%~dp0
\techo.
\techo.Build finished; the PDF files are in %%BUILDDIR%%/latex.
\tgoto end
@@ -818,6 +884,15 @@ results in %%BUILDDIR%%/doctest/output.txt.
\tgoto end
)
+if "%%1" == "coverage" (
+\t%%SPHINXBUILD%% -b coverage %%ALLSPHINXOPTS%% %%BUILDDIR%%/coverage
+\tif errorlevel 1 exit /b 1
+\techo.
+\techo.Testing of coverage in the sources finished, look at the ^
+results in %%BUILDDIR%%/coverage/python.txt.
+\tgoto end
+)
+
if "%%1" == "xml" (
\t%%SPHINXBUILD%% -b xml %%ALLSPHINXOPTS%% %%BUILDDIR%%/xml
\tif errorlevel 1 exit /b 1
@@ -918,16 +993,20 @@ def mkdir_p(dir):
class ValidationError(Exception):
"""Raised for validation errors."""
+
def is_path(x):
+ x = path.expanduser(x)
if path.exists(x) and not path.isdir(x):
raise ValidationError("Please enter a valid path name.")
return x
+
def nonempty(x):
if not x:
raise ValidationError("Please enter some text.")
return x
+
def choice(*l):
def val(x):
if x not in l:
@@ -935,17 +1014,20 @@ def choice(*l):
return x
return val
+
def boolean(x):
if x.upper() not in ('Y', 'YES', 'N', 'NO'):
raise ValidationError("Please enter either 'y' or 'n'.")
return x.upper() in ('Y', 'YES')
+
def suffix(x):
if not (x[0:1] == '.' and len(x) > 1):
raise ValidationError("Please enter a file suffix, "
"e.g. '.rst' or '.txt'.")
return x
+
def ok(x):
return x
@@ -956,16 +1038,16 @@ def do_prompt(d, key, text, default=None, validator=nonempty):
prompt = PROMPT_PREFIX + '%s [%s]: ' % (text, default)
else:
prompt = PROMPT_PREFIX + text + ': '
- if sys.version_info < (3, 0):
+ if PY2:
# for Python 2.x, try to get a Unicode string out of it
if prompt.encode('ascii', 'replace').decode('ascii', 'replace') \
!= prompt:
if TERM_ENCODING:
prompt = prompt.encode(TERM_ENCODING)
else:
- print turquoise('* Note: non-ASCII default value provided '
+ print(turquoise('* Note: non-ASCII default value provided '
'and terminal encoding unknown -- assuming '
- 'UTF-8 or Latin-1.')
+ 'UTF-8 or Latin-1.'))
try:
prompt = prompt.encode('utf-8')
except UnicodeEncodeError:
@@ -974,29 +1056,29 @@ def do_prompt(d, key, text, default=None, validator=nonempty):
x = term_input(prompt).strip()
if default and not x:
x = default
- if not isinstance(x, unicode):
+ if not isinstance(x, text_type):
# for Python 2.x, try to get a Unicode string out of it
if x.decode('ascii', 'replace').encode('ascii', 'replace') != x:
if TERM_ENCODING:
x = x.decode(TERM_ENCODING)
else:
- print turquoise('* Note: non-ASCII characters entered '
+ print(turquoise('* Note: non-ASCII characters entered '
'and terminal encoding unknown -- assuming '
- 'UTF-8 or Latin-1.')
+ 'UTF-8 or Latin-1.'))
try:
x = x.decode('utf-8')
except UnicodeDecodeError:
x = x.decode('latin1')
try:
x = validator(x)
- except ValidationError, err:
- print red('* ' + str(err))
+ except ValidationError as err:
+ print(red('* ' + str(err)))
continue
break
d[key] = x
-if sys.version_info >= (3, 0):
+if PY3:
# remove Unicode literal prefixes
def _convert_python_source(source, rex=re.compile(r"[uU]('.*?')")):
return rex.sub('\\1', source)
@@ -1019,6 +1101,7 @@ def ask_user(d):
* author: author names
* version: version of project
* release: release of project
+ * language: document language
* suffix: source file suffix
* master: master document name
* epub: use epub (bool)
@@ -1027,98 +1110,110 @@ def ask_user(d):
* batchfile: make command file
"""
- print bold('Welcome to the Sphinx %s quickstart utility.') % __version__
- print '''
+ print(bold('Welcome to the Sphinx %s quickstart utility.') % __version__)
+ print('''
Please enter values for the following settings (just press Enter to
-accept a default value, if one is given in brackets).'''
+accept a default value, if one is given in brackets).''')
if 'path' in d:
- print bold('''
-Selected root path: %s''' % d['path'])
+ print(bold('''
+Selected root path: %s''' % d['path']))
else:
- print '''
-Enter the root path for documentation.'''
+ print('''
+Enter the root path for documentation.''')
do_prompt(d, 'path', 'Root path for the documentation', '.', is_path)
while path.isfile(path.join(d['path'], 'conf.py')) or \
- path.isfile(path.join(d['path'], 'source', 'conf.py')):
- print
- print bold('Error: an existing conf.py has been found in the '
- 'selected root path.')
- print 'sphinx-quickstart will not overwrite existing Sphinx projects.'
- print
+ path.isfile(path.join(d['path'], 'source', 'conf.py')):
+ print()
+ print(bold('Error: an existing conf.py has been found in the '
+ 'selected root path.'))
+ print('sphinx-quickstart will not overwrite existing Sphinx projects.')
+ print()
do_prompt(d, 'path', 'Please enter a new root path (or just Enter '
'to exit)', '', is_path)
if not d['path']:
sys.exit(1)
if 'sep' not in d:
- print '''
+ print('''
You have two options for placing the build directory for Sphinx output.
Either, you use a directory "_build" within the root path, or you separate
-"source" and "build" directories within the root path.'''
+"source" and "build" directories within the root path.''')
do_prompt(d, 'sep', 'Separate source and build directories (y/n)', 'n',
boolean)
if 'dot' not in d:
- print '''
+ print('''
Inside the root directory, two more directories will be created; "_templates"
for custom HTML templates and "_static" for custom stylesheets and other static
-files. You can enter another prefix (such as ".") to replace the underscore.'''
+files. You can enter another prefix (such as ".") to replace the underscore.''')
do_prompt(d, 'dot', 'Name prefix for templates and static dir', '_', ok)
if 'project' not in d:
- print '''
-The project name will occur in several places in the built documentation.'''
+ print('''
+The project name will occur in several places in the built documentation.''')
do_prompt(d, 'project', 'Project name')
if 'author' not in d:
do_prompt(d, 'author', 'Author name(s)')
if 'version' not in d:
- print '''
+ print('''
Sphinx has the notion of a "version" and a "release" for the
software. Each version can have multiple releases. For example, for
Python the version is something like 2.5 or 3.0, while the release is
something like 2.5.1 or 3.0a1. If you don't need this dual structure,
-just set both to the same value.'''
+just set both to the same value.''')
do_prompt(d, 'version', 'Project version')
if 'release' not in d:
do_prompt(d, 'release', 'Project release', d['version'])
+ if 'language' not in d:
+ print('''
+If the documents are to be written in a language other than English,
+you can select a language here by its language code. Sphinx will then
+translate text that it generates into that language.
+
+For a list of supported codes, see
+http://sphinx-doc.org/config.html#confval-language.''')
+ do_prompt(d, 'language', 'Project language', 'en')
+ if d['language'] == 'en':
+ d['language'] = None
+
if 'suffix' not in d:
- print '''
+ print('''
The file name suffix for source files. Commonly, this is either ".txt"
-or ".rst". Only files with this suffix are considered documents.'''
+or ".rst". Only files with this suffix are considered documents.''')
do_prompt(d, 'suffix', 'Source file suffix', '.rst', suffix)
if 'master' not in d:
- print '''
+ print('''
One document is special in that it is considered the top node of the
"contents tree", that is, it is the root of the hierarchical structure
of the documents. Normally, this is "index", but if your "index"
-document is a custom template, you can also set this to another filename.'''
+document is a custom template, you can also set this to another filename.''')
do_prompt(d, 'master', 'Name of your master document (without suffix)',
'index')
while path.isfile(path.join(d['path'], d['master']+d['suffix'])) or \
- path.isfile(path.join(d['path'], 'source', d['master']+d['suffix'])):
- print
- print bold('Error: the master file %s has already been found in the '
- 'selected root path.' % (d['master']+d['suffix']))
- print 'sphinx-quickstart will not overwrite the existing file.'
- print
+ path.isfile(path.join(d['path'], 'source', d['master']+d['suffix'])):
+ print()
+ print(bold('Error: the master file %s has already been found in the '
+ 'selected root path.' % (d['master']+d['suffix'])))
+ print('sphinx-quickstart will not overwrite the existing file.')
+ print()
do_prompt(d, 'master', 'Please enter a new file name, or rename the '
'existing file and press Enter', d['master'])
if 'epub' not in d:
- print '''
-Sphinx can also add configuration for epub output:'''
+ print('''
+Sphinx can also add configuration for epub output:''')
do_prompt(d, 'epub', 'Do you want to use the epub builder (y/n)',
'n', boolean)
if 'ext_autodoc' not in d:
- print '''
-Please indicate if you want to use one of the following Sphinx extensions:'''
+ print('''
+Please indicate if you want to use one of the following Sphinx extensions:''')
do_prompt(d, 'ext_autodoc', 'autodoc: automatically insert docstrings '
'from modules (y/n)', 'n', boolean)
if 'ext_doctest' not in d:
@@ -1140,8 +1235,8 @@ Please indicate if you want to use one of the following Sphinx extensions:'''
do_prompt(d, 'ext_mathjax', 'mathjax: include math, rendered in the '
'browser by MathJax (y/n)', 'n', boolean)
if d['ext_pngmath'] and d['ext_mathjax']:
- print '''Note: pngmath and mathjax cannot be enabled at the same time.
-pngmath has been deselected.'''
+ print('''Note: pngmath and mathjax cannot be enabled at the same time.
+pngmath has been deselected.''')
d['ext_pngmath'] = False
if 'ext_ifconfig' not in d:
do_prompt(d, 'ext_ifconfig', 'ifconfig: conditional inclusion of '
@@ -1150,16 +1245,20 @@ pngmath has been deselected.'''
do_prompt(d, 'ext_viewcode', 'viewcode: include links to the source '
'code of documented Python objects (y/n)', 'n', boolean)
- if 'makefile' not in d:
- print '''
+ if 'no_makefile' in d:
+ d['makefile'] = False
+ elif 'makefile' not in d:
+ print('''
A Makefile and a Windows command file can be generated for you so that you
only have to run e.g. `make html' instead of invoking sphinx-build
-directly.'''
+directly.''')
do_prompt(d, 'makefile', 'Create Makefile? (y/n)', 'y', boolean)
- if 'batchfile' not in d:
+ if 'no_batchfile' in d:
+ d['batchfile'] = False
+ elif 'batchfile' not in d:
do_prompt(d, 'batchfile', 'Create Windows command file? (y/n)',
'y', boolean)
- print
+ print()
def generate(d, overwrite=True, silent=False):
@@ -1179,19 +1278,18 @@ def generate(d, overwrite=True, silent=False):
d['project_underline'] = column_width(d['project']) * '='
extensions = (',\n' + indent).join(
repr('sphinx.ext.' + name)
- for name in ('autodoc', 'doctest', 'intersphinx', 'todo', 'coverage',
- 'pngmath', 'mathjax', 'ifconfig', 'viewcode')
+ for name in EXTENSIONS
if d.get('ext_' + name))
if extensions:
d['extensions'] = '\n' + indent + extensions + ',\n'
else:
d['extensions'] = extensions
d['copyright'] = time.strftime('%Y') + ', ' + d['author']
- d['author_texescaped'] = unicode(d['author']).\
- translate(texescape.tex_escape_map)
+ d['author_texescaped'] = text_type(d['author']).\
+ translate(texescape.tex_escape_map)
d['project_doc'] = d['project'] + ' Documentation'
- d['project_doc_texescaped'] = unicode(d['project'] + ' Documentation').\
- translate(texescape.tex_escape_map)
+ d['project_doc_texescaped'] = text_type(d['project'] + ' Documentation').\
+ translate(texescape.tex_escape_map)
# escape backslashes and single quotes in strings that are put into
# a Python string literal
@@ -1218,14 +1316,14 @@ def generate(d, overwrite=True, silent=False):
def write_file(fpath, content, newline=None):
if overwrite or not path.isfile(fpath):
- print 'Creating file %s.' % fpath
+ print('Creating file %s.' % fpath)
f = open(fpath, 'wt', encoding='utf-8', newline=newline)
try:
f.write(content)
finally:
f.close()
else:
- print 'File %s already exists, skipping.' % fpath
+ print('File %s already exists, skipping.' % fpath)
conf_text = QUICKSTART_CONF % d
if d['epub']:
@@ -1238,22 +1336,22 @@ def generate(d, overwrite=True, silent=False):
masterfile = path.join(srcdir, d['master'] + d['suffix'])
write_file(masterfile, MASTER_FILE % d)
- if d['makefile']:
+ if d['makefile'] is True:
d['rsrcdir'] = d['sep'] and 'source' or '.'
d['rbuilddir'] = d['sep'] and 'build' or d['dot'] + 'build'
# use binary mode, to avoid writing \r\n on Windows
write_file(path.join(d['path'], 'Makefile'), MAKEFILE % d, u'\n')
- if d['batchfile']:
+ if d['batchfile'] is True:
d['rsrcdir'] = d['sep'] and 'source' or '.'
d['rbuilddir'] = d['sep'] and 'build' or d['dot'] + 'build'
write_file(path.join(d['path'], 'make.bat'), BATCHFILE % d, u'\r\n')
if silent:
return
- print
- print bold('Finished: An initial directory structure has been created.')
- print '''
+ print()
+ print(bold('Finished: An initial directory structure has been created.'))
+ print('''
You should now populate your master file %s and create other documentation
source files. ''' % masterfile + ((d['makefile'] or d['batchfile']) and '''\
Use the Makefile to build the docs, like so:
@@ -1263,23 +1361,144 @@ Use the sphinx-build command to build the docs, like so:
sphinx-build -b builder %s %s
''' % (srcdir, builddir)) + '''\
where "builder" is one of the supported builders, e.g. html, latex or linkcheck.
-'''
+''')
+
+
+def usage(argv, msg=None):
+ if msg:
+ print(msg, file=sys.stderr)
+ print(file=sys.stderr)
+
+USAGE = """\
+Sphinx v%s
+Usage: %%prog [options] [projectdir]
+""" % __version__
+
+EPILOG = """\
+For more information, visit <http://sphinx-doc.org/>.
+"""
+
+
+class MyFormatter(optparse.IndentedHelpFormatter):
+ def format_usage(self, usage):
+ return usage
+
+ def format_help(self, formatter):
+ result = []
+ if self.description:
+ result.append(self.format_description(formatter))
+ if self.option_list:
+ result.append(self.format_option_help(formatter))
+ return "\n".join(result)
def main(argv=sys.argv):
if not color_terminal():
nocolor()
- d = {}
- if len(argv) > 3:
- print 'Usage: sphinx-quickstart [root]'
- sys.exit(1)
- elif len(argv) == 2:
- d['path'] = argv[1]
+ parser = optparse.OptionParser(USAGE, epilog=EPILOG,
+ version='Sphinx v%s' % __version__,
+ formatter=MyFormatter())
+ parser.add_option('-q', '--quiet', action='store_true', dest='quiet',
+ default=False,
+ help='quiet mode')
+
+ group = parser.add_option_group('Structure options')
+ group.add_option('--sep', action='store_true', dest='sep',
+ help='if specified, separate source and build dirs')
+ group.add_option('--dot', metavar='DOT', dest='dot',
+ help='replacement for dot in _templates etc.')
+
+ group = parser.add_option_group('Project basic options')
+ group.add_option('-p', '--project', metavar='PROJECT', dest='project',
+ help='project name')
+ group.add_option('-a', '--author', metavar='AUTHOR', dest='author',
+ help='author names')
+ group.add_option('-v', metavar='VERSION', dest='version',
+ help='version of project')
+ group.add_option('-r', '--release', metavar='RELEASE', dest='release',
+ help='release of project')
+ group.add_option('-l', '--language', metavar='LANGUAGE', dest='language',
+ help='document language')
+ group.add_option('--suffix', metavar='SUFFIX', dest='suffix',
+ help='source file suffix')
+ group.add_option('--master', metavar='MASTER', dest='master',
+ help='master document name')
+ group.add_option('--epub', action='store_true', dest='epub',
+ default=False,
+ help='use epub')
+
+ group = parser.add_option_group('Extension options')
+ for ext in EXTENSIONS:
+ group.add_option('--ext-' + ext, action='store_true',
+ dest='ext_' + ext, default=False,
+ help='enable %s extension' % ext)
+
+ group = parser.add_option_group('Makefile and Batchfile creation')
+ group.add_option('--makefile', action='store_true', dest='makefile',
+ default=False,
+ help='create makefile')
+ group.add_option('--no-makefile', action='store_true', dest='no_makefile',
+ default=False,
+ help='not create makefile')
+ group.add_option('--batchfile', action='store_true', dest='batchfile',
+ default=False,
+ help='create batchfile')
+ group.add_option('--no-batchfile', action='store_true', dest='no_batchfile',
+ default=False,
+ help='not create batchfile')
+
+ # parse options
try:
- ask_user(d)
+ opts, args = parser.parse_args()
+ except SystemExit as err:
+ return err.code
+
+ if len(args) > 0:
+ opts.ensure_value('path', args[0])
+
+ d = vars(opts)
+ for k, v in list(d.items()):
+ # delete None or False value
+ if v is None or v is False:
+ del d[k]
+
+ try:
+ if 'quiet' in d:
+ if 'project' not in d or 'author' not in d or \
+ 'version' not in d:
+ print('''"quiet" is specified, but any of "project", \
+"author" or "version" is not specified.''')
+ return
+
+ if all(['quiet' in d, 'project' in d, 'author' in d,
+ 'version' in d]):
+ # quiet mode with all required params satisfied, use default
+ d.setdefault('release', d['version'])
+ d2 = DEFAULT_VALUE.copy()
+ d2.update(dict(("ext_"+ext, False) for ext in EXTENSIONS))
+ d2.update(d)
+ d = d2
+ if 'no_makefile' in d:
+ d['makefile'] = False
+ if 'no_batchfile' in d:
+ d['batchfile'] = False
+
+ if path.exists(d['path']) and (
+ not path.isdir(d['path']) or os.listdir(d['path'])):
+ print()
+ print(bold('Error: specified path is not a directory, or not a'
+ ' empty directory.'))
+ print('sphinx-quickstart only generate into a empty directory.'
+ ' Please specify a new root path.')
+ return
+ else:
+ ask_user(d)
except (KeyboardInterrupt, EOFError):
- print
- print '[Interrupted.]'
+ print()
+ print('[Interrupted.]')
return
generate(d)
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv))