summaryrefslogtreecommitdiff
path: root/sphinx/cmd/quickstart.py
diff options
context:
space:
mode:
authorAdam Turner <9087854+aa-turner@users.noreply.github.com>2022-09-09 09:58:24 +0100
committerAdam Turner <9087854+aa-turner@users.noreply.github.com>2022-09-09 09:58:24 +0100
commit14c9b40f1549d4a51c6816793af011b0e901328b (patch)
tree404af9a945766ee61bc11a08e2b5df14179d1abe /sphinx/cmd/quickstart.py
parent5c82449eca73ef448eb7fdfbcc061cb91d70c18c (diff)
parentfe2f96ac99ae3261bca4a66b989149f13abaa212 (diff)
downloadsphinx-git-14c9b40f1549d4a51c6816793af011b0e901328b.tar.gz
Merge branch '5.x'
# Conflicts: # setup.py # sphinx/application.py # sphinx/environment/__init__.py # sphinx/ext/autodoc/directive.py # tests/test_build_html.py
Diffstat (limited to 'sphinx/cmd/quickstart.py')
-rw-r--r--sphinx/cmd/quickstart.py25
1 files changed, 14 insertions, 11 deletions
diff --git a/sphinx/cmd/quickstart.py b/sphinx/cmd/quickstart.py
index d8d4d3297..f9e3546bc 100644
--- a/sphinx/cmd/quickstart.py
+++ b/sphinx/cmd/quickstart.py
@@ -7,14 +7,14 @@ import sys
import time
from collections import OrderedDict
from os import path
-from typing import TYPE_CHECKING, Any, Callable, Dict, List, Union
+from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Union
# try to import readline, unix specific enhancement
try:
import readline
if TYPE_CHECKING and sys.platform == "win32": # always false, for type checking
raise ImportError
-
+ READLINE_AVAILABLE = True
if readline.__doc__ and 'libedit' in readline.__doc__:
readline.parse_and_bind("bind ^I rl_complete")
USE_LIBEDIT = True
@@ -22,7 +22,7 @@ try:
readline.parse_and_bind("tab: complete")
USE_LIBEDIT = False
except ImportError:
- readline = None
+ READLINE_AVAILABLE = False
USE_LIBEDIT = False
from docutils.utils import column_width
@@ -130,7 +130,9 @@ def ok(x: str) -> str:
return x
-def do_prompt(text: str, default: str = None, validator: Callable[[str], Any] = nonempty) -> Union[str, bool]: # NOQA
+def do_prompt(
+ text: str, default: Optional[str] = None, validator: Callable[[str], Any] = nonempty
+) -> Union[str, bool]:
while True:
if default is not None:
prompt = PROMPT_PREFIX + '%s [%s]: ' % (text, default)
@@ -141,7 +143,7 @@ def do_prompt(text: str, default: str = None, validator: Callable[[str], Any] =
# sequence (see #5335). To avoid the problem, all prompts are not colored
# on libedit.
pass
- elif readline:
+ elif READLINE_AVAILABLE:
# pass input_mode=True if readline available
prompt = colorize(COLOR_QUESTION, prompt, input_mode=True)
else:
@@ -159,8 +161,8 @@ def do_prompt(text: str, default: str = None, validator: Callable[[str], Any] =
class QuickstartRenderer(SphinxRenderer):
- def __init__(self, templatedir: str) -> None:
- self.templatedir = templatedir or ''
+ def __init__(self, templatedir: str = '') -> None:
+ self.templatedir = templatedir
super().__init__()
def _has_custom_template(self, template_name: str) -> bool:
@@ -321,10 +323,11 @@ def ask_user(d: Dict[str, Any]) -> None:
print()
-def generate(d: Dict, overwrite: bool = True, silent: bool = False, templatedir: str = None
- ) -> None:
+def generate(
+ d: Dict, overwrite: bool = True, silent: bool = False, templatedir: Optional[str] = None
+) -> None:
"""Generate project based on values in *d*."""
- template = QuickstartRenderer(templatedir=templatedir)
+ template = QuickstartRenderer(templatedir or '')
if 'mastertoctree' not in d:
d['mastertoctree'] = ''
@@ -357,7 +360,7 @@ def generate(d: Dict, overwrite: bool = True, silent: bool = False, templatedir:
ensuredir(path.join(srcdir, d['dot'] + 'templates'))
ensuredir(path.join(srcdir, d['dot'] + 'static'))
- def write_file(fpath: str, content: str, newline: str = None) -> None:
+ def write_file(fpath: str, content: str, newline: Optional[str] = None) -> None:
if overwrite or not path.isfile(fpath):
if 'quiet' not in d:
print(__('Creating file %s.') % fpath)