[Python setuptools] Import error from distutils for lower version of setuptools (#35561)

Fix: https://github.com/grpc/grpc/issues/35555
<!--

If you know who should review your pull request, please assign it to
that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the
appropriate
lang label.

-->
pull/35597/head
Xuan Wang 1 year ago committed by GitHub
parent bc04417440
commit ad1dc17030
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 12
      src/python/grpcio/support.py

@ -18,7 +18,13 @@ import shutil
import sys
import tempfile
from setuptools import errors
try:
from setuptools.errors import CompileError
except ImportError:
# CompileError only exist for setuptools>=59.0.1, which becomes standard library
# after Python 3.10.6.
# TODO(xuanwn): Remove this once Python version floor is higher than 3.10.
from distutils.errors import CompileError
import commands
@ -58,7 +64,7 @@ def _compile(compiler, source_string):
cfile.write(source_string)
try:
compiler.compile([cpath])
except errors.CompileError as error:
except CompileError as error:
return error
finally:
shutil.rmtree(tempdir)
@ -108,7 +114,7 @@ def diagnose_attribute_error(build_ext, error):
_ERROR_DIAGNOSES = {
errors.CompileError: diagnose_compile_error,
CompileError: diagnose_compile_error,
AttributeError: diagnose_attribute_error,
}

Loading…
Cancel
Save