Skip to content

Commit 84a90a1

Browse files
committed
Close #9820: Use setuptools.Command if available
distutils was marked as deprecated since Python 3.10 (see PEP 632). And it will be removed since Python 3.12. To follow the deprecation, this starts to use `setuptools.Command` if available.
1 parent 873d9f6 commit 84a90a1

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

sphinx/setup_command.py

Lines changed: 8 additions & 4 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
"""
@@ -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)