25
25
"""
26
26
27
27
from distutils .command .build_ext import build_ext
28
- from distutils .command .build import build
29
28
from distutils .command .install import install
30
29
from distutils .command .install_lib import install_lib
31
30
from distutils .errors import DistutilsExecError
@@ -223,16 +222,25 @@ def _finalize_connector_c(self, connc_loc):
223
222
self ._mysql_config_info = None
224
223
min_version = BuildMySQLExt .min_connector_c_version
225
224
225
+ err_invalid_loc = "MySQL C API location is invalid; was %s"
226
+
226
227
mysql_config = None
227
228
err_version = "MySQL C API {0}.{1}.{2} or later required" .format (
228
229
* BuildMySQLExt .min_connector_c_version )
229
230
231
+ if not os .path .exists (connc_loc ):
232
+ log .error (err_invalid_loc , connc_loc )
233
+ sys .exit (1 )
234
+
230
235
if os .path .isdir (connc_loc ):
231
- # if directory, and no mysql_config is availble , figure out the
236
+ # if directory, and no mysql_config is available , figure out the
232
237
# lib/ and include/ folders from the the filesystem
233
238
mysql_config = os .path .join (connc_loc , 'bin' , 'mysql_config' )
234
- if not (os .path .isfile (mysql_config ) and
235
- os .access (mysql_config , os .X_OK )):
239
+ if os .path .isfile (mysql_config ) and \
240
+ os .access (mysql_config , os .X_OK ):
241
+ connc_loc = mysql_config
242
+ else :
243
+ # Probably using MS Windows
236
244
myconfigh = os .path .join (connc_loc , 'include' , 'my_config.h' )
237
245
238
246
if not os .path .exists (myconfigh ):
@@ -280,11 +288,10 @@ def _finalize_connector_c(self, connc_loc):
280
288
else :
281
289
self .arch = 'i386'
282
290
283
- # We were given the mysql_config, or we discovered it
284
- if not mysql_config :
291
+ # We were given the location of the mysql_config tool (not on Windows)
292
+ if not os .name == 'nt' and os .path .isfile (connc_loc ) \
293
+ and os .access (connc_loc , os .X_OK ):
285
294
mysql_config = connc_loc
286
-
287
- if os .path .isfile (mysql_config ) and os .access (mysql_config , os .X_OK ):
288
295
# Check mysql_config
289
296
myc_info = get_mysql_config_info (mysql_config )
290
297
@@ -299,8 +306,8 @@ def _finalize_connector_c(self, connc_loc):
299
306
self .arch = self ._mysql_config_info ['arch' ]
300
307
connc_64bit = self .arch == 'x86_64'
301
308
302
- else :
303
- log .error ("MySQL tool mysql_config not available" )
309
+ if not os . path . exists ( include_dir ) :
310
+ log .error (err_invalid_loc , connc_loc )
304
311
sys .exit (1 )
305
312
306
313
# Set up the build_ext class
@@ -404,6 +411,7 @@ def finalize_options(self):
404
411
install_lib .finalize_options (self )
405
412
self .set_undefined_options ('install' ,
406
413
('byte_code_only' , 'byte_code_only' ))
414
+ self .set_undefined_options ('build' , ('build_base' , 'build_dir' ))
407
415
408
416
def run (self ):
409
417
self .build ()
@@ -456,4 +464,6 @@ def run(self):
456
464
# We install pure Python code in purelib location when no
457
465
# extension is build
458
466
self .install_lib = self .install_purelib
467
+ else :
468
+ log .info ("installing C Extension" )
459
469
install .run (self )
0 commit comments