66import os
77import sys
88import warnings
9- from distutils .cmd import Command
10- from distutils .errors import DistutilsExecError
119from io import StringIO
1210from typing import Any , Dict
1311
1816from sphinx .util .docutils import docutils_namespace , patch_docutils
1917from 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
2227class 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