diff options
Diffstat (limited to 'sphinx/cmd/quickstart.py')
-rw-r--r-- | sphinx/cmd/quickstart.py | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/sphinx/cmd/quickstart.py b/sphinx/cmd/quickstart.py index 44a188b27..27d0cca62 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,7 +161,7 @@ def do_prompt(text: str, default: str = None, validator: Callable[[str], Any] = class QuickstartRenderer(SphinxRenderer): - def __init__(self, templatedir: str) -> None: + def __init__(self, templatedir: Optional[str]) -> None: self.templatedir = templatedir or '' super().__init__() @@ -321,8 +323,9 @@ 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) @@ -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) |