-
Notifications
You must be signed in to change notification settings - Fork 18
/
configure-old.py
executable file
·1973 lines (1493 loc) · 66.5 KB
/
configure-old.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright (c) 2017, Riverbank Computing Limited
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
# This is v2.3 of this boilerplate.
from distutils import sysconfig
import glob
import os
import optparse
import sys
###############################################################################
# You shouldn't need to modify anything above this line.
###############################################################################
# This must be kept in sync with Python/configure-old.py, qwt.pro,
# example-Qt4Qt5/application.pro and designer-Qt4Qt5/designer.pro.
QWT_API_MAJOR = 6
class ModuleConfiguration(object):
""" This class encapsulates all the module specific information needed by
the rest of this script to implement a configure.py script for modules that
build on top of PyQt. Functions implemented by the rest of this script
that begin with an underscore are considered internal and shouldn't be
called from here.
"""
# The name of the module as it would be used in an import statement.
name = 'Qwt'
# The descriptive name of the module. This is used in help text and error
# messages.
descriptive_name = "Qwt"
# The version of the module as a string. Set it to None if you don't
# provide version information.
version = "1.9.0"
# The name of the PEP 376 .dist-info directory to be created.
distinfo_name = 'Qwt'
# Set if a configuration script is provided that handles versions of PyQt4
# prior to v4.10 (i.e. versions where the pyqtconfig.py module is
# available). If provided the script must be called configure-old.py and
# be in the same directory as this script.
legacy_configuration_script = False
# The minimum version of SIP that is required. This should be a
# dot-separated string of two or three integers (e.g. '1.0', '4.10.3'). If
# it is None or an empty string then the version is not checked.
minimum_sip_version = '4.18'
# Set if support for C++ exceptions can be disabled.
no_exceptions = True
# The name (without the .pyi extension) of the name of the PEP 484 stub
# file to be generated. If it is None or an empty string then a stub file
# is not generated.
pep484_stub_file = 'Qwt'
# Set if the module supports redefining 'protected' as 'public'.
protected_is_public_is_supported = True
# Set if the module supports PyQt4.
pyqt4_is_supported = True
# Set if the module supports PyQt5.
pyqt5_is_supported = True
# Set if the PyQt5 support is the default. It is ignored unless both
# 'pyqt4_is_supported' and 'pyqt5_is_supported' are set.
pyqt5_is_default = True
# The name (without the .api extension) of the name of the Qwt API
# file to be generated. If it is None or an empty string then an API file
# is not generated.
qwt_api_file = 'Qwt'
# The email address that will be included when an error in the script is
# detected. Leave it blank if you don't want to include an address.
support_email_address = 'gudjon@gudjon.org'
# Set if the user can provide a configuration file. It is normally only
# used if cross-compilation is supported.
user_configuration_file_is_supported = True
# Set if the user is allowed to pass PyQt sip flags on the command line.
# It is normally only used if cross-compilation is supported. It is
# ignored unless at least one of 'pyqt4_is_supported' or
# 'pyqt5_is_supported' is set.
user_pyqt_sip_flags_is_supported = True
@staticmethod
def init_target_configuration(target_configuration):
""" Perform any module specific initialisation of the target
target configuration. Typically this is the initialisation of module
specific attributes. To avoid name clashes attributes should be given
a module specific prefix. target_configuration is the target
configuration.
"""
target_configuration.qwt_version = None
target_configuration.qwt_features_dir = None
target_configuration.qwt_inc_dir = None
target_configuration.qwt_lib_dir = None
target_configuration.qwt_lib = None
target_configuration.qwt_sip_dir = None
@staticmethod
def init_optparser(optparser, target_configuration):
""" Perform any module specific initialisation of the command line
option parser. To avoid name clashes destination attributes should be
given a module specific prefix. optparser is the option parser.
target_configuration is the target configuration.
"""
optparser.add_option('--qwt-incdir', '-n', dest='qwt_inc_dir',
type='string', default=None, action='callback',
callback=optparser_store_abspath_dir, metavar="DIR",
help="the directory containing the Qwt header "
"file directory is DIR [default: QT_INSTALL_HEADERS]")
optparser.add_option('--qwt-featuresdir', dest='qwt_features_dir',
type='string', default=None, action='callback',
callback=optparser_store_abspath_dir, metavar="DIR",
help="the directory containing the qwt.prf features "
"file is DIR [default: "
"QT_INSTALL_PREFIX/mkspecs/features]")
optparser.add_option('--qwt-libdir', '-o', dest='qwt_lib_dir',
type='string', default=None, action='callback',
callback=optparser_store_abspath_dir, metavar="DIR",
help="the directory containing the Qwt library is DIR "
"[default: QT_INSTALL_LIBS]")
optparser.add_option('--qwt-lib', '-l', dest='qwt_lib',
type='string', default=None,
help="the Qwt library "
"[default: qwt]")
optparser.add_option('--qwt-sipdir', '-v', dest='qwt_sip_dir',
type='string', default=None, action='callback',
callback=optparser_store_abspath_dir, metavar="DIR",
help="the Qwt .sip files will be installed in DIR "
"[default: %s]" % target_configuration.pyqt_sip_dir)
optparser.add_option("--no-sip-files", action="store_true",
default=False, dest="qwt_no_sip_files",
help="disable the installation of the .sip files "
"[default: enabled]")
@staticmethod
def apply_options(target_configuration, options):
""" Apply the module specific command line options to the target
configuration. target_configuration is the target configuration.
options are the parsed options.
"""
if options.qwt_features_dir is not None:
target_configuration.qwt_features_dir = options.qwt_features_dir
if options.qwt_inc_dir is not None:
target_configuration.qwt_inc_dir = options.qwt_inc_dir
if options.qwt_lib_dir is not None:
target_configuration.qwt_lib_dir = options.qwt_lib_dir
if options.qwt_lib is not None:
target_configuration.qwt_lib = options.qwt_lib
if options.qwt_sip_dir is not None:
target_configuration.qwt_sip_dir = options.qwt_sip_dir
else:
target_configuration.qwt_sip_dir = target_configuration.pyqt_sip_dir
if options.qwt_no_sip_files:
target_configuration.qwt_sip_dir = ''
@staticmethod
def check_module(target_configuration):
""" Perform any module specific checks now that the target
configuration is complete. target_configuration is the target
configuration.
"""
# Find the Qwt header files.
inc_dir = target_configuration.qwt_inc_dir
if inc_dir is None:
inc_dir = target_configuration.qt_inc_dir
qwtglobal = os.path.join(inc_dir, '', 'qwt_global.h')
print(inc_dir)
if not os.access(qwtglobal, os.F_OK):
error(
"qwt/qwt_global.h could not be found in %s. If "
"Qwt is installed then use the --qwt-incdir "
"argument to explicitly specify the correct "
"directory." % inc_dir)
# Get the Qwt version string.
qwt_version = read_define(qwtglobal, 'QWT_VERSION_STR')
if qwt_version is None:
error(
"The Qwt version number could not be determined by "
"reading %s." % qwtglobal)
lib_dir = target_configuration.qwt_lib_dir
if lib_dir is None:
lib_dir = target_configuration.qt_lib_dir
if not glob.glob(os.path.join(lib_dir, '*qwt*')):
error(
"The Qwt library could not be found in %s. If "
"Qwt is installed then use the --qwt-libdir "
"argument to explicitly specify the correct "
"directory." % lib_dir)
# Because we include the Python bindings with the C++ code we can
# reasonably force the same version to be used and not bother about
# versioning in the .sip files.
qv=qwt_version.split('.')
qwt_version_numeric = int(qv[0])*10000 + int(qv[1])*100 + int(qv[2])
mv=ModuleConfiguration.version.split('.')
mod_version_numeric = int(mv[0])*10000 + int(mv[1])*100 + int(mv[2])
if qwt_version_numeric < mod_version_numeric:
error(
"Qwt %s is being used but the Python bindings %s "
"are being built. Please use a newer Qwt "
"version." % (qwt_version, ModuleConfiguration.version))
target_configuration.qwt_version = qwt_version
@staticmethod
def inform_user(target_configuration):
""" Inform the user about module specific configuration information.
target_configuration is the target configuration.
"""
inform("Qwt %s is being used." %
target_configuration.qwt_version)
if target_configuration.qwt_sip_dir != '':
inform("The Qwt .sip files will be installed in %s." %
target_configuration.qwt_sip_dir)
@staticmethod
def pre_code_generation(target_config):
""" Perform any module specific initialisation prior to generating the
code. target_config is the target configuration.
"""
# Nothing to do.
@staticmethod
def get_sip_flags(target_configuration):
""" Return the list of module-specific flags to pass to SIP.
target_configuration is the target configuration.
"""
# Nothing to do.
return []
@staticmethod
def get_sip_file(target_configuration):
""" Return the name of the module's .sip file. target_configuration is
the target configuration.
"""
return 'sip/qwt.sip'
#if target_configuration.pyqt_package == 'PyQt5':
# return os.path.join(src_dir, 'sip/qwt.sip')
#else:
# return os.path.join(src_dir, 'sip/qwtmod4.sip')
#return 'sip/qwtmod5.sip' if target_configuration.pyqt_package == 'PyQt5' else 'sip/qwtmod4.sip'
@staticmethod
def get_sip_installs(target_configuration):
""" Return a tuple of the installation directory of the module's .sip
files and a sequence of the names of each of the .sip files relative to
the directory containing this configuration script. None is returned
if the module's .sip files are not to be installed.
target_configuration is the target configuration.
"""
if target_configuration.qwt_sip_dir == '':
return None
path = os.path.join(target_configuration.qwt_sip_dir, 'Qwt')
files = glob.glob('sip/*.sip')
return path, files
@staticmethod
def get_qmake_configuration(target_configuration):
""" Return a dict of qmake configuration values for CONFIG, DEFINES,
INCLUDEPATH, LIBS and QT. If value names (i.e. dict keys) have either
'Qt4' or 'Qt5' prefixes then they are specific to the corresponding
version of Qt. target_configuration is the target configuration.
"""
qmake = {'CONFIG': 'qwt'}
if target_configuration.qwt_inc_dir is not None:
qmake['INCLUDEPATH'] = quote(target_configuration.qwt_inc_dir)
if target_configuration.qwt_lib_dir is not None:
qmake['LIBS'] = '-L%s' % quote(target_configuration.qwt_lib_dir)
if target_configuration.qwt_features_dir is not None:
os.environ['QMAKEFEATURES'] = target_configuration.qwt_features_dir
return qmake
@staticmethod
def get_mac_wrapped_library_file(target_configuration):
""" Return the full pathname of the file that implements the library
being wrapped by the module as it would be called on OS/X so that the
module will reference it explicitly without DYLD_LIBRARY_PATH being
set. If it is None or an empty string then the default is used.
target_configuration is the target configuration.
"""
lib_dir = target_configuration.qwt_lib_dir
if lib_dir is None:
lib_dir = target_configuration.qt_lib_dir
debug = '_debug' if target_configuration.debug else ''
return os.path.join(lib_dir,
'libqwt%s.%s.dylib' % (debug,
QWT_API_MAJOR))
###############################################################################
# You shouldn't need to modify anything below this line.
###############################################################################
def error(msg):
""" Display an error message and terminate. msg is the text of the error
message.
"""
sys.stderr.write(_format("Error: " + msg) + "\n")
sys.exit(1)
def inform(msg):
""" Display an information message. msg is the text of the error message.
"""
sys.stdout.write(_format(msg) + "\n")
def quote(path):
""" Return a path with quotes added if it contains spaces. path is the
path.
"""
if ' ' in path:
path = '"%s"' % path
return path
def optparser_store_abspath(option, opt_str, value, parser):
""" An optparser callback that saves an option as an absolute pathname. """
setattr(parser.values, option.dest, os.path.abspath(value))
def optparser_store_abspath_dir(option, opt_str, value, parser):
""" An optparser callback that saves an option as the absolute pathname
of an existing directory.
"""
if not os.path.isdir(value):
raise optparse.OptionValueError("'%s' is not a directory" % value)
setattr(parser.values, option.dest, os.path.abspath(value))
def optparser_store_abspath_exe(option, opt_str, value, parser):
""" An optparser callback that saves an option as the absolute pathname
of an existing executable.
"""
if not os.access(value, os.X_OK):
raise optparse.OptionValueError("'%s' is not an executable" % value)
setattr(parser.values, option.dest, os.path.abspath(value))
def read_define(filename, define):
""" Read the value of a #define from a file. filename is the name of the
file. define is the name of the #define. None is returned if there was no
such #define.
"""
f = open(filename)
for l in f:
wl = l.split()
if len(wl) >= 3 and wl[0] == "#define" and wl[1] == define:
# Take account of embedded spaces.
value = ' '.join(wl[2:])[1:-1]
break
else:
value = None
f.close()
return value
def version_from_string(version_str):
""" Convert a version string of the form m, m.n or m.n.o to an encoded
version number (or None if it was an invalid format). version_str is the
version string.
"""
parts = version_str.split('.')
if not isinstance(parts, list):
return None
if len(parts) == 1:
parts.append('0')
if len(parts) == 2:
parts.append('0')
if len(parts) != 3:
return None
version = 0
for part in parts:
try:
v = int(part)
except ValueError:
return None
version = (version << 8) + v
return version
def _format(msg, left_margin=0, right_margin=78):
""" Format a message by inserting line breaks at appropriate places. msg
is the text of the message. left_margin is the position of the left
margin. right_margin is the position of the right margin. Returns the
formatted message.
"""
curs = left_margin
fmsg = " " * left_margin
for w in msg.split():
l = len(w)
if curs != left_margin and curs + l > right_margin:
fmsg = fmsg + "\n" + (" " * left_margin)
curs = left_margin
if curs > left_margin:
fmsg = fmsg + " "
curs = curs + 1
fmsg = fmsg + w
curs = curs + l
return fmsg
class _ConfigurationFileParser:
""" A parser for configuration files. """
def __init__(self, config_file):
""" Read and parse a configuration file. """
self._config = {}
self._extrapolating = []
cfg = open(config_file)
line_nr = 0
last_name = None
section = ''
section_config = {}
self._config[section] = section_config
for l in cfg:
line_nr += 1
# Strip comments.
l = l.split('#')[0]
# See if this might be part of a multi-line.
multiline = (last_name is not None and len(l) != 0 and l[0] == ' ')
l = l.strip()
if l == '':
last_name = None
continue
# See if this is a new section.
if l[0] == '[' and l[-1] == ']':
section = l[1:-1].strip()
if section == '':
error(
"%s:%d: Empty section name." % (
config_file, line_nr))
if section in self._config:
error(
"%s:%d: Section '%s' defined more than once." % (
config_file, line_nr, section))
section_config = {}
self._config[section] = section_config
last_name = None
continue
parts = l.split('=', 1)
if len(parts) == 2:
name = parts[0].strip()
value = parts[1].strip()
elif multiline:
name = last_name
value = section_config[last_name]
value += ' ' + l
else:
name = value = ''
if name == '' or value == '':
error("%s:%d: Invalid line." % (config_file, line_nr))
section_config[name] = value
last_name = name
cfg.close()
def sections(self):
""" Return the list of sections, excluding the default one. """
return [s for s in self._config.keys() if s != '']
def preset(self, name, value):
""" Add a preset value to the configuration. """
self._config[''][name] = value
def get(self, section, name, default=None):
""" Get a configuration value while extrapolating. """
# Get the name from the section, or the default section.
value = self._config[section].get(name)
if value is None:
value = self._config[''].get(name)
if value is None:
if default is None:
error(
"Configuration file references non-existent name "
"'%s'." % name)
return default
# Handle any extrapolations.
parts = value.split('%(', 1)
while len(parts) == 2:
prefix, tail = parts
parts = tail.split(')', 1)
if len(parts) != 2:
error(
"Configuration file contains unterminated "
"extrapolated name '%s'." % tail)
xtra_name, suffix = parts
if xtra_name in self._extrapolating:
error(
"Configuration file contains a recursive reference to "
"'%s'." % xtra_name)
self._extrapolating.append(xtra_name)
xtra_value = self.get(section, xtra_name)
self._extrapolating.pop()
value = prefix + xtra_value + suffix
parts = value.split('%(', 1)
return value
def getboolean(self, section, name, default):
""" Get a boolean configuration value while extrapolating. """
value = self.get(section, name, default)
# In case the default was returned.
if isinstance(value, bool):
return value
if value in ('True', 'true', '1'):
return True
if value in ('False', 'false', '0'):
return False
error(
"Configuration file contains invalid boolean value for "
"'%s'." % name)
def getlist(self, section, name, default):
""" Get a list configuration value while extrapolating. """
value = self.get(section, name, default)
# In case the default was returned.
if isinstance(value, list):
return value
return value.split()
class _HostPythonConfiguration:
""" A container for the host Python configuration. """
def __init__(self):
""" Initialise the configuration. """
self.platform = sys.platform
self.version = sys.hexversion >> 8
self.inc_dir = sysconfig.get_python_inc()
self.venv_inc_dir = sysconfig.get_python_inc(prefix=sys.prefix)
self.module_dir = sysconfig.get_python_lib(plat_specific=1)
self.debug = hasattr(sys, 'gettotalrefcount')
if sys.platform == 'win32':
try:
# Python v3.3 and later.
base_prefix = sys.base_prefix
except AttributeError:
try:
# virtualenv for Python v2.
base_prefix = sys.real_prefix
except AttributeError:
# We can't detect the base prefix in Python v3 prior to
# v3.3.
base_prefix = sys.prefix
self.data_dir = sys.prefix
self.lib_dir = base_prefix + '\\libs'
else:
self.data_dir = sys.prefix + '/share'
self.lib_dir = sys.prefix + '/lib'
class _TargetQtConfiguration:
""" A container for the target Qt configuration. """
def __init__(self, qmake):
""" Initialise the configuration. qmake is the full pathname of the
qmake executable that will provide the configuration.
"""
pipe = os.popen(quote(qmake) + ' -query')
for l in pipe:
l = l.strip()
tokens = l.split(':', 1)
if isinstance(tokens, list):
if len(tokens) != 2:
error("Unexpected output from qmake: '%s'\n" % l)
name, value = tokens
else:
name = tokens
value = None
name = name.replace('/', '_')
setattr(self, name, value)
pipe.close()
class _TargetConfiguration:
""" A container for the target configuration. """
def __init__(self, pkg_config):
""" Initialise the configuration with default values. pkg_config is
the package configuration.
"""
# Values based on the host Python configuration.
py_config = _HostPythonConfiguration()
self.py_debug = py_config.debug
self.py_platform = py_config.platform
self.py_version = py_config.version
self.py_module_dir = py_config.module_dir
self.py_inc_dir = py_config.inc_dir
self.py_venv_inc_dir = py_config.venv_inc_dir
self.py_pylib_dir = py_config.lib_dir
self.py_sip_dir = os.path.join(py_config.data_dir, 'sip')
self.sip_inc_dir = py_config.venv_inc_dir
# Remaining values.
self.debug = False
self.pyqt_sip_flags = None
self.pyqt_version_str = ''
self.qmake = self._find_exe('qmake')
self.qmake_spec = ''
self.qt_version = 0
self.qt_version_str = ''
self.sip = self._find_exe('sip5', 'sip')
self.sip_version = None
self.sip_version_str = None
self.sysroot = ''
self.stubs_dir = ''
self.distinfo = False
self.prot_is_public = (self.py_platform.startswith('linux') or self.py_platform == 'darwin')
if pkg_config.pyqt5_is_supported and pkg_config.pyqt4_is_supported:
pyqt = 'PyQt5' if pkg_config.pyqt5_is_default else 'PyQt4'
elif pkg_config.pyqt5_is_supported and not pkg_config.pyqt4_is_supported:
pyqt = 'PyQt5'
elif not pkg_config.pyqt5_is_supported and pkg_config.pyqt4_is_supported:
pyqt = 'PyQt4'
else:
pyqt = None
if pyqt is not None:
self.module_dir = os.path.join(py_config.module_dir, pyqt)
self.pyqt_sip_dir = os.path.join(self.py_sip_dir, pyqt)
else:
self.module_dir = py_config.module_dir
self.pyqt_sip_dir = None
self.pyqt_package = pyqt
pkg_config.init_target_configuration(self)
def update_from_configuration_file(self, config_file):
""" Update the configuration with values from a file. config_file
is the name of the configuration file.
"""
inform("Reading configuration from %s..." % config_file)
parser = _ConfigurationFileParser(config_file)
# Populate some presets from the command line.
parser.preset('py_major', str(self.py_version >> 16))
parser.preset('py_minor', str((self.py_version >> 8) & 0xff))
parser.preset('sysroot', self.sysroot)
if self.pyqt_package is None:
section = ''
else:
# At the moment we only need to distinguish between PyQt4 and
# PyQt5. If that changes we may need a --target-pyqt-version
# command line option.
pyqt_version = 0x050000 if self.pyqt_package == 'PyQt5' else 0x040000
# Find the section corresponding to the version of PyQt.
section = None
latest_section = -1
for name in parser.sections():
parts = name.split()
if len(parts) != 2 or parts[0] != 'PyQt':
continue
section_pyqt_version = version_from_string(parts[1])
if section_pyqt_version is None:
continue
# Major versions must match.
if section_pyqt_version >> 16 != pyqt_version >> 16:
continue
# It must be no later that the version of PyQt.
if section_pyqt_version > pyqt_version:
continue
# Save it if it is the latest so far.
if section_pyqt_version > latest_section:
section = name
latest_section = section_pyqt_version
if section is None:
error(
"%s does not define a section that covers PyQt "
"v%s." % (config_file, self.pyqt_version_str))
self.py_platform = parser.get(section, 'py_platform', self.py_platform)
self.py_inc_dir = parser.get(section, 'py_inc_dir', self.py_inc_dir)
self.py_venv_inc_dir = self.py_inc_dir
self.py_pylib_dir = parser.get(section, 'py_pylib_dir',
self.py_pylib_dir)
self.sip_inc_dir = self.py_venv_inc_dir
self.module_dir = parser.get(section, 'module_dir', self.module_dir)
if self.pyqt_package is not None:
self.py_sip_dir = parser.get(section, 'py_sip_dir',
self.py_sip_dir)
# Construct the SIP flags.
flags = []
flags.append('-t')
flags.append(self._get_platform_tag())
if self.pyqt_package == 'PyQt5':
if self.qt_version < 0x050000:
error("PyQt5 requires Qt v5.0 or later.")
if self.qt_version > 0x060000:
self.qt_version = 0x060000
else:
if self.qt_version > 0x050000:
self.qt_version = 0x050000
major = (self.qt_version >> 16) & 0xff
minor = (self.qt_version >> 8) & 0xff
patch = self.qt_version & 0xff
flags.append('-t')
flags.append('Qt_%d_%d_%d' % (major, minor, patch))
for feat in parser.getlist(section, 'pyqt_disabled_features', []):
flags.append('-x')
flags.append(feat)
self.pyqt_sip_flags = ' '.join(flags)
def _get_platform_tag(self):
""" Return the tag for the target platform. """
# This replicates the logic in PyQt's configure scripts.
if self.py_platform == 'win32':
plattag = 'WS_WIN'
elif self.py_platform == 'darwin':
plattag = 'WS_MACX'
else:
plattag = 'WS_X11'
return plattag
def introspect_pyqt(self, pkg_config):
""" Introspect PyQt to determine the sip flags required. pkg_config
is the package configuration.
"""
if self.pyqt_package == 'PyQt5':
try:
from PyQt5 import QtCore
except ImportError:
error(
"Unable to import PyQt5.QtCore. Make sure PyQt5 is "
"installed.")
else:
try:
from PyQt4 import QtCore
except ImportError:
error(
"Unable to import PyQt4.QtCore. Make sure PyQt4 is "
"installed.")
self.pyqt_version_str = QtCore.PYQT_VERSION_STR
self.qt_version_str = QtCore.qVersion()
# See if we have a PyQt that embeds its configuration.
try:
pyqt_config = QtCore.PYQT_CONFIGURATION
except AttributeError:
pyqt_config = None
if pyqt_config is None:
if pkg_config.legacy_configuration_script:
# Fallback to the old configuration script.
config_script = sys.argv[0].replace('configure', 'configure-old')
args = [sys.executable, config_script] + sys.argv[1:]
try:
os.execv(sys.executable, args)
except OSError:
pass
error("Unable to execute '%s'" % config_script)
error("PyQt v4.10 or later is required.")
self.pyqt_sip_flags = pyqt_config['sip_flags']
def apply_sysroot(self):
""" Apply sysroot where necessary. """
if self.sysroot != '':
self.py_inc_dir = self._apply_sysroot(self.py_inc_dir)
self.py_venv_inc_dir = self._apply_sysroot(self.py_venv_inc_dir)
self.py_pylib_dir = self._apply_sysroot(self.py_pylib_dir)
self.py_sip_dir = self._apply_sysroot(self.py_sip_dir)
self.module_dir = self._apply_sysroot(self.module_dir)
self.sip_inc_dir = self._apply_sysroot(self.sip_inc_dir)
def _apply_sysroot(self, dir_name):
""" Replace any leading sys.prefix of a directory name with sysroot.
"""
if dir_name.startswith(sys.prefix):
dir_name = self.sysroot + dir_name[len(sys.prefix):]
return dir_name
def get_qt_configuration(self, opts):
""" Get the Qt configuration that can be extracted from qmake. opts
are the command line options.
"""
# Query qmake.
qt_config = _TargetQtConfiguration(self.qmake)
self.qt_version_str = getattr(qt_config, 'QT_VERSION', '')
self.qt_version = version_from_string(self.qt_version_str)
if self.qt_version is None:
error("Unable to determine the version of Qt.")
# On Windows for Qt versions prior to v5.9.0 we need to be explicit
# about the qmake spec.
if self.qt_version < 0x050900 and self.py_platform == 'win32':
if self.py_version >= 0x030500:
self.qmake_spec = 'win32-msvc2015'
elif self.py_version >= 0x030300:
self.qmake_spec = 'win32-msvc2010'
elif self.py_version >= 0x020600:
self.qmake_spec = 'win32-msvc2008'
elif self.py_version >= 0x020400:
self.qmake_spec = 'win32-msvc.net'
else:
self.qmake_spec = 'win32-msvc'
else:
# Otherwise use the default.
self.qmake_spec = ''
# The binary MacOS/X Qt installer used to default to XCode. If so then
# use macx-clang (Qt v5) or macx-g++ (Qt v4).
if sys.platform == 'darwin':
try:
# Qt v5.
if qt_config.QMAKE_SPEC == 'macx-xcode':
# This will exist (and we can't check anyway).
self.qmake_spec = 'macx-clang'
else:
# No need to explicitly name the default.
self.qmake_spec = ''
except AttributeError:
# Qt v4.
self.qmake_spec = 'macx-g++'
self.api_dir = os.path.join(qt_config.QT_INSTALL_DATA, 'qwt')
self.qt_inc_dir = qt_config.QT_INSTALL_HEADERS
self.qt_lib_dir = qt_config.QT_INSTALL_LIBS