mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Migrate to py3 style type annotation: sphinx.cmd.build
This commit is contained in:
parent
afefeebb52
commit
fdc2bee7d3
@ -14,6 +14,7 @@ import multiprocessing
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
|
from typing import Any, IO, List
|
||||||
|
|
||||||
from docutils.utils import SystemMessage
|
from docutils.utils import SystemMessage
|
||||||
|
|
||||||
@ -26,13 +27,8 @@ from sphinx.util import Tee, format_exception_cut_frames, save_traceback
|
|||||||
from sphinx.util.console import red, nocolor, color_terminal, terminal_safe # type: ignore
|
from sphinx.util.console import red, nocolor, color_terminal, terminal_safe # type: ignore
|
||||||
from sphinx.util.docutils import docutils_namespace, patch_docutils
|
from sphinx.util.docutils import docutils_namespace, patch_docutils
|
||||||
|
|
||||||
if False:
|
|
||||||
# For type annotation
|
|
||||||
from typing import Any, IO, List, Union # NOQA
|
|
||||||
|
|
||||||
|
def handle_exception(app: Sphinx, args: Any, exception: BaseException, stderr: IO = sys.stderr) -> None: # NOQA
|
||||||
def handle_exception(app, args, exception, stderr=sys.stderr):
|
|
||||||
# type: (Sphinx, Any, Union[Exception, KeyboardInterrupt], IO) -> None
|
|
||||||
if args.pdb:
|
if args.pdb:
|
||||||
import pdb
|
import pdb
|
||||||
print(red(__('Exception occurred while building, starting debugger:')),
|
print(red(__('Exception occurred while building, starting debugger:')),
|
||||||
@ -82,8 +78,7 @@ def handle_exception(app, args, exception, stderr=sys.stderr):
|
|||||||
file=stderr)
|
file=stderr)
|
||||||
|
|
||||||
|
|
||||||
def jobs_argument(value):
|
def jobs_argument(value: str) -> int:
|
||||||
# type: (str) -> int
|
|
||||||
"""
|
"""
|
||||||
Special type to handle 'auto' flags passed to 'sphinx-build' via -j flag. Can
|
Special type to handle 'auto' flags passed to 'sphinx-build' via -j flag. Can
|
||||||
be expanded to handle other special scaling requests, such as setting job count
|
be expanded to handle other special scaling requests, such as setting job count
|
||||||
@ -99,8 +94,7 @@ def jobs_argument(value):
|
|||||||
return jobs
|
return jobs
|
||||||
|
|
||||||
|
|
||||||
def get_parser():
|
def get_parser() -> argparse.ArgumentParser:
|
||||||
# type: () -> argparse.ArgumentParser
|
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
usage='%(prog)s [OPTIONS] SOURCEDIR OUTPUTDIR [FILENAMES...]',
|
usage='%(prog)s [OPTIONS] SOURCEDIR OUTPUTDIR [FILENAMES...]',
|
||||||
epilog=__('For more information, visit <http://sphinx-doc.org/>.'),
|
epilog=__('For more information, visit <http://sphinx-doc.org/>.'),
|
||||||
@ -195,15 +189,13 @@ files can be built by specifying individual filenames.
|
|||||||
return parser
|
return parser
|
||||||
|
|
||||||
|
|
||||||
def make_main(argv=sys.argv[1:]):
|
def make_main(argv: List[str] = sys.argv[1:]) -> int:
|
||||||
# type: (List[str]) -> int
|
|
||||||
"""Sphinx build "make mode" entry."""
|
"""Sphinx build "make mode" entry."""
|
||||||
from sphinx.cmd import make_mode
|
from sphinx.cmd import make_mode
|
||||||
return make_mode.run_make_mode(argv[1:])
|
return make_mode.run_make_mode(argv[1:])
|
||||||
|
|
||||||
|
|
||||||
def build_main(argv=sys.argv[1:]):
|
def build_main(argv: List[str] = sys.argv[1:]) -> int:
|
||||||
# type: (List[str]) -> int
|
|
||||||
"""Sphinx build "main" command-line entry."""
|
"""Sphinx build "main" command-line entry."""
|
||||||
|
|
||||||
parser = get_parser()
|
parser = get_parser()
|
||||||
@ -288,8 +280,7 @@ def build_main(argv=sys.argv[1:]):
|
|||||||
return 2
|
return 2
|
||||||
|
|
||||||
|
|
||||||
def main(argv=sys.argv[1:]):
|
def main(argv: List[str] = sys.argv[1:]) -> int:
|
||||||
# type: (List[str]) -> int
|
|
||||||
sphinx.locale.setlocale(locale.LC_ALL, '')
|
sphinx.locale.setlocale(locale.LC_ALL, '')
|
||||||
sphinx.locale.init_console(os.path.join(package_dir, 'locale'), 'sphinx')
|
sphinx.locale.init_console(os.path.join(package_dir, 'locale'), 'sphinx')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user