-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure.py
3157 lines (2435 loc) · 111 KB
/
configure.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
# This script generates the Makefiles for building PyQt5.
#
# Copyright (c) 2023 Riverbank Computing Limited <info@riverbankcomputing.com>
#
# This file is part of PyQt5.
#
# This file may be used under the terms of the GNU General Public License
# version 3.0 as published by the Free Software Foundation and appearing in
# the file LICENSE included in the packaging of this file. Please review the
# following information to ensure the GNU General Public License version 3.0
# requirements will be met: http://www.gnu.org/copyleft/gpl.html.
#
# If you do not wish to use this file under the terms of the GPL version 3.0
# then you may purchase a commercial license. For more information contact
# info@riverbankcomputing.com.
#
# This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
# WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
from distutils import sysconfig
import glob
import optparse
import os
import shutil
import stat
import sys
# Initialise the constants.
PYQT_VERSION_STR = "5.15.9"
SIP_MIN_VERSION = '@MinimumSipVersion@'
class ModuleMetadata:
""" This class encapsulates the meta-data about a PyQt5 module. """
def __init__(self, qmake_QT=None, qmake_TARGET='', qpy_lib=False, cpp11=False, public=True):
""" Initialise the meta-data. """
# The values to update qmake's QT variable.
self.qmake_QT = [] if qmake_QT is None else qmake_QT
# The value to set qmake's TARGET variable to. It defaults to the name
# of the module.
self.qmake_TARGET = qmake_TARGET
# Set if there is a qpy support library.
self.qpy_lib = qpy_lib
# Set if C++11 support is required.
self.cpp11 = cpp11
# Set if the module is public.
self.public = public
# The module meta-data.
MODULE_METADATA = {
'dbus': ModuleMetadata(qmake_QT=['-gui'],
qmake_TARGET='pyqt5'),
'QAxContainer': ModuleMetadata(qmake_QT=['axcontainer']),
'Qt': ModuleMetadata(qmake_QT=['-core', '-gui']),
'QtAndroidExtras': ModuleMetadata(qmake_QT=['androidextras']),
'QtBluetooth': ModuleMetadata(qmake_QT=['bluetooth']),
'QtCore': ModuleMetadata(qmake_QT=['-gui'], qpy_lib=True),
'QtDBus': ModuleMetadata(qmake_QT=['dbus', '-gui'],
qpy_lib=True),
'QtDesigner': ModuleMetadata(qmake_QT=['designer'],
qpy_lib=True),
'Enginio': ModuleMetadata(qmake_QT=['enginio']),
'QtGui': ModuleMetadata(qpy_lib=True),
'QtHelp': ModuleMetadata(qmake_QT=['help']),
'QtLocation': ModuleMetadata(qmake_QT=['location']),
'QtMacExtras': ModuleMetadata(qmake_QT=['macextras']),
'QtMultimedia': ModuleMetadata(qmake_QT=['multimedia']),
'QtMultimediaWidgets': ModuleMetadata(
qmake_QT=['multimediawidgets',
'multimedia']),
'QtNetwork': ModuleMetadata(qmake_QT=['network', '-gui']),
'QtNfc': ModuleMetadata(qmake_QT=['nfc', '-gui']),
'QtOpenGL': ModuleMetadata(qmake_QT=['opengl']),
'QtPositioning': ModuleMetadata(qmake_QT=['positioning']),
'QtPrintSupport': ModuleMetadata(qmake_QT=['printsupport']),
'QtQml': ModuleMetadata(qmake_QT=['qml'], qpy_lib=True),
'QtQuick': ModuleMetadata(qmake_QT=['quick'], qpy_lib=True),
'QtQuick3D': ModuleMetadata(qmake_QT=['quick3d']),
'QtQuickWidgets': ModuleMetadata(qmake_QT=['quickwidgets']),
'QtRemoteObjects': ModuleMetadata(qmake_QT=['remoteobjects', '-gui']),
'QtSensors': ModuleMetadata(qmake_QT=['sensors']),
'QtSerialPort': ModuleMetadata(qmake_QT=['serialport']),
'QtSql': ModuleMetadata(qmake_QT=['sql', 'widgets']),
'QtSvg': ModuleMetadata(qmake_QT=['svg']),
'QtTest': ModuleMetadata(qmake_QT=['testlib', 'widgets']),
'QtTextToSpeech': ModuleMetadata(qmake_QT=['texttospeech', '-gui']),
'QtWebChannel': ModuleMetadata(
qmake_QT=['webchannel', 'network',
'-gui']),
'QtWebKit': ModuleMetadata(qmake_QT=['webkit', 'network']),
'QtWebKitWidgets': ModuleMetadata(
qmake_QT=['webkitwidgets',
'printsupport']),
'QtWebSockets': ModuleMetadata(qmake_QT=['websockets', '-gui']),
'QtWidgets': ModuleMetadata(qmake_QT=['widgets'], qpy_lib=True),
'QtWinExtras': ModuleMetadata(qmake_QT=['winextras', 'widgets']),
'QtX11Extras': ModuleMetadata(qmake_QT=['x11extras']),
'QtXml': ModuleMetadata(qmake_QT=['xml', '-gui']),
'QtXmlPatterns': ModuleMetadata(
qmake_QT=['xmlpatterns', '-gui',
'network']),
# The OpenGL wrappers.
'_QOpenGLFunctions_1_0': ModuleMetadata(public=False),
'_QOpenGLFunctions_1_1': ModuleMetadata(public=False),
'_QOpenGLFunctions_1_2': ModuleMetadata(public=False),
'_QOpenGLFunctions_1_3': ModuleMetadata(public=False),
'_QOpenGLFunctions_1_4': ModuleMetadata(public=False),
'_QOpenGLFunctions_1_5': ModuleMetadata(public=False),
'_QOpenGLFunctions_2_0': ModuleMetadata(public=False),
'_QOpenGLFunctions_2_1': ModuleMetadata(public=False),
'_QOpenGLFunctions_3_0': ModuleMetadata(public=False),
'_QOpenGLFunctions_3_1': ModuleMetadata(public=False),
'_QOpenGLFunctions_3_2_Compatibility': ModuleMetadata(public=False),
'_QOpenGLFunctions_3_2_Core': ModuleMetadata(public=False),
'_QOpenGLFunctions_3_3_Compatibility': ModuleMetadata(public=False),
'_QOpenGLFunctions_3_3_Core': ModuleMetadata(public=False),
'_QOpenGLFunctions_4_0_Compatibility': ModuleMetadata(public=False),
'_QOpenGLFunctions_4_0_Core': ModuleMetadata(public=False),
'_QOpenGLFunctions_4_1_Compatibility': ModuleMetadata(public=False),
'_QOpenGLFunctions_4_1_Core': ModuleMetadata(public=False),
'_QOpenGLFunctions_4_2_Compatibility': ModuleMetadata(public=False),
'_QOpenGLFunctions_4_2_Core': ModuleMetadata(public=False),
'_QOpenGLFunctions_4_3_Compatibility': ModuleMetadata(public=False),
'_QOpenGLFunctions_4_3_Core': ModuleMetadata(public=False),
'_QOpenGLFunctions_4_4_Compatibility': ModuleMetadata(public=False),
'_QOpenGLFunctions_4_4_Core': ModuleMetadata(public=False),
'_QOpenGLFunctions_4_5_Compatibility': ModuleMetadata(public=False),
'_QOpenGLFunctions_4_5_Core': ModuleMetadata(public=False),
'_QOpenGLFunctions_ES2': ModuleMetadata(public=False),
# Internal modules.
'pylupdate': ModuleMetadata(qmake_QT=['xml', '-gui'],
qpy_lib=True, public=False),
'pyrcc': ModuleMetadata(qmake_QT=['xml', '-gui'],
qpy_lib=True, public=False),
}
# The component modules that make up the composite Qt module. SIP is broken in
# its handling of composite module in that a component module must be %Included
# before it is first %Imported. In other words, a module must appear before
# any modules that depend on it.
COMPOSITE_COMPONENTS = (
'QtCore',
'QtAndroidExtras', 'QtDBus', 'QtGui', 'QtNetwork',
'QtSensors', 'QtSerialPort', 'QtMultimedia', 'QtQml', 'QtWebKit',
'QtWidgets', 'QtXml', 'QtXmlPatterns', 'QtAxContainer', 'QtDesigner',
'QtHelp', 'QtMultimediaWidgets', 'QtOpenGL',
'QtPrintSupport', 'QtQuick', 'QtSql', 'QtSvg', 'QtTest',
'QtWebKitWidgets', 'QtBluetooth', 'QtMacExtras', 'QtPositioning',
'QtWinExtras', 'QtX11Extras', 'QtQuick3D', 'QtQuickWidgets',
'QtWebSockets', 'Enginio', 'QtWebChannel',
'QtLocation', 'QtNfc', 'QtRemoteObjects', 'QtTextToSpeech'
)
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 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
def version_to_sip_tag(version):
""" Convert a version number to a SIP tag. version is the version number.
"""
# Anything after Qt v5 is assumed to be Qt v6.0.
if version > 0x060000:
version = 0x060000
major = (version >> 16) & 0xff
minor = (version >> 8) & 0xff
patch = version & 0xff
# Qt v5.12.4 was the last release where we updated for a patch version.
if (major, minor) >= (5, 13):
patch = 0
elif (major, minor) == (5, 12):
if patch > 4:
patch = 4
return 'Qt_%d_%d_%d' % (major, minor, patch)
def version_to_string(version, parts=3):
""" Convert an n-part version number encoded as a hexadecimal value to a
string. version is the version number. Returns the string.
"""
part_list = [str((version >> 16) & 0xff)]
if parts > 1:
part_list.append(str((version >> 8) & 0xff))
if parts > 2:
part_list.append(str(version & 0xff))
return '.'.join(part_list)
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':
bin_dir = sys.exec_prefix
try:
# Python v3.3 and later.
base_prefix = sys.base_prefix
if sys.exec_prefix != sys.base_exec_prefix:
bin_dir += '\\Scripts'
except AttributeError:
try:
# virtualenv for Python v2.
base_prefix = sys.real_prefix
bin_dir += '\\Scripts'
except AttributeError:
# We can't detect the base prefix in Python v3 prior to
# v3.3.
base_prefix = sys.prefix
self.bin_dir = bin_dir
self.data_dir = sys.prefix
self.lib_dir = base_prefix + '\\libs'
else:
self.bin_dir = sys.exec_prefix + '/bin'
self.data_dir = sys.prefix + '/share'
self.lib_dir = sys.prefix + '/lib'
# The name of the interpreter used by the pyuic5 wrapper.
if sys.platform == 'darwin':
# The installation of MacOS's python is a mess that changes from
# version to version and where sys.executable is useless.
py_major = self.version >> 16
py_minor = (self.version >> 8) & 0xff
# In Python v3.4 and later there is no pythonw.
if (py_major == 3 and py_minor >= 4) or py_major >= 4:
exe = "python"
else:
exe = "pythonw"
self.pyuic_interpreter = '%s%d.%d' % (exe, py_major, py_minor)
else:
self.pyuic_interpreter = sys.executable
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.
"""
inform("Querying qmake about your Qt installation...")
pipe = os.popen(' '.join([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 configuration information about the target. """
def __init__(self):
""" Initialise the configuration with default values. """
# Values based on the host Python configuration.
py_config = HostPythonConfiguration()
self.py_debug = py_config.debug
self.py_inc_dir = py_config.inc_dir
self.py_venv_inc_dir = py_config.venv_inc_dir
self.py_lib_dir = py_config.lib_dir
self.py_platform = py_config.platform
self.py_version = py_config.version
self.pyqt_bin_dir = py_config.bin_dir
self.pyqt_module_dir = py_config.module_dir
self.pyqt_stubs_dir = os.path.join(py_config.module_dir, 'PyQt5')
self.pyqt_sip_dir = os.path.join(py_config.data_dir, 'sip', 'PyQt5')
self.pyuic_interpreter = py_config.pyuic_interpreter
# Remaining values.
self.abi_version = None
self.dbus_inc_dirs = []
self.dbus_lib_dirs = []
self.dbus_libs = []
self.debug = False
self.designer_plugin_dir = ''
self.license_dir = source_path('sip')
self.link_full_dll = False
self.no_designer_plugin = False
self.no_docstrings = False
self.no_pydbus = False
self.no_qml_plugin = False
self.no_tools = False
self.prot_is_public = (self.py_platform.startswith('linux') or self.py_platform == 'darwin')
self.qmake = self._find_exe('qmake')
self.qmake_spec = ''
self.qmake_spec_default = ''
self.qmake_variables = []
self.qml_debug = False
self.py_pylib_dir = ''
self.py_pylib_lib = ''
self.py_pyshlib = ''
self.pydbus_inc_dir = ''
self.pydbus_module_dir = ''
self.pyqt_disabled_features = []
self.pyqt_modules = []
self.qml_plugin_dir = ''
self.qsci_api = False
self.qsci_api_dir = ''
self.qt_shared = False
self.qt_version = 0
self.sip = self._find_exe('sip5', 'sip')
self.sip_inc_dir = None
self.static = False
self.sysroot = ''
self.vend_enabled = False
self.vend_inc_dir = ''
self.vend_lib_dir = ''
def from_configuration_file(self, config_file):
""" Initialise 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.
version = version_to_string(self.py_version).split('.')
parser.preset('py_major', version[0])
parser.preset('py_minor', version[1])
parser.preset('sysroot', self.sysroot)
# Find the section corresponding to the version of Qt.
qt_major = self.qt_version >> 16
section = None
latest_section = -1
for name in parser.sections():
parts = name.split()
if len(parts) != 2 or parts[0] != 'Qt':
continue
section_qt_version = version_from_string(parts[1])
if section_qt_version is None:
continue
# Major versions must match.
if section_qt_version >> 16 != self.qt_version >> 16:
continue
# It must be no later that the version of Qt.
if section_qt_version > self.qt_version:
continue
# Save it if it is the latest so far.
if section_qt_version > latest_section:
section = name
latest_section = section_qt_version
if section is None:
error("%s does not define a section that covers Qt v%s." % (config_file, version_to_string(self.qt_version)))
self.py_platform = parser.get(section, 'py_platform', self.py_platform)
self.py_debug = parser.get(section, 'py_debug', self.py_debug)
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.py_pylib_lib = parser.get(section, 'py_pylib_lib',
self.py_pylib_lib)
self.py_pyshlib = parser.get(section, 'py_pyshlib', self.py_pyshlib)
self.qt_shared = parser.getboolean(section, 'qt_shared',
self.qt_shared)
self.pyqt_disabled_features = parser.getlist(section,
'pyqt_disabled_features', self.pyqt_disabled_features)
self.pyqt_modules = parser.getlist(section, 'pyqt_modules',
self.pyqt_modules)
self.pyqt_module_dir = parser.get(section, 'pyqt_module_dir',
self.pyqt_module_dir)
self.pyqt_bin_dir = parser.get(section, 'pyqt_bin_dir',
self.pyqt_bin_dir)
self.pyqt_stubs_dir = parser.get(section, 'pyqt_stubs_dir',
self.pyqt_stubs_dir)
self.pyqt_sip_dir = parser.get(section, 'pyqt_sip_dir',
self.pyqt_sip_dir)
self.pyuic_interpreter = parser.get(section, 'pyuic_interpreter',
self.pyuic_interpreter)
def from_introspection(self, verbose, debug):
""" Initialise the configuration by introspecting the system. """
# Check that the enum module is available.
try:
import enum
except ImportError:
error(
"Unable to import enum. Please install the enum34 "
"package from PyPI.")
# Get the details of the Python interpreter library.
py_major = self.py_version >> 16
py_minor = (self.py_version >> 8) & 0x0ff
if sys.platform == 'win32':
debug_suffix = self.get_win32_debug_suffix()
# See if we are using the limited API.
limited = (py_major == 3 and py_minor >= 4)
if self.py_debug or self.link_full_dll:
limited = False
if limited:
pylib_lib = 'python%d%s' % (py_major, debug_suffix)
else:
pylib_lib = 'python%d%d%s' % (py_major, py_minor, debug_suffix)
pylib_dir = self.py_lib_dir
# Assume Python is a DLL on Windows.
pyshlib = pylib_lib
else:
abi = getattr(sys, 'abiflags', '')
pylib_lib = 'python%d.%d%s' % (py_major, py_minor, abi)
pylib_dir = pyshlib = ''
# Use distutils to get the additional configuration.
ducfg = sysconfig.get_config_vars()
config_args = ducfg.get('CONFIG_ARGS', '')
dynamic_pylib = '--enable-shared' in config_args
if not dynamic_pylib:
dynamic_pylib = '--enable-framework' in config_args
if dynamic_pylib:
pyshlib = ducfg.get('LDLIBRARY', '')
exec_prefix = ducfg['exec_prefix']
multiarch = ducfg.get('MULTIARCH', '')
libdir = ducfg['LIBDIR']
if glob.glob('%s/lib/libpython%d.%d*' % (exec_prefix, py_major, py_minor)):
pylib_dir = exec_prefix + '/lib'
elif multiarch != '' and glob.glob('%s/lib/%s/libpython%d.%d*' % (exec_prefix, multiarch, py_major, py_minor)):
pylib_dir = exec_prefix + '/lib/' + multiarch
elif glob.glob('%s/libpython%d.%d*' % (libdir, py_major, py_minor)):
pylib_dir = libdir
self.py_pylib_dir = pylib_dir
self.py_pylib_lib = pylib_lib
self.py_pyshlib = pyshlib
# 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.pyqt_bin_dir = self._apply_sysroot(self.pyqt_bin_dir)
self.pyqt_module_dir = self._apply_sysroot(self.pyqt_module_dir)
self.pyqt_stubs_dir = self._apply_sysroot(self.pyqt_stubs_dir)
self.pyqt_sip_dir = self._apply_sysroot(self.pyqt_sip_dir)
inform("Determining the details of your Qt installation...")
# Compile and run the QtCore test program.
test = compile_test_program(self, verbose, 'QtCore', debug=debug)
if test is None:
error("Failed to determine the detail of your Qt installation. Try again using the --verbose flag to see more detail about the problem.")
lines = run_test_program('QtCore', test, verbose)
self.qt_shared = (lines[0] == 'shared')
self.pyqt_disabled_features = lines[1:]
if self.pyqt_disabled_features:
inform("Disabled QtCore features: %s" % ', '.join(
self.pyqt_disabled_features))
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_win32_debug_suffix(self):
""" Return the debug-dependent suffix appended to the name of Windows
libraries.
"""
return '_d' if self.py_debug else ''
def get_qt_configuration(self):
""" Get the Qt configuration that can be extracted from qmake. """
# Query qmake.
qt_config = TargetQtConfiguration(self.qmake)
self.qt_version = 0
try:
qt_version_str = qt_config.QT_VERSION
for v in qt_version_str.split('.'):
self.qt_version *= 256
self.qt_version += int(v)
except AttributeError:
qt_version_str = "3"
# Check the Qt version number as soon as possible.
if self.qt_version < 0x050000:
error(
"PyQt5 requires Qt v5.0 or later. You seem to be using "
"v%s. Use the --qmake flag to specify the correct version "
"of qmake." % qt_version_str)
self.designer_plugin_dir = qt_config.QT_INSTALL_PLUGINS + '/designer'
self.qml_plugin_dir = qt_config.QT_INSTALL_PLUGINS + '/PyQt5'
if self.sysroot == '':
self.sysroot = qt_config.QT_SYSROOT
# By default, install the API file if QScintilla seems to be installed
# in the default location.
self.qsci_api_dir = os.path.join(qt_config.QT_INSTALL_DATA, 'qsci')
self.qsci_api = os.path.isdir(self.qsci_api_dir)
# Save the default qmake spec. and finalise the value we want to use.
self.qmake_spec_default = qt_config.QMAKE_SPEC
# 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 = self.qmake_spec_default
# The binary OS/X Qt installer used to default to XCode. If so then
# use macx-clang.
if self.qmake_spec == 'macx-xcode':
# This will exist (and we can't check anyway).
self.qmake_spec = 'macx-clang'
def post_configuration(self):
""" Handle any remaining default configuration after having read a
configuration file or introspected the system.
"""
# The platform may have changed so update the default.
if self.py_platform.startswith('linux') or self.py_platform == 'darwin':
self.prot_is_public = True
self.vend_inc_dir = self.py_venv_inc_dir
self.vend_lib_dir = self.py_lib_dir
def apply_pre_options(self, opts):
""" Apply options from the command line that influence subsequent
configuration. opts are the command line options.
"""
# On Windows the interpreter must be a debug build if a debug version
# is to be built and vice versa.
if sys.platform == 'win32':
if opts.debug:
if not self.py_debug:
error(
"A debug version of Python must be used when "
"--debug is specified.")
elif self.py_debug:
error(
"--debug must be specified when a debug version of "
"Python is used.")
self.debug = opts.debug
# Get the target Python version.
if opts.target_py_version is not None:
self.py_version = opts.target_py_version
# Get the system root.
if opts.sysroot is not None:
self.sysroot = opts.sysroot
# Determine how to run qmake.
if opts.qmake is not None:
self.qmake = opts.qmake
# On Windows add the directory that probably contains the Qt DLLs
# to PATH.
if sys.platform == 'win32':
path = os.environ['PATH']
path = os.path.dirname(self.qmake) + ';' + path
os.environ['PATH'] = path
if self.qmake is None:
error(
"Use the --qmake argument to explicitly specify a working "
"Qt qmake.")
if opts.qmakespec is not None:
self.qmake_spec = opts.qmakespec
if opts.sipincdir is not None:
self.sip_inc_dir = opts.sipincdir
def apply_post_options(self, opts):
""" Apply options from the command line that override the previous
configuration. opts are the command line options.
"""
self.pyqt_disabled_features.extend(opts.disabled_features)
if opts.assumeshared:
self.qt_shared = True
if opts.bindir is not None:
self.pyqt_bin_dir = opts.bindir
if opts.licensedir is not None:
self.license_dir = opts.licensedir
if opts.link_full_dll:
self.link_full_dll = True
if opts.designerplugindir is not None:
self.designer_plugin_dir = opts.designerplugindir
if opts.qmlplugindir is not None:
self.qml_plugin_dir = opts.qmlplugindir
if opts.destdir is not None:
self.pyqt_module_dir = opts.destdir
if len(opts.modules) > 0:
self.pyqt_modules = opts.modules
if opts.nodesignerplugin:
self.no_designer_plugin = True
if opts.nodocstrings:
self.no_docstrings = True
if opts.nopydbus:
self.no_pydbus = True
if opts.noqmlplugin:
self.no_qml_plugin = True
if opts.notools:
self.no_tools = True
if opts.protispublic is not None:
self.prot_is_public = opts.protispublic
if opts.pydbusincdir is not None:
self.pydbus_inc_dir = opts.pydbusincdir
if opts.pyuicinterpreter is not None:
self.pyuic_interpreter = opts.pyuicinterpreter
if opts.qml_debug:
self.qml_debug = True
if opts.qsciapidir is not None:
self.qsci_api_dir = opts.qsciapidir
# Assume we want to install the API file if we have provided an
# installation directory.
self.qsci_api = True
if opts.qsciapi is not None:
self.qsci_api = opts.qsciapi
if opts.qsciapidir is not None:
self.qsci_api_dir = opts.qsciapidir
if opts.stubsdir is not None:
self.pyqt_stubs_dir = opts.stubsdir
elif not opts.install_stubs:
self.pyqt_stubs_dir = ''
if opts.sip is not None:
self.sip = opts.sip
if opts.abi_version is not None:
if not self.using_sip5():
error("The --abi-version argument can only be used with sip5.")
self.abi_version = opts.abi_version
if opts.sipdir is not None:
self.pyqt_sip_dir = opts.sipdir
elif not opts.install_sipfiles:
self.pyqt_sip_dir = ''
if opts.static:
self.static = True
if opts.vendenabled:
self.vend_enabled = True
if opts.vendincdir is not None:
self.vend_inc_dir = opts.vendincdir
if opts.vendlibdir is not None:
self.vend_lib_dir = opts.vendlibdir
# Handle any conflicts.
if not self.qt_shared:
if not self.static:
error(
"Qt has been built as static libraries so the "
"--static argument should be used.")
if self.vend_enabled and self.static:
error(
"Using the VendorID package when building static "
"libraries makes no sense.")
def get_pylib_link_arguments(self, name=True):
""" Return a string to append to qmake's LIBS macro to link against the
Python interpreter library.
"""
args = qmake_quote('-L' + self.py_pylib_dir)
if name:
args += ' -l' + self.py_pylib_lib
return args
def add_sip_h_directives(self, pro_lines):
""" Add the directives required by sip.h to a sequence of .pro file
lines.
"""
# Make sure the include directory is searched before the Python include
# directory if they are different.
pro_lines.append('INCLUDEPATH += %s' % qmake_quote(self.sip_inc_dir))
if self.py_inc_dir != self.sip_inc_dir:
pro_lines.append('INCLUDEPATH += %s' % qmake_quote(self.py_inc_dir))
# Python.h on Windows seems to embed the need for pythonXY.lib, so tell
# it where it is.
if not self.static:
pro_lines.extend(['win32 {',
' LIBS += ' + self.get_pylib_link_arguments(name=False),
'}'])
def using_sip5(self):