1313# limitations under the License.
1414
1515from __future__ import print_function
16+
17+ import fnmatch
1618import os
19+ import shutil
1720import sys
1821import json
1922import warnings
2023from pathlib import Path
24+ from sysconfig import get_config_vars
2125
2226if __name__ == '__main__' and sys .argv [1 ] == "gevent_nosetests" :
2327 print ("Running gevent tests" )
2933 from eventlet import monkey_patch
3034 monkey_patch ()
3135
32- from setuptools import setup
33- from distutils .command .build_ext import build_ext
34- from distutils .core import Extension
35- from distutils .errors import (CCompilerError , DistutilsPlatformError ,
36- DistutilsExecError )
37- from distutils .cmd import Command
36+ from setuptools .command .build_ext import build_ext
37+ from setuptools import Extension , Command , setup
38+ from setuptools .errors import (CCompilerError , PlatformError ,
39+ ExecError )
3840
3941try :
4042 import subprocess
@@ -226,6 +228,7 @@ def __init__(self, *args, **kwargs):
226228
227229
228230class build_extensions (build_ext ):
231+ _needs_stub = False
229232
230233 error_message = """
231234===============================================================================
@@ -281,7 +284,7 @@ def run(self):
281284 try :
282285 self ._setup_extensions ()
283286 build_ext .run (self )
284- except DistutilsPlatformError as exc :
287+ except PlatformError as exc :
285288 sys .stderr .write ('%s\n ' % str (exc ))
286289 warnings .warn (self .error_message % "C extensions." )
287290 if CASS_DRIVER_BUILD_EXTENSIONS_ARE_MUST :
@@ -299,9 +302,9 @@ def build_extensions(self):
299302
300303 def build_extension (self , ext ):
301304 try :
302- build_ext .build_extension (self , ext )
303- except (CCompilerError , DistutilsExecError ,
304- DistutilsPlatformError , IOError ) as exc :
305+ build_ext .build_extension (self , fix_extension_class ( ext ) )
306+ except (CCompilerError , ExecError ,
307+ PlatformError , IOError ) as exc :
305308 sys .stderr .write ('%s\n ' % str (exc ))
306309 name = "The %s extension" % (ext .name ,)
307310 warnings .warn (self .error_message % (name ,))
@@ -344,6 +347,13 @@ def _setup_extensions(self):
344347 if CASS_DRIVER_BUILD_EXTENSIONS_ARE_MUST :
345348 raise
346349
350+
351+ def fix_extension_class (ext : Extension ) -> Extension :
352+ # Avoid bug in setuptools that requires _needs_stub
353+ ext ._needs_stub = False
354+ return ext
355+
356+
347357def pre_build_check ():
348358 """
349359 Try to verify build tools
@@ -352,9 +362,9 @@ def pre_build_check():
352362 return True
353363
354364 try :
355- from distutils .ccompiler import new_compiler
356- from distutils .sysconfig import customize_compiler
357- from distutils .dist import Distribution
365+ from setuptools . _distutils .ccompiler import new_compiler
366+ from setuptools . _distutils .sysconfig import customize_compiler
367+ from setuptools .dist import Distribution
358368
359369 # base build_ext just to emulate compiler option setup
360370 be = build_ext (Distribution ())
@@ -384,9 +394,8 @@ def pre_build_check():
384394 executables = [getattr (compiler , exe ) for exe in ('cc' , 'linker' )]
385395
386396 if executables :
387- from distutils .spawn import find_executable
388397 for exe in executables :
389- if not find_executable (exe ):
398+ if not shutil . which (exe ):
390399 sys .stderr .write ("Failed to find %s for compiler type %s.\n " % (exe , compiler .compiler_type ))
391400 return False
392401
0 commit comments