Skip to content

Commit

Permalink
Fix console_scripts entry points
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner committed Aug 17, 2023
1 parent 4add50a commit 4ddbee4
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 14 deletions.
16 changes: 11 additions & 5 deletions sphinx/cmd/build.py
Expand Up @@ -12,7 +12,7 @@
import sys
import traceback
from os import path
from typing import Any, TextIO
from typing import TYPE_CHECKING, Any, TextIO

from docutils.utils import SystemMessage

Expand All @@ -32,6 +32,9 @@
from sphinx.util.exceptions import format_exception_cut_frames, save_traceback
from sphinx.util.osutil import ensuredir

if TYPE_CHECKING:
from collections.abc import Sequence


def handle_exception(
app: Sphinx | None, args: Any, exception: BaseException, stderr: TextIO = sys.stderr,
Expand Down Expand Up @@ -204,13 +207,13 @@ def get_parser() -> argparse.ArgumentParser:
return parser


def make_main(argv: list[str]) -> int:
def make_main(argv: Sequence[str]) -> int:
"""Sphinx build "make mode" entry."""
from sphinx.cmd import make_mode
return make_mode.run_make_mode(argv[1:])


def _parse_arguments(argv: list[str]) -> argparse.Namespace:
def _parse_arguments(argv: Sequence[str]) -> argparse.Namespace:
parser = get_parser()
args = parser.parse_args(argv)

Expand Down Expand Up @@ -279,7 +282,7 @@ def _parse_arguments(argv: list[str]) -> argparse.Namespace:
return args


def build_main(argv: list[str]) -> int:
def build_main(argv: Sequence[str]) -> int:
"""Sphinx build "main" command-line entry."""
args = _parse_arguments(argv)

Expand Down Expand Up @@ -319,10 +322,13 @@ def _bug_report_info() -> int:
return 0


def main(argv: list[str], /) -> int:
def main(argv: Sequence[str] = (), /) -> int:
locale.setlocale(locale.LC_ALL, '')
sphinx.locale.init_console()

if not argv:
argv = sys.argv[1:]

if argv[:1] == ['--bug-report']:
return _bug_report_info()
if argv[:1] == ['-M']:
Expand Down
10 changes: 7 additions & 3 deletions sphinx/cmd/make_mode.py
Expand Up @@ -13,6 +13,7 @@
import subprocess
import sys
from os import path
from typing import TYPE_CHECKING

import sphinx
from sphinx.cmd.build import build_main
Expand All @@ -29,6 +30,9 @@
except ImportError:
from sphinx.util.osutil import _chdir as chdir

if TYPE_CHECKING:
from collections.abc import Sequence

BUILDERS = [
("", "html", "to make standalone HTML files"),
("", "dirhtml", "to make HTML files named index.html in directories"),
Expand Down Expand Up @@ -59,10 +63,10 @@


class Make:
def __init__(self, srcdir: str, builddir: str, opts: list[str]) -> None:
def __init__(self, srcdir: str, builddir: str, opts: Sequence[str]) -> None:
self.srcdir = srcdir
self.builddir = builddir
self.opts = opts
self.opts = [*opts]
self.makecmd = os.environ.get('MAKE', 'make') # refer $MAKE to determine make command

def builddir_join(self, *comps: str) -> str:
Expand Down Expand Up @@ -159,7 +163,7 @@ def run_generic_build(self, builder: str, doctreedir: str | None = None) -> int:
return build_main(args + opts)


def run_make_mode(args: list[str]) -> int:
def run_make_mode(args: Sequence[str]) -> int:
if len(args) < 3:
print('Error: at least 3 arguments (builder, source '
'dir, build dir) are required.', file=sys.stderr)
Expand Down
7 changes: 5 additions & 2 deletions sphinx/cmd/quickstart.py
Expand Up @@ -41,6 +41,9 @@
from sphinx.util.osutil import ensuredir
from sphinx.util.template import SphinxRenderer

if TYPE_CHECKING:
from collections.abc import Sequence

EXTENSIONS = {
'autodoc': __('automatically insert docstrings from modules'),
'doctest': __('automatically test code snippets in doctest blocks'),
Expand Down Expand Up @@ -545,7 +548,7 @@ def get_parser() -> argparse.ArgumentParser:
return parser


def main(argv: list[str], /) -> int:
def main(argv: Sequence[str] = (), /) -> int:
locale.setlocale(locale.LC_ALL, '')
sphinx.locale.init_console()

Expand All @@ -555,7 +558,7 @@ def main(argv: list[str], /) -> int:
# parse options
parser = get_parser()
try:
args = parser.parse_args(argv)
args = parser.parse_args(argv or sys.argv[1:])
except SystemExit as err:
return err.code # type: ignore[return-value]

Expand Down
4 changes: 2 additions & 2 deletions sphinx/ext/apidoc.py
Expand Up @@ -409,13 +409,13 @@ def get_parser() -> argparse.ArgumentParser:
return parser


def main(argv: list[str], /) -> int:
def main(argv: Sequence[str] = (), /) -> int:
"""Parse and check the command line arguments."""
locale.setlocale(locale.LC_ALL, '')
sphinx.locale.init_console()

parser = get_parser()
args = parser.parse_args(argv)
args = parser.parse_args(argv or sys.argv[1:])

rootpath = path.abspath(args.module_path)

Expand Down
4 changes: 2 additions & 2 deletions sphinx/ext/autosummary/generate.py
Expand Up @@ -729,14 +729,14 @@ def get_parser() -> argparse.ArgumentParser:
return parser


def main(argv: list[str], /) -> None:
def main(argv: Sequence[str] = (), /) -> None:
locale.setlocale(locale.LC_ALL, '')
sphinx.locale.init_console()

app = DummyApplication(sphinx.locale.get_translator())
logging.setup(app, sys.stdout, sys.stderr) # type: ignore[arg-type]
setup_documenters(app)
args = get_parser().parse_args(argv)
args = get_parser().parse_args(argv or sys.argv[1:])

if args.templates:
app.config.templates_path.append(path.abspath(args.templates))
Expand Down

0 comments on commit 4ddbee4

Please sign in to comment.