13
13
# limitations under the License.
14
14
15
15
from __future__ import print_function
16
+
17
+ import fnmatch
16
18
import os
19
+ import shutil
17
20
import sys
18
21
import json
19
22
import warnings
20
23
from pathlib import Path
24
+ from sysconfig import get_config_vars
21
25
22
26
if __name__ == '__main__' and sys .argv [1 ] == "gevent_nosetests" :
23
27
print ("Running gevent tests" )
29
33
from eventlet import monkey_patch
30
34
monkey_patch ()
31
35
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 )
38
40
39
41
try :
40
42
import subprocess
@@ -226,6 +228,7 @@ def __init__(self, *args, **kwargs):
226
228
227
229
228
230
class build_extensions (build_ext ):
231
+ _needs_stub = False
229
232
230
233
error_message = """
231
234
===============================================================================
@@ -281,7 +284,7 @@ def run(self):
281
284
try :
282
285
self ._setup_extensions ()
283
286
build_ext .run (self )
284
- except DistutilsPlatformError as exc :
287
+ except PlatformError as exc :
285
288
sys .stderr .write ('%s\n ' % str (exc ))
286
289
warnings .warn (self .error_message % "C extensions." )
287
290
if CASS_DRIVER_BUILD_EXTENSIONS_ARE_MUST :
@@ -299,9 +302,9 @@ def build_extensions(self):
299
302
300
303
def build_extension (self , ext ):
301
304
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 :
305
308
sys .stderr .write ('%s\n ' % str (exc ))
306
309
name = "The %s extension" % (ext .name ,)
307
310
warnings .warn (self .error_message % (name ,))
@@ -344,6 +347,13 @@ def _setup_extensions(self):
344
347
if CASS_DRIVER_BUILD_EXTENSIONS_ARE_MUST :
345
348
raise
346
349
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
+
347
357
def pre_build_check ():
348
358
"""
349
359
Try to verify build tools
@@ -352,9 +362,9 @@ def pre_build_check():
352
362
return True
353
363
354
364
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
358
368
359
369
# base build_ext just to emulate compiler option setup
360
370
be = build_ext (Distribution ())
@@ -384,9 +394,8 @@ def pre_build_check():
384
394
executables = [getattr (compiler , exe ) for exe in ('cc' , 'linker' )]
385
395
386
396
if executables :
387
- from distutils .spawn import find_executable
388
397
for exe in executables :
389
- if not find_executable (exe ):
398
+ if not shutil . which (exe ):
390
399
sys .stderr .write ("Failed to find %s for compiler type %s.\n " % (exe , compiler .compiler_type ))
391
400
return False
392
401
0 commit comments