-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.py
More file actions
1954 lines (1699 loc) · 80.7 KB
/
setup.py
File metadata and controls
1954 lines (1699 loc) · 80.7 KB
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) 2016 The Qt Company Ltd.
## Contact: https://www.qt.io/licensing/
##
## This file is part of PySide2.
##
## $QT_BEGIN_LICENSE:LGPL$
## Commercial License Usage
## Licensees holding valid commercial Qt licenses may use this file in
## accordance with the commercial license agreement provided with the
## Software or, alternatively, in accordance with the terms contained in
## a written agreement between you and The Qt Company. For licensing terms
## and conditions see https://www.qt.io/terms-conditions. For further
## information use the contact form at https://www.qt.io/contact-us.
##
## GNU Lesser General Public License Usage
## Alternatively, this file may be used under the terms of the GNU Lesser
## General Public License version 3 as published by the Free Software
## Foundation and appearing in the file LICENSE.LGPL3 included in the
## packaging of this file. Please review the following information to
## ensure the GNU Lesser General Public License version 3 requirements
## will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
##
## GNU General Public License Usage
## Alternatively, this file may be used under the terms of the GNU
## General Public License version 2.0 or (at your option) the GNU General
## Public license version 3 or any later version approved by the KDE Free
## Qt Foundation. The licenses are as published by the Free Software
## Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
## included in the packaging of this file. Please review the following
## information to ensure the GNU General Public License requirements will
## be met: https://www.gnu.org/licenses/gpl-2.0.html and
## https://www.gnu.org/licenses/gpl-3.0.html.
##
## $QT_END_LICENSE$
##
#############################################################################
from __future__ import print_function
from distutils.version import LooseVersion
"""
This is a distutils setup-script for the Qt for Python project
To build PySide2 simply execute:
python setup.py build
or
python setup.py install
to build and install into your current Python installation.
Optionally, one can specify the location of qmake and cmake if it is
not on the current PATH with:
--qmake=/path/to/qt/bin/qmake
and
--cmake=/path/to/bin/cmake
respectively.
For windows, if OpenSSL support is required, it is necessary to specify
the directory with:
--openssl=/path/to/openssl/bin
ADDITIONAL OPTIONS:
On Linux and macOS you can use the option `--standalone` to embed Qt
libraries into the PySide2 package.
The option does not affect Windows, because it is used implicitly,
i.e. all relevant DLLs have to be copied into the PySide2 package
anyway, because there is no proper rpath support on the platform.
You can use the option `--rpath=/path/to/lib/path` to specify which
rpath values should be embedded into the PySide2 modules and shared
libraries.
This overrides the automatically generated values when the option is
not specified.
You can use the option `--only-package` if you want to create more
binary packages (bdist_wheel, bdist_egg, ...) without rebuilding the
entire PySide2 every time:
e.g.:
* First, we create a bdist_wheel from a full PySide2 build:
python setup.py bdist_wheel --qmake=c:\Qt\5.9\bin\qmake.exe
--cmake=c:\tools\cmake\bin\cmake.exe
--openssl=c:\libs\OpenSSL32bit\bin
* Then, we create a bdist_egg reusing PySide2 build with option
`--only-package`:
python setup.py bdist_egg --only-package
--qmake=c:\Qt\5.9\bin\qmake.exe
--cmake=c:\tools\cmake\bin\cmake.exe
--openssl=c:\libs\OpenSSL32bit\bin
You can use the option `--qt-conf-prefix` to pass a path relative to
the PySide2 installed package, which will be embedded into an
auto-generated `qt.conf` registered in the Qt resource system.
This path will serve as the PrefixPath for QLibraryInfo, thus allowing
to choose where Qt plugins should be loaded from.
This option overrides the usual prefix chosen by `--standalone` option,
or when building on Windows.
To temporarily disable registration of the internal `qt.conf` file, a
new environment variable called PYSIDE_DISABLE_INTERNAL_QT_CONF is
introduced.
You should assign the integer "1" to disable the internal `qt.conf`,
or "0" (or leave empty) to keep usining the internal `qt.conf` file.
DEVELOPMENT OPTIONS:
For development purposes the following options might be of use, when
using `setup.py build`:
--reuse-build option allows recompiling only the modified sources and
not the whole world, shortening development iteration time,
--skip-cmake will reuse the already generated Makefiles (or
equivalents), instead of invoking, CMake to update the
Makefiles (note, CMake should be ran at least once to generate
the files),
--skip-make-install will not run make install (or equivalent) for
each module built,
--skip-packaging will skip creation of the python package,
--ignore-git will skip the fetching and checkout steps for
supermodule and all submodules.
--verbose-build will output the compiler invocation with command line
arguments, etc.
--sanitize-address will build the project with address sanitizer
enabled (Linux or macOS only).
REQUIREMENTS:
* Python: 2.7 and 3.3+ are supported
* CMake: Specify the path to cmake with `--cmake` option or add cmake
to the system path.
* Qt: 5.9 and 5.11 are supported. Specify the path to qmake with
`--qmake` option or add qmake to the system path.
OPTIONAL:
* OpenSSL:
Specifying the --openssl option is only required on Windows.
It is a no-op for other platforms.
You can specify the location of OpenSSL DLLs with option:
--openssl=</path/to/openssl/bin>.
You can download OpenSSL for Windows here:
http://slproweb.com/products/Win32OpenSSL.html (*)
Official Qt packages do not link to the SSL library directly, but
rather try to find the library at runtime.
On Windows, official Qt builds will try to pick up OpenSSL
libraries at application path, system registry, or in the PATH
environment variable.
On macOS, official Qt builds use SecureTransport (provided by OS)
instead of OpenSSL.
On Linux, official Qt builds will try to pick up the system OpenSSL
library.
Note: this means that Qt packages that directly link to the OpenSSL
shared libraries, are not currently compatible with
standalone PySide2 packages.
(*) Revised on 23.03.2018
* macOS SDK:
You can specify which macOS SDK should be used for compilation with
the option:
--osx-sysroot=</path/to/sdk>.
e.g.: "--osx-sysroot=/Applications/.../Developer/SDKs/MacOSX10.11.sdk/"
* macOS minimum deployment target:
You can specify a custom macOS minimum deployment target with the
option:
--osx-deployment-target=<value>
e.g.: "--osx-deployment-target=10.10"
If the option is not set, the minimum deployment target of the used
Qt library will be used instead. Thus it is not necessary to use
the option without a good reason.
If a new value is specified, it has to be higher or equal to both
Python's and Qt's minimum deployment targets.
Description: macOS allows specifying a minimum OS version on which
a binary will be able to run. This implies that an
application can be built on a machine with the latest
macOS version installed, with latest Xcode version and
SDK version and the built application can still run on
an older OS version.
"""
import os
import time
from utils import memoize, has_option, get_python_dict
OPTION_SNAPSHOT_BUILD = has_option("snapshot-build")
# Change the cwd to setup.py's dir.
try:
this_file = __file__
except NameError:
this_file = sys.argv[0]
this_file = os.path.abspath(this_file)
if os.path.dirname(this_file):
os.chdir(os.path.dirname(this_file))
script_dir = os.getcwd()
@memoize
def get_package_timestamp():
return int(time.time())
@memoize
def get_package_version():
""" Returns the version string for the PySide2 package. """
pyside_version_py = os.path.join(script_dir, "sources", "pyside2", "pyside_version.py")
d = get_python_dict(pyside_version_py)
final_version = "{}.{}.{}".format(d['major_version'], d['minor_version'], d['patch_version'])
pre_release_version_type = d['pre_release_version_type']
pre_release_version = d['pre_release_version']
if pre_release_version and pre_release_version:
final_version += pre_release_version_type + pre_release_version
# Add the current timestamp to the version number, to suggest it is a development snapshot
# build.
if OPTION_SNAPSHOT_BUILD:
final_version += ".dev{}".format(get_package_timestamp())
return final_version
# The __version__ variable is just for PEP compliancy, and shoudn't be used as a value source.
__version__ = get_package_version()
# Buildable extensions.
containedModules = ['shiboken2', 'pyside2', 'pyside2-tools']
# Git submodules: ["submodule_name", "location_relative_to_sources_folder"]
submodules = [["pyside2-tools"]]
pyside_package_dir_name = "pyside_package"
try:
import setuptools
except ImportError:
from ez_setup import use_setuptools
use_setuptools()
import sys
import platform
import re
import fnmatch
import difflib # for a close match of dirname and module
import functools
from distutils import log
from distutils.errors import DistutilsOptionError
from distutils.errors import DistutilsSetupError
from distutils.sysconfig import get_config_var
from distutils.sysconfig import get_python_lib
from distutils.spawn import find_executable
from distutils.command.build import build as _build
from distutils.command.build_ext import build_ext as _build_ext
from distutils.util import get_platform
from setuptools import setup, Extension
from setuptools.command.install import install as _install
from setuptools.command.install_lib import install_lib as _install_lib
from setuptools.command.bdist_egg import bdist_egg as _bdist_egg
from setuptools.command.develop import develop as _develop
from setuptools.command.build_py import build_py as _build_py
wheel_module_exists = False
try:
from wheel.bdist_wheel import bdist_wheel as _bdist_wheel
from wheel.bdist_wheel import safer_name as _safer_name
wheel_module_exists = True
except ImportError:
pass
from qtinfo import QtInfo
from utils import rmtree, detectClang
from utils import makefile
from utils import copyfile
from utils import copydir
from utils import run_process_output, run_process
from utils import option_value
from utils import update_env_path
from utils import init_msvc_env
from utils import regenerate_qt_resources
from utils import filter_match
from utils import osx_fix_rpaths_for_library
from utils import copy_icu_libs
from utils import find_files_using_glob
from textwrap import dedent
# make sure that setup.py is run with an allowed python version
def check_allowed_python_version():
import re
pattern = "'Programming Language :: Python :: (\d+)\.(\d+)'"
supported = []
with open(this_file) as setup:
for line in setup.readlines():
found = re.search(pattern, line)
if found:
major = int(found.group(1))
minor = int(found.group(2))
supported.append( (major, minor) )
this_py = sys.version_info[:2]
if this_py not in supported:
print("only these python versions are supported:", supported)
sys.exit(1)
check_allowed_python_version()
qtSrcDir = ''
# Declare options
OPTION_DEBUG = has_option("debug")
OPTION_RELWITHDEBINFO = has_option('relwithdebinfo')
OPTION_QMAKE = option_value("qmake")
OPTION_QT_VERSION = option_value("qt")
OPTION_CMAKE = option_value("cmake")
OPTION_OPENSSL = option_value("openssl")
OPTION_ONLYPACKAGE = has_option("only-package")
OPTION_STANDALONE = has_option("standalone")
OPTION_VERSION = option_value("version") # Deprecated
OPTION_LISTVERSIONS = has_option("list-versions") # Deprecated
OPTION_MAKESPEC = option_value("make-spec")
OPTION_IGNOREGIT = has_option("ignore-git")
OPTION_NOEXAMPLES = has_option("no-examples") # don't include pyside2-examples
OPTION_JOBS = option_value('jobs') # number of parallel build jobs
OPTION_JOM = has_option('jom') # Legacy, not used any more.
OPTION_NO_JOM = has_option('no-jom') # Do not use jom instead of nmake with msvc
OPTION_BUILDTESTS = has_option("build-tests")
OPTION_OSXARCH = option_value("osx-arch")
OPTION_OSX_USE_LIBCPP = has_option("osx-use-libc++")
OPTION_OSX_SYSROOT = option_value("osx-sysroot")
OPTION_OSX_DEPLOYMENT_TARGET = option_value("osx-deployment-target")
OPTION_XVFB = has_option("use-xvfb")
OPTION_REUSE_BUILD = has_option("reuse-build")
OPTION_SKIP_CMAKE = has_option("skip-cmake")
OPTION_SKIP_MAKE_INSTALL = has_option("skip-make-install")
OPTION_SKIP_PACKAGING = has_option("skip-packaging")
OPTION_MODULE_SUBSET = option_value("module-subset")
OPTION_RPATH_VALUES = option_value("rpath")
OPTION_QT_CONF_PREFIX = option_value("qt-conf-prefix")
OPTION_QT_SRC = option_value("qt-src-dir")
OPTION_ICULIB = option_value("iculib-url") # Deprecated
OPTION_VERBOSE_BUILD = has_option("verbose-build")
OPTION_SANITIZE_ADDRESS = has_option("sanitize-address")
# This is used automatically by distutils.command.install object, to specify final installation
# location.
OPTION_FINAL_INSTALL_PREFIX = option_value("prefix")
if OPTION_QT_VERSION is None:
OPTION_QT_VERSION = "5"
if OPTION_QMAKE is None:
OPTION_QMAKE = find_executable("qmake-qt5")
if OPTION_QMAKE is None:
OPTION_QMAKE = find_executable("qmake")
# make qtinfo.py independent of relative paths.
if OPTION_QMAKE is not None and os.path.exists(OPTION_QMAKE):
OPTION_QMAKE = os.path.abspath(OPTION_QMAKE)
if OPTION_CMAKE is not None and os.path.exists(OPTION_CMAKE):
OPTION_CMAKE = os.path.abspath(OPTION_CMAKE)
QMAKE_COMMAND = None
if OPTION_QMAKE is not None and os.path.exists(OPTION_QMAKE): # Checking whether qmake executable exists
if os.path.islink(OPTION_QMAKE) and os.path.lexists(OPTION_QMAKE): # Looking whether qmake path is a link and whether the link exists
if "qtchooser" in os.readlink(OPTION_QMAKE): # Set -qt=X here.
QMAKE_COMMAND = [OPTION_QMAKE, "-qt=%s" %(OPTION_QT_VERSION)]
if not QMAKE_COMMAND:
QMAKE_COMMAND = [OPTION_QMAKE]
if len(QMAKE_COMMAND) == 0 or QMAKE_COMMAND[0] is None:
print("qmake could not be found.")
sys.exit(1)
if not os.path.exists(QMAKE_COMMAND[0]):
print("'%s' does not exist." % QMAKE_COMMAND[0])
sys.exit(1)
if OPTION_CMAKE is None:
OPTION_CMAKE = find_executable("cmake")
if OPTION_CMAKE is None:
print("cmake could not be found.")
sys.exit(1)
if not os.path.exists(OPTION_CMAKE):
print("'%s' does not exist." % OPTION_CMAKE)
sys.exit(1)
if sys.platform == "win32":
if OPTION_MAKESPEC is None:
OPTION_MAKESPEC = "msvc"
if not OPTION_MAKESPEC in ["msvc", "mingw"]:
print("Invalid option --make-spec. Available values are %s" % (["msvc", "mingw"]))
sys.exit(1)
else:
if OPTION_MAKESPEC is None:
OPTION_MAKESPEC = "make"
if not OPTION_MAKESPEC in ["make"]:
print("Invalid option --make-spec. Available values are %s" % (["make"]))
sys.exit(1)
if OPTION_JOBS:
if sys.platform == 'win32' and OPTION_NO_JOM:
print("Option --jobs can only be used with jom on Windows.")
sys.exit(1)
else:
if not OPTION_JOBS.startswith('-j'):
OPTION_JOBS = '-j' + OPTION_JOBS
else:
OPTION_JOBS = ''
if OPTION_ICULIB:
if not OPTION_STANDALONE:
print("--iculib-url option is a no-op option and will be removed soon.")
def is_debug_python():
return getattr(sys, "gettotalrefcount", None) is not None
# Return a prefix suitable for the _install/_build directory
def prefix():
virtualEnvName = os.environ.get('VIRTUAL_ENV', None)
name = os.path.basename(virtualEnvName) if virtualEnvName is not None else 'pyside'
name += str(sys.version_info[0])
if OPTION_DEBUG:
name += 'd'
if is_debug_python():
name += 'p'
return name
# Initialize, pull and checkout submodules
def prepareSubModules():
print("Initializing submodules for PySide2 version: {}".format(get_package_version()))
submodules_dir = os.path.join(script_dir, "sources")
# Create list of [name, desired branch, absolute path, desired branch]
# and determine whether all submodules are present
needInitSubModules = False
for m in submodules:
module_name = m[0]
module_dir = m[1] if len(m) > 1 else ''
module_dir = os.path.join(submodules_dir, module_dir, module_name)
# Check for non-empty directory (repository checked out)
if not os.listdir(module_dir):
needInitSubModules = True
break
if needInitSubModules:
git_update_cmd = ["git", "submodule", "update", "--init"]
if run_process(git_update_cmd) != 0:
m = "Failed to initialize the git submodules: update --init failed"
raise DistutilsSetupError(m)
git_pull_cmd = ["git", "submodule", "foreach", "git", "fetch", "--all"]
if run_process(git_pull_cmd) != 0:
m = "Failed to initialize the git submodules: git fetch --all failed"
raise DistutilsSetupError(m)
else:
print("All submodules present.")
git_update_cmd = ["git", "submodule", "update"]
if run_process(git_update_cmd) != 0:
m = "Failed to checkout the correct git submodules SHA1s."
raise DistutilsSetupError(m)
# Single global instance of QtInfo to be used later in multiple code paths.
qtinfo = QtInfo(QMAKE_COMMAND)
def get_qt_version():
qt_version = qtinfo.version
if not qt_version:
log.error("Failed to query the Qt version with qmake {0}".format(self.qtinfo.qmake_command))
sys.exit(1)
if LooseVersion(qtinfo.version) < LooseVersion("5.7"):
m = "Incompatible Qt version detected: {0}. A Qt version >= 5.7 is required."
log.error(m.format(qt_version))
sys.exit(1)
return qt_version
def prepareBuild():
if os.path.isdir(".git") and not OPTION_IGNOREGIT and not OPTION_ONLYPACKAGE and not OPTION_REUSE_BUILD:
prepareSubModules()
# Clean up temp and package folders
for n in [pyside_package_dir_name, "build"]:
d = os.path.join(script_dir, n)
if os.path.isdir(d):
print("Removing %s" % d)
try:
rmtree(d)
except Exception as e:
print('***** problem removing "{}"'.format(d))
print('ignored error: {}'.format(e))
# Prepare package folders
ppdn = pyside_package_dir_name
for pkg in [os.path.join(ppdn, "PySide2"), os.path.join(ppdn, "pyside2uic")]:
pkg_dir = os.path.join(script_dir, pkg)
os.makedirs(pkg_dir)
# locate Qt sources for the documentation
if OPTION_QT_SRC is None:
installPrefix = qtinfo.prefix_dir
if installPrefix:
global qtSrcDir
if installPrefix.endswith("qtbase"): # In-source, developer build
qtSrcDir = installPrefix
else: # SDK: Use 'Src' directory
qtSrcDir = os.path.join(os.path.dirname(installPrefix), 'Src', 'qtbase')
class pyside_install(_install):
def __init__(self, *args, **kwargs):
_install.__init__(self, *args, **kwargs)
def initialize_options (self):
_install.initialize_options(self)
if sys.platform == 'darwin':
# Because we change the plat_name to include a correct deployment target on macOS
# distutils thinks we are cross-compiling, and throws an exception when trying to
# execute setup.py install.
# The check looks like this
#if self.warn_dir and build_plat != get_platform():
# raise DistutilsPlatformError("Can't install when "
# "cross-compiling")
# Obviously get_platform will return the old deployment target.
# The fix is to disable the warn_dir flag, which was created for bdist_* derived classes
# to override, for similar cases.
self.warn_dir = False
def run(self):
_install.run(self)
log.info('*** Install completed')
class pyside_develop(_develop):
def __init__(self, *args, **kwargs):
_develop.__init__(self, *args, **kwargs)
def run(self):
self.run_command("build")
_develop.run(self)
class pyside_bdist_egg(_bdist_egg):
def __init__(self, *args, **kwargs):
_bdist_egg.__init__(self, *args, **kwargs)
def run(self):
self.run_command("build")
_bdist_egg.run(self)
class pyside_build_ext(_build_ext):
def __init__(self, *args, **kwargs):
_build_ext.__init__(self, *args, **kwargs)
def run(self):
pass
if wheel_module_exists:
class pyside_build_wheel(_bdist_wheel):
def __init__(self, *args, **kwargs):
_bdist_wheel.__init__(self, *args, **kwargs)
@property
def wheel_dist_name(self):
# Slightly modified version of wheel's wheel_dist_name method, to add the Qt version
# as well.
# Example: PySide2-5.6-5.6.4-cp27-cp27m-macosx_10_10_intel.whl
# The PySide2 version is "5.6. The built against Qt version is "5.6.4.
qt_version = get_qt_version()
package_version = get_package_version()
wheel_version = "{}-{}".format(package_version, qt_version)
components = (_safer_name(self.distribution.get_name()),
wheel_version)
if self.build_number:
components += (self.build_number,)
return '-'.join(components)
def finalize_options(self):
if sys.platform == 'darwin':
# Override the platform name to contain the correct minimum deployment target.
# This is used in the final wheel name.
self.plat_name = pyside_build.macos_plat_name()
_bdist_wheel.finalize_options(self)
# pyside_build_py and pyside_install_lib are reimplemented to preserve symlinks when
# distutils / setuptools copy files to various directories through the different build stages.
class pyside_build_py(_build_py):
def __init__(self, *args, **kwargs):
_build_py.__init__(self, *args, **kwargs)
def build_package_data(self):
"""Copies files from pyside_package into build/xxx directory"""
for package, src_dir, build_dir, filenames in self.data_files:
for filename in filenames:
target = os.path.join(build_dir, filename)
self.mkpath(os.path.dirname(target))
srcfile = os.path.abspath(os.path.join(src_dir, filename))
# Using our own copyfile makes sure to preserve symlinks.
copyfile(srcfile, target)
class pyside_install_lib(_install_lib):
def __init__(self, *args, **kwargs):
_install_lib.__init__(self, *args, **kwargs)
def install(self):
"""Installs files from build/xxx directory into final site-packages/PySide2 directory."""
if os.path.isdir(self.build_dir):
# Using our own copydir makes sure to preserve symlinks.
outfiles = copydir(os.path.abspath(self.build_dir), os.path.abspath(self.install_dir))
else:
self.warn("'%s' does not exist -- no Python modules to install" % self.build_dir)
return
return outfiles
class pyside_build(_build):
def __init__(self, *args, **kwargs):
_build.__init__(self, *args, **kwargs)
def finalize_options(self):
os_name_backup = os.name
if sys.platform == 'darwin':
self.plat_name = pyside_build.macos_plat_name()
# This is a hack to circumvent the dubious check in distutils.commands.build ->
# finalize_options, which only allows setting the plat_name for windows NT.
# That is not the case for the wheel module though (which does allow setting plat_name),
# so we circumvent by faking the os name when finalizing the options, and then restoring
# the original os name.
os.name = "nt"
_build.finalize_options(self)
if sys.platform == 'darwin':
os.name = os_name_backup
def initialize_options(self):
_build.initialize_options(self)
self.make_path = None
self.make_generator = None
self.debug = False
self.script_dir = None
self.sources_dir = None
self.build_dir = None
self.install_dir = None
self.py_executable = None
self.py_include_dir = None
self.py_library = None
self.py_version = None
self.build_type = "Release"
self.qtinfo = None
self.build_tests = False
def run(self):
prepareBuild()
platform_arch = platform.architecture()[0]
log.info("Python architecture is %s" % platform_arch)
build_type = "Debug" if OPTION_DEBUG else "Release"
if OPTION_RELWITHDEBINFO:
build_type = 'RelWithDebInfo'
# Check env
make_path = None
make_generator = None
if not OPTION_ONLYPACKAGE:
if OPTION_MAKESPEC == "make":
make_name = "make"
make_generator = "Unix Makefiles"
elif OPTION_MAKESPEC == "msvc":
nmake_path = find_executable("nmake")
if nmake_path is None or not os.path.exists(nmake_path):
log.info("nmake not found. Trying to initialize the MSVC env...")
init_msvc_env(platform_arch, build_type)
nmake_path = find_executable("nmake")
assert(nmake_path is not None and os.path.exists(nmake_path))
jom_path = None if OPTION_NO_JOM else find_executable("jom")
if jom_path is not None and os.path.exists(jom_path):
log.info("jom was found in %s" % jom_path)
make_name = "jom"
make_generator = "NMake Makefiles JOM"
else:
log.info("nmake was found in %s" % nmake_path)
make_name = "nmake"
make_generator = "NMake Makefiles"
elif OPTION_MAKESPEC == "mingw":
make_name = "mingw32-make"
make_generator = "MinGW Makefiles"
else:
raise DistutilsSetupError(
"Invalid option --make-spec.")
make_path = find_executable(make_name)
if make_path is None or not os.path.exists(make_path):
raise DistutilsSetupError(
"You need the program \"%s\" on your system path to compile PySide2." \
% make_name)
if OPTION_CMAKE is None or not os.path.exists(OPTION_CMAKE):
raise DistutilsSetupError(
"Failed to find cmake."
" Please specify the path to cmake with --cmake parameter.")
if OPTION_QMAKE is None or not os.path.exists(OPTION_QMAKE):
raise DistutilsSetupError(
"Failed to find qmake."
" Please specify the path to qmake with --qmake parameter.")
# Prepare parameters
py_executable = sys.executable
py_version = "%s.%s" % (sys.version_info[0], sys.version_info[1])
py_include_dir = get_config_var("INCLUDEPY")
py_libdir = get_config_var("LIBDIR")
py_prefix = get_config_var("prefix")
if not py_prefix or not os.path.exists(py_prefix):
py_prefix = sys.prefix
if sys.platform == "win32":
py_scripts_dir = os.path.join(py_prefix, "Scripts")
else:
py_scripts_dir = os.path.join(py_prefix, "bin")
if py_libdir is None or not os.path.exists(py_libdir):
if sys.platform == "win32":
py_libdir = os.path.join(py_prefix, "libs")
else:
py_libdir = os.path.join(py_prefix, "lib")
if py_include_dir is None or not os.path.exists(py_include_dir):
if sys.platform == "win32":
py_include_dir = os.path.join(py_prefix, "include")
else:
py_include_dir = os.path.join(py_prefix, "include/python%s" % py_version)
dbgPostfix = ""
if build_type == "Debug":
dbgPostfix = "_d"
if sys.platform == "win32":
if OPTION_MAKESPEC == "mingw":
py_library = os.path.join(py_libdir, "libpython%s%s.a" % \
(py_version.replace(".", ""), dbgPostfix))
else:
py_library = os.path.join(py_libdir, "python%s%s.lib" % \
(py_version.replace(".", ""), dbgPostfix))
else:
lib_exts = ['.so']
if sys.platform == 'darwin':
lib_exts.append('.dylib')
if sys.version_info[0] > 2:
lib_suff = getattr(sys, 'abiflags', None)
else: # Python 2
lib_suff = ''
lib_exts.append('.so.1')
# Suffix for OpenSuSE 13.01
lib_exts.append('.so.1.0')
lib_exts.append('.a') # static library as last gasp
if sys.version_info[0] == 2 and dbgPostfix:
# For Python2 add a duplicate set of extensions combined with
# the dbgPostfix, so we test for both the debug version of
# the lib and the normal one. This allows a debug PySide2 to
# be built with a non-debug Python.
lib_exts = [dbgPostfix + e for e in lib_exts] + lib_exts
python_library_found = False
libs_tried = []
for lib_ext in lib_exts:
lib_name = "libpython%s%s%s" % (py_version, lib_suff, lib_ext)
py_library = os.path.join(py_libdir, lib_name)
if os.path.exists(py_library):
python_library_found = True
break
libs_tried.append(py_library)
else:
# At least on macOS 10.11, the system Python 2.6 does not include a symlink
# to the framework file disguised as a .dylib file, thus finding the library would
# fail. Manually check if a framework file "Python" exists in the Python framework
# bundle.
if sys.platform == 'darwin' and sys.version_info[:2] == (2, 6):
# These manipulations essentially transform
# /System/Library/Frameworks/Python.framework/Versions/2.6/lib
# to /System/Library/Frameworks/Python.framework/Versions/2.6/Python
possible_framework_path = os.path.realpath(os.path.join(py_libdir, '..'))
possible_framework_version = os.path.basename(possible_framework_path)
possible_framework_library = os.path.join(possible_framework_path, 'Python')
if possible_framework_version == '2.6' \
and os.path.exists(possible_framework_library):
py_library = possible_framework_library
python_library_found = True
else:
libs_tried.append(possible_framework_library)
# Try to find shared libraries which have a multi arch suffix.
if not python_library_found:
py_multiarch = get_config_var("MULTIARCH")
if py_multiarch and not python_library_found:
try_py_libdir = os.path.join(py_libdir, py_multiarch)
libs_tried = []
for lib_ext in lib_exts:
lib_name = "libpython%s%s%s" % (py_version, lib_suff, lib_ext)
py_library = os.path.join(try_py_libdir, lib_name)
if os.path.exists(py_library):
py_libdir = try_py_libdir
python_library_found = True
break
libs_tried.append(py_library)
if not python_library_found:
raise DistutilsSetupError(
"Failed to locate the Python library with %s" %
', '.join(libs_tried))
if py_library.endswith('.a'):
# Python was compiled as a static library
log.error("Failed to locate a dynamic Python library, using %s"
% py_library)
self.qtinfo = qtinfo
qt_dir = os.path.dirname(OPTION_QMAKE)
qt_version = get_qt_version()
# Update the PATH environment variable
additionalPaths = [py_scripts_dir, qt_dir]
# Add Clang to path for Windows. Revisit once Clang is bundled with Qt.
if sys.platform == "win32" and LooseVersion(self.qtinfo.version) >= LooseVersion("5.7.0"):
clangDir = detectClang()
if clangDir[0]:
clangBinDir = os.path.join(clangDir[0], 'bin')
if not clangBinDir in os.environ.get('PATH'):
log.info("Adding %s as detected by %s to PATH" % (clangBinDir, clangDir[1]))
additionalPaths.append(clangBinDir)
else:
log.error("Failed to detect Clang by checking LLVM_INSTALL_DIR, CLANG_INSTALL_DIR, llvm-config")
update_env_path(additionalPaths)
build_name = "py%s-qt%s-%s-%s" % \
(py_version, qt_version, platform.architecture()[0], build_type.lower())
script_dir = os.getcwd()
sources_dir = os.path.join(script_dir, "sources")
build_dir = os.path.join(script_dir, prefix() + '_build', "%s" % build_name)
install_dir = os.path.join(script_dir, prefix() + '_install', "%s" % build_name)
# Try to ensure that tools built by this script (such as shiboken2)
# are found before any that may already be installed on the system.
update_env_path([os.path.join(install_dir, 'bin')])
# Tell cmake to look here for *.cmake files
os.environ['CMAKE_PREFIX_PATH'] = install_dir
self.make_path = make_path
self.make_generator = make_generator
self.debug = OPTION_DEBUG
self.script_dir = script_dir
self.pyside_package_dir = os.path.join(self.script_dir, pyside_package_dir_name)
self.sources_dir = sources_dir
self.build_dir = build_dir
self.install_dir = install_dir
self.py_executable = py_executable
self.py_include_dir = py_include_dir
self.py_library = py_library
self.py_version = py_version
self.build_type = build_type
self.site_packages_dir = get_python_lib(1, 0, prefix=install_dir)
self.build_tests = OPTION_BUILDTESTS
setuptools_install_prefix = get_python_lib(1)
if OPTION_FINAL_INSTALL_PREFIX:
setuptools_install_prefix = OPTION_FINAL_INSTALL_PREFIX
# Save the shiboken build dir path for clang deployment purposes.
self.shiboken_build_dir = os.path.join(self.build_dir, "shiboken2")
log.info("=" * 30)
log.info("Package version: %s" % get_package_version())
log.info("Build type: %s" % self.build_type)
log.info("Build tests: %s" % self.build_tests)
log.info("-" * 3)
log.info("Make path: %s" % self.make_path)
log.info("Make generator: %s" % self.make_generator)
log.info("Make jobs: %s" % OPTION_JOBS)
log.info("-" * 3)
log.info("Script directory: %s" % self.script_dir)
log.info("Sources directory: %s" % self.sources_dir)
log.info(dedent("""
Building PySide2 will create and touch directories in the following order:
make build directory (py*_build/*/*) ->
make install directory (py*_install/*/*) ->
{} directory (pyside_package/*) ->
setuptools build directory (build/*/*) ->
setuptools install directory (usually path-installed-python/lib/python*/site-packages/*)
""").format(pyside_package_dir_name))
log.info("make build directory: %s" % self.build_dir)
log.info("make install directory: %s" % self.install_dir)
log.info("%s directory: %s" % (pyside_package_dir_name, self.pyside_package_dir))
log.info("setuptools build directory: %s" % os.path.join(self.script_dir, "build"))
log.info("setuptools install directory: %s" % setuptools_install_prefix)
log.info("make-installed site-packages directory: %s \n"
" (only relevant for copying files from 'make install directory' "
"to '%s directory'" % (self.site_packages_dir, pyside_package_dir_name))
log.info("-" * 3)
log.info("Python executable: %s" % self.py_executable)
log.info("Python includes: %s" % self.py_include_dir)
log.info("Python library: %s" % self.py_library)
log.info("Python prefix: %s" % py_prefix)
log.info("Python scripts: %s" % py_scripts_dir)
log.info("-" * 3)
log.info("Qt qmake: %s" % self.qtinfo.qmake_command)
log.info("Qt version: %s" % self.qtinfo.version)
log.info("Qt bins: %s" % self.qtinfo.bins_dir)
log.info("Qt docs: %s" % self.qtinfo.docs_dir)
log.info("Qt plugins: %s" % self.qtinfo.plugins_dir)
log.info("-" * 3)
if sys.platform == 'win32':
log.info("OpenSSL dll directory: %s" % OPTION_OPENSSL)
if sys.platform == 'darwin':
pyside_macos_deployment_target = pyside_build.macos_pyside_min_deployment_target()
log.info("MACOSX_DEPLOYMENT_TARGET set to: {}".format(pyside_macos_deployment_target))
log.info("=" * 30)
# Prepare folders
if not os.path.exists(self.sources_dir):
log.info("Creating sources folder %s..." % self.sources_dir)
os.makedirs(self.sources_dir)
if not os.path.exists(self.build_dir):
log.info("Creating build folder %s..." % self.build_dir)
os.makedirs(self.build_dir)
if not os.path.exists(self.install_dir):
log.info("Creating install folder %s..." % self.install_dir)
os.makedirs(self.install_dir)
if not OPTION_ONLYPACKAGE:
# Build extensions
for ext in containedModules:
self.build_extension(ext)
if OPTION_BUILDTESTS:
# we record the latest successful build and note the build
# directory for supporting the tests.
timestamp = time.strftime('%Y-%m-%d_%H%M%S')
build_history = os.path.join(script_dir, 'build_history')
unique_dir = os.path.join(build_history, timestamp)
os.makedirs(unique_dir)
fpath = os.path.join(unique_dir, 'build_dir.txt')
with open(fpath, 'w') as f:
print(build_dir, file=f)
log.info("Created %s" % build_history)
if not OPTION_SKIP_PACKAGING:
# Build patchelf if needed
self.build_patchelf()
# Prepare packages
self.prepare_packages()
# Build packages
_build.run(self)
else:
log.info("Skipped preparing and building packages.")
log.info('*** Build completed')
@staticmethod
def macos_qt_min_deployment_target():
target = qtinfo.macos_min_deployment_target
if not target:
raise DistutilsSetupError("Failed to query for Qt's QMAKE_MACOSX_DEPLOYMENT_TARGET.")
return target
@staticmethod
@memoize
def macos_pyside_min_deployment_target():
"""
Compute and validate PySide2 MACOSX_DEPLOYMENT_TARGET value. Candidate sources that are
considered:
- setup.py provided value
- maximum value between minimum deployment target of the Python interpreter and the
minimum deployment target of the Qt libraries.
If setup.py value is provided, that takes precedence.