47
47
48
48
from setuptools .command .build_ext import build_ext
49
49
50
- from .utils import (
51
- ARCH ,
52
- ARCH_64BIT ,
53
- mysql_c_api_info ,
54
- write_info_bin ,
55
- write_info_src ,
56
- )
50
+ from .utils import ARCH , ARCH_64BIT , mysql_c_api_info , write_info_bin , write_info_src
57
51
58
52
# Load version information
59
53
VERSION = [999 , 0 , 0 , "a" , 0 ]
@@ -177,31 +171,25 @@ def finalize_options(self):
177
171
"MYSQL_CAPI"
178
172
)
179
173
cmd_build_ext .with_openssl_include_dir = (
180
- self .with_openssl_include_dir
181
- or os .environ .get ("OPENSSL_INCLUDE_DIR" )
174
+ self .with_openssl_include_dir or os .environ .get ("OPENSSL_INCLUDE_DIR" )
182
175
)
183
176
cmd_build_ext .with_openssl_lib_dir = (
184
177
self .with_openssl_lib_dir or os .environ .get ("OPENSSL_LIB_DIR" )
185
178
)
186
179
cmd_build_ext .with_protobuf_include_dir = (
187
- self .with_protobuf_include_dir
188
- or os .environ .get ("PROTOBUF_INCLUDE_DIR" )
180
+ self .with_protobuf_include_dir or os .environ .get ("PROTOBUF_INCLUDE_DIR" )
189
181
)
190
182
cmd_build_ext .with_protobuf_lib_dir = (
191
183
self .with_protobuf_lib_dir or os .environ .get ("PROTOBUF_LIB_DIR" )
192
184
)
193
- cmd_build_ext .with_protoc = self .with_protoc or os .environ .get (
194
- "PROTOC"
195
- )
196
- cmd_build_ext .extra_compile_args = (
197
- self .extra_compile_args or os .environ .get ("EXTRA_COMPILE_ARGS" )
185
+ cmd_build_ext .with_protoc = self .with_protoc or os .environ .get ("PROTOC" )
186
+ cmd_build_ext .extra_compile_args = self .extra_compile_args or os .environ .get (
187
+ "EXTRA_COMPILE_ARGS"
198
188
)
199
189
cmd_build_ext .extra_link_args = self .extra_link_args or os .environ .get (
200
190
"EXTRA_LINK_ARGS"
201
191
)
202
- cmd_build_ext .skip_vendor = self .skip_vendor or os .environ .get (
203
- "SKIP_VENDOR"
204
- )
192
+ cmd_build_ext .skip_vendor = self .skip_vendor or os .environ .get ("SKIP_VENDOR" )
205
193
if not cmd_build_ext .skip_vendor :
206
194
self ._copy_vendor_libraries ()
207
195
@@ -233,9 +221,7 @@ def remove_temp(self):
233
221
234
222
def _get_openssl_libs (self ):
235
223
libssl = glob (os .path .join (self .with_openssl_lib_dir , "libssl.*.*.*" ))
236
- libcrypto = glob (
237
- os .path .join (self .with_openssl_lib_dir , "libcrypto.*.*.*" )
238
- )
224
+ libcrypto = glob (os .path .join (self .with_openssl_lib_dir , "libcrypto.*.*.*" ))
239
225
if not libssl or not libcrypto :
240
226
self .log .error (
241
227
"Unable to find OpenSSL libraries in '%s'" ,
@@ -251,9 +237,7 @@ def _copy_vendor_libraries(self):
251
237
# Bundle OpenSSL libs
252
238
if self .with_openssl_lib_dir :
253
239
libssl , libcrypto = self ._get_openssl_libs ()
254
- vendor_libs .append (
255
- (self .with_openssl_lib_dir , [libssl , libcrypto ])
256
- )
240
+ vendor_libs .append ((self .with_openssl_lib_dir , [libssl , libcrypto ]))
257
241
258
242
# Plugins
259
243
bundle_plugin_libs = False
@@ -309,22 +293,16 @@ def _copy_vendor_libraries(self):
309
293
else :
310
294
openssl_libs = ["libssl-1_1.dll" , "libcrypto-1_1.dll" ]
311
295
if self .with_openssl_lib_dir :
312
- openssl_libs_path = os .path .abspath (
313
- self .with_openssl_lib_dir
314
- )
296
+ openssl_libs_path = os .path .abspath (self .with_openssl_lib_dir )
315
297
if os .path .basename (openssl_libs_path ) == "lib" :
316
298
openssl_libs_path = os .path .split (openssl_libs_path )[0 ]
317
299
if os .path .exists (openssl_libs_path ) and os .path .exists (
318
300
os .path .join (openssl_libs_path , "bin" )
319
301
):
320
- openssl_libs_path = os .path .join (
321
- openssl_libs_path , "bin"
322
- )
302
+ openssl_libs_path = os .path .join (openssl_libs_path , "bin" )
323
303
self .log .info ("# openssl_libs_path: %s" , openssl_libs_path )
324
304
else :
325
- openssl_libs_path = os .path .join (
326
- self .with_mysql_capi , "bin"
327
- )
305
+ openssl_libs_path = os .path .join (self .with_mysql_capi , "bin" )
328
306
vendor_libs .append ((openssl_libs_path , openssl_libs ))
329
307
330
308
if not vendor_libs :
@@ -358,27 +336,20 @@ def _copy_vendor_libraries(self):
358
336
if os .name == "nt" :
359
337
self .distribution .package_data = {"mysql" : ["vendor/plugin/*" ]}
360
338
site_packages_files = [
361
- os .path .join (openssl_libs_path , lib_n )
362
- for lib_n in openssl_libs
339
+ os .path .join (openssl_libs_path , lib_n ) for lib_n in openssl_libs
363
340
]
364
341
site_packages_files .append (
365
342
os .path .join (self .with_mysql_capi , "lib" , "libmysql.dll" )
366
343
)
367
344
self .distribution .data_files = [
368
345
("lib\\ site-packages\\ " , site_packages_files )
369
346
]
370
- self .log .debug (
371
- "# site_packages_files: %s" , self .distribution .data_files
372
- )
347
+ self .log .debug ("# site_packages_files: %s" , self .distribution .data_files )
373
348
elif bundle_plugin_libs :
374
349
# Bundle SASL libs
375
- sasl_libs_path = os .path .join (
376
- self .with_mysql_capi , "lib" , "private"
377
- )
350
+ sasl_libs_path = os .path .join (self .with_mysql_capi , "lib" , "private" )
378
351
if not os .path .exists (sasl_libs_path ):
379
- self .log .info (
380
- "sasl2 llibraries not found at %s" , sasl_libs_path
381
- )
352
+ self .log .info ("sasl2 llibraries not found at %s" , sasl_libs_path )
382
353
sasl_libs = []
383
354
sasl_plugin_libs_w = [
384
355
"libsasl2.*.*" ,
@@ -408,9 +379,7 @@ def _copy_vendor_libraries(self):
408
379
if not os .path .exists (src ):
409
380
self .log .warn ("Library not found: %s" , src )
410
381
continue
411
- dst = os .path .join (
412
- os .getcwd (), self .vendor_folder , "private"
413
- )
382
+ dst = os .path .join (os .getcwd (), self .vendor_folder , "private" )
414
383
self .log .info ("copying %s -> %s" , src , dst )
415
384
shutil .copy (src , dst )
416
385
@@ -420,9 +389,7 @@ def _copy_vendor_libraries(self):
420
389
self .with_mysql_capi , "lib" , "private" , "sasl2"
421
390
)
422
391
if not os .path .exists (sasl2_libs_path ):
423
- self .log .info (
424
- "sasl2 llibraries not found at %s" , sasl2_libs_path
425
- )
392
+ self .log .info ("sasl2 llibraries not found at %s" , sasl2_libs_path )
426
393
sasl2_libs_w = [
427
394
"libanonymous.*" ,
428
395
"libcrammd5.*.*" ,
@@ -449,9 +416,7 @@ def _copy_vendor_libraries(self):
449
416
450
417
sasl2_scram_libs = []
451
418
for sasl2_lib in sasl2_libs_w :
452
- lib_path_entries = glob (
453
- os .path .join (sasl2_libs_path , sasl2_lib )
454
- )
419
+ lib_path_entries = glob (os .path .join (sasl2_libs_path , sasl2_lib ))
455
420
for lib_path_entry in lib_path_entries :
456
421
sasl2_scram_libs .append (os .path .basename (lib_path_entry ))
457
422
@@ -522,9 +487,7 @@ def _finalize_mysql_capi(self):
522
487
# Add libmysqlclient libraries to be copied
523
488
if "link_dirs" in self ._mysql_info :
524
489
libs += glob (
525
- os .path .join (
526
- self ._mysql_info ["link_dirs" ][0 ], "libmysqlclient*"
527
- )
490
+ os .path .join (self ._mysql_info ["link_dirs" ][0 ], "libmysqlclient*" )
528
491
)
529
492
530
493
for lib in libs :
@@ -549,9 +512,7 @@ def _finalize_protobuf(self):
549
512
)
550
513
551
514
if not self .with_protobuf_lib_dir :
552
- self .with_protobuf_lib_dir = os .environ .get (
553
- "MYSQLXPB_PROTOBUF_LIB_DIR"
554
- )
515
+ self .with_protobuf_lib_dir = os .environ .get ("MYSQLXPB_PROTOBUF_LIB_DIR" )
555
516
556
517
if not self .with_protoc :
557
518
self .with_protoc = os .environ .get ("MYSQLXPB_PROTOC" )
@@ -569,9 +530,7 @@ def _finalize_protobuf(self):
569
530
sys .exit (1 )
570
531
571
532
if self .with_protobuf_lib_dir :
572
- self .log .info (
573
- "Protobuf library directory: %s" , self .with_protobuf_lib_dir
574
- )
533
+ self .log .info ("Protobuf library directory: %s" , self .with_protobuf_lib_dir )
575
534
if not os .path .isdir (self .with_protobuf_lib_dir ):
576
535
self .log .error ("Protobuf library dir should be a directory" )
577
536
sys .exit (1 )
@@ -596,9 +555,7 @@ def _finalize_protobuf(self):
596
555
libs = glob (os .path .join (self .with_protobuf_lib_dir , "libprotobuf*" ))
597
556
for lib in libs :
598
557
if os .path .isfile (lib ):
599
- self .log .info (
600
- "copying %s -> %s" , lib , self ._build_protobuf_lib_dir
601
- )
558
+ self .log .info ("copying %s -> %s" , lib , self ._build_protobuf_lib_dir )
602
559
shutil .copy2 (lib , self ._build_protobuf_lib_dir )
603
560
604
561
# Remove all but static libraries to force static linking
@@ -609,9 +566,7 @@ def _finalize_protobuf(self):
609
566
)
610
567
for lib in os .listdir (self ._build_protobuf_lib_dir ):
611
568
lib_path = os .path .join (self ._build_protobuf_lib_dir , lib )
612
- if os .path .isfile (lib_path ) and not lib .endswith (
613
- (".a" , ".dylib" )
614
- ):
569
+ if os .path .isfile (lib_path ) and not lib .endswith ((".a" , ".dylib" )):
615
570
os .unlink (os .path .join (self ._build_protobuf_lib_dir , lib ))
616
571
617
572
def _run_protoc (self ):
@@ -635,12 +590,8 @@ def finalize_options(self):
635
590
636
591
self .log .info ("Python architecture: %s" , ARCH )
637
592
638
- self ._build_mysql_lib_dir = os .path .join (
639
- self .build_temp , "capi" , "lib"
640
- )
641
- self ._build_protobuf_lib_dir = os .path .join (
642
- self .build_temp , "protobuf" , "lib"
643
- )
593
+ self ._build_mysql_lib_dir = os .path .join (self .build_temp , "capi" , "lib" )
594
+ self ._build_protobuf_lib_dir = os .path .join (self .build_temp , "protobuf" , "lib" )
644
595
if self .with_mysql_capi :
645
596
self ._mysql_info = mysql_c_api_info (self .with_mysql_capi )
646
597
self ._finalize_mysql_capi ()
@@ -665,9 +616,7 @@ def run(self):
665
616
# Add Protobuf include and library dirs
666
617
if ext .name == "_mysqlxpb" :
667
618
if not self .with_mysqlxpb_cext :
668
- self .log .warning (
669
- "The '_mysqlxpb' C extension will not be built"
670
- )
619
+ self .log .warning ("The '_mysqlxpb' C extension will not be built" )
671
620
disabled .append (ext )
672
621
continue
673
622
if platform .system () == "Darwin" :
@@ -680,9 +629,7 @@ def run(self):
680
629
fp .write ("\n " )
681
630
ext .include_dirs .append (self .with_protobuf_include_dir )
682
631
ext .library_dirs .append (self ._build_protobuf_lib_dir )
683
- ext .libraries .append (
684
- "libprotobuf" if os .name == "nt" else "protobuf"
685
- )
632
+ ext .libraries .append ("libprotobuf" if os .name == "nt" else "protobuf" )
686
633
# Add -std=c++11 needed for Protobuf 3.6.1
687
634
ext .extra_compile_args .append ("-std=c++11" )
688
635
self ._run_protoc ()
@@ -695,17 +642,13 @@ def run(self):
695
642
continue
696
643
# Add extra compile args
697
644
if self .extra_compile_args :
698
- ext .extra_compile_args .extend (
699
- self .extra_compile_args .split ()
700
- )
645
+ ext .extra_compile_args .extend (self .extra_compile_args .split ())
701
646
# Add extra link args
702
647
if self .extra_link_args :
703
648
ext .extra_link_args .extend (self .extra_link_args .split ())
704
649
# Add -rpath if the platform is Linux
705
650
if platform .system () == "Linux" and not self .skip_vendor :
706
- ext .extra_link_args .extend (
707
- ["-Wl,-rpath,$ORIGIN/mysql/vendor" ]
708
- )
651
+ ext .extra_link_args .extend (["-Wl,-rpath,$ORIGIN/mysql/vendor" ])
709
652
# Add include dirs
710
653
if self .with_openssl_include_dir :
711
654
ext .include_dirs .append (self .with_openssl_include_dir )
@@ -726,11 +669,11 @@ def run(self):
726
669
727
670
if os .name != "nt" :
728
671
cmd_gcc_ver = ["gcc" , "-v" ]
729
- self .log .info ("Executing: {0}" "" .format (" " .join (cmd_gcc_ver )))
672
+ self .log .info ("Executing: {0}" .format (" " .join (cmd_gcc_ver )))
730
673
proc = Popen (cmd_gcc_ver , stdout = PIPE , universal_newlines = True )
731
674
self .log .info (proc .communicate ())
732
675
cmd_gpp_ver = ["g++" , "-v" ]
733
- self .log .info ("Executing: {0}" "" .format (" " .join (cmd_gcc_ver )))
676
+ self .log .info ("Executing: {0}" .format (" " .join (cmd_gcc_ver )))
734
677
proc = Popen (cmd_gpp_ver , stdout = PIPE , universal_newlines = True )
735
678
self .log .info (proc .communicate ())
736
679
@@ -752,12 +695,8 @@ def run(self):
752
695
"@loader_path/mysql/vendor/{0}" .format (libssl ),
753
696
build_ext .get_ext_fullpath (self , "_mysql_connector" ),
754
697
]
755
- self .log .info (
756
- "Executing: {0}" "" .format (" " .join (cmd_libssl ))
757
- )
758
- proc = Popen (
759
- cmd_libssl , stdout = PIPE , universal_newlines = True
760
- )
698
+ self .log .info ("Executing: {0}" .format (" " .join (cmd_libssl )))
699
+ proc = Popen (cmd_libssl , stdout = PIPE , universal_newlines = True )
761
700
stdout , _ = proc .communicate ()
762
701
cmd_libcrypto = [
763
702
"install_name_tool" ,
@@ -766,12 +705,8 @@ def run(self):
766
705
"@loader_path/mysql/vendor/{0}" .format (libcrypto ),
767
706
build_ext .get_ext_fullpath (self , "_mysql_connector" ),
768
707
]
769
- self .log .info (
770
- "Executing: {0}" "" .format (" " .join (cmd_libcrypto ))
771
- )
772
- proc = Popen (
773
- cmd_libcrypto , stdout = PIPE , universal_newlines = True
774
- )
708
+ self .log .info ("Executing: {0}" .format (" " .join (cmd_libcrypto )))
709
+ proc = Popen (cmd_libcrypto , stdout = PIPE , universal_newlines = True )
775
710
stdout , _ = proc .communicate ()
776
711
777
712
# Generate docs/INFO_BIN
@@ -806,9 +741,7 @@ def initialize_options(self):
806
741
def finalize_options (self ):
807
742
"""Finalize the options."""
808
743
install_lib .finalize_options (self )
809
- self .set_undefined_options (
810
- "install" , ("byte_code_only" , "byte_code_only" )
811
- )
744
+ self .set_undefined_options ("install" , ("byte_code_only" , "byte_code_only" ))
812
745
self .set_undefined_options ("build" , ("build_base" , "build_dir" ))
813
746
814
747
def run (self ):
0 commit comments