Skip to content

Commit 3873836

Browse files
authored
Merge pull request #10490 from tk0miya/9820_use_setuptools.Command
Close #9820: Use setuptools.Command if available
2 parents f1bf5b8 + bc57599 commit 3873836

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

sphinx/setup_command.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
import os
77
import sys
88
import warnings
9-
from distutils.cmd import Command
10-
from distutils.errors import DistutilsExecError
119
from io import StringIO
1210
from typing import Any, Dict
1311

@@ -18,6 +16,13 @@
1816
from sphinx.util.docutils import docutils_namespace, patch_docutils
1917
from sphinx.util.osutil import abspath
2018

19+
try:
20+
from setuptools import Command
21+
from setuptools.errors import ExecError
22+
except ImportError:
23+
from distutils.cmd import Command
24+
from distutils.errors import DistutilsExecError as ExecError
25+
2126

2227
class BuildDoc(Command):
2328
"""
@@ -97,7 +102,7 @@ def initialize_options(self) -> None:
97102
self.link_index = False
98103
self.copyright = ''
99104
# Link verbosity to distutils' (which uses 1 by default).
100-
self.verbosity = self.distribution.verbose - 1 # type: ignore
105+
self.verbosity = self.distribution.verbose - 1
101106
self.traceback = False
102107
self.nitpicky = False
103108
self.keep_going = False
@@ -125,7 +130,7 @@ def finalize_options(self) -> None:
125130

126131
if self.build_dir is None:
127132
build = self.get_finalized_command('build')
128-
self.build_dir = os.path.join(abspath(build.build_base), 'sphinx') # type: ignore
133+
self.build_dir = os.path.join(abspath(build.build_base), 'sphinx')
129134

130135
self.doctree_dir = os.path.join(self.build_dir, 'doctrees')
131136

@@ -139,7 +144,7 @@ def run(self) -> None:
139144

140145
if not color_terminal():
141146
nocolor()
142-
if not self.verbose: # type: ignore
147+
if not self.verbose:
143148
status_stream = StringIO()
144149
else:
145150
status_stream = sys.stdout # type: ignore
@@ -171,8 +176,7 @@ def run(self) -> None:
171176
verbosity=self.verbosity, keep_going=self.keep_going)
172177
app.build(force_all=self.all_files)
173178
if app.statuscode:
174-
raise DistutilsExecError(
175-
'caused by %s builder.' % app.builder.name)
179+
raise ExecError('caused by %s builder.' % app.builder.name)
176180
except Exception as exc:
177181
handle_exception(app, self, exc, sys.stderr)
178182
if not self.pdb:

0 commit comments

Comments
 (0)