Skip to content

Commit 4ddbee4

Browse files
committed
Fix console_scripts entry points
1 parent 4add50a commit 4ddbee4

File tree

5 files changed

+27
-14
lines changed

5 files changed

+27
-14
lines changed

sphinx/cmd/build.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import sys
1313
import traceback
1414
from os import path
15-
from typing import Any, TextIO
15+
from typing import TYPE_CHECKING, Any, TextIO
1616

1717
from docutils.utils import SystemMessage
1818

@@ -32,6 +32,9 @@
3232
from sphinx.util.exceptions import format_exception_cut_frames, save_traceback
3333
from sphinx.util.osutil import ensuredir
3434

35+
if TYPE_CHECKING:
36+
from collections.abc import Sequence
37+
3538

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

206209

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

212215

213-
def _parse_arguments(argv: list[str]) -> argparse.Namespace:
216+
def _parse_arguments(argv: Sequence[str]) -> argparse.Namespace:
214217
parser = get_parser()
215218
args = parser.parse_args(argv)
216219

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

281284

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

@@ -319,10 +322,13 @@ def _bug_report_info() -> int:
319322
return 0
320323

321324

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

329+
if not argv:
330+
argv = sys.argv[1:]
331+
326332
if argv[:1] == ['--bug-report']:
327333
return _bug_report_info()
328334
if argv[:1] == ['-M']:

sphinx/cmd/make_mode.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import subprocess
1414
import sys
1515
from os import path
16+
from typing import TYPE_CHECKING
1617

1718
import sphinx
1819
from sphinx.cmd.build import build_main
@@ -29,6 +30,9 @@
2930
except ImportError:
3031
from sphinx.util.osutil import _chdir as chdir
3132

33+
if TYPE_CHECKING:
34+
from collections.abc import Sequence
35+
3236
BUILDERS = [
3337
("", "html", "to make standalone HTML files"),
3438
("", "dirhtml", "to make HTML files named index.html in directories"),
@@ -59,10 +63,10 @@
5963

6064

6165
class Make:
62-
def __init__(self, srcdir: str, builddir: str, opts: list[str]) -> None:
66+
def __init__(self, srcdir: str, builddir: str, opts: Sequence[str]) -> None:
6367
self.srcdir = srcdir
6468
self.builddir = builddir
65-
self.opts = opts
69+
self.opts = [*opts]
6670
self.makecmd = os.environ.get('MAKE', 'make') # refer $MAKE to determine make command
6771

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

161165

162-
def run_make_mode(args: list[str]) -> int:
166+
def run_make_mode(args: Sequence[str]) -> int:
163167
if len(args) < 3:
164168
print('Error: at least 3 arguments (builder, source '
165169
'dir, build dir) are required.', file=sys.stderr)

sphinx/cmd/quickstart.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
from sphinx.util.osutil import ensuredir
4242
from sphinx.util.template import SphinxRenderer
4343

44+
if TYPE_CHECKING:
45+
from collections.abc import Sequence
46+
4447
EXTENSIONS = {
4548
'autodoc': __('automatically insert docstrings from modules'),
4649
'doctest': __('automatically test code snippets in doctest blocks'),
@@ -545,7 +548,7 @@ def get_parser() -> argparse.ArgumentParser:
545548
return parser
546549

547550

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

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

sphinx/ext/apidoc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,13 +409,13 @@ def get_parser() -> argparse.ArgumentParser:
409409
return parser
410410

411411

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

417417
parser = get_parser()
418-
args = parser.parse_args(argv)
418+
args = parser.parse_args(argv or sys.argv[1:])
419419

420420
rootpath = path.abspath(args.module_path)
421421

sphinx/ext/autosummary/generate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -729,14 +729,14 @@ def get_parser() -> argparse.ArgumentParser:
729729
return parser
730730

731731

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

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

741741
if args.templates:
742742
app.config.templates_path.append(path.abspath(args.templates))

0 commit comments

Comments
 (0)