/
build.py
113 lines (95 loc) · 3.4 KB
/
build.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
"""
This file includes the build configuration for the Tribler.
The exports of this file are used in setup.py to build the executable or wheel package.
There are two build options:
1) setuptools is used to build the wheel package.
To create a wheel package:
python setup.py bdist_wheel
2) Building executable is done using cx_Freeze.
To build an executable:
python setup.py build
To create a distributable package:
python setup.py bdist
To create a distributable package for a specific platform:
python setup.py bdist_mac
python setup.py bdist_win
Building wheel and building executable had to be separated because cx_Freeze does not
support building wheels. Therefore, the build options are separated into two functions
and the appropriate function is called based on the command line arguments.
"""
import sys
def get_wheel_build_options():
from setuptools import setup as _setup # pylint: disable=import-outside-toplevel
_setup_options = {"build_exe": {}}
_setup_executables = None
return _setup, _setup_options, _setup_executables
def get_freeze_build_options():
from cx_Freeze import setup as _setup, Executable # pylint: disable=import-outside-toplevel
# These packages will be included in the build
sys.path.insert(0, 'src')
included_packages = [
"aiohttp_apispec",
"sentry_sdk",
"ipv8",
"PIL",
"pkg_resources",
"pydantic",
"pyqtgraph",
"PyQt5.QtTest",
"requests",
"tribler.core",
"tribler.gui",
"faker",
"libtorrent",
"ssl",
]
# These files will be included in the build
included_files = [
("src/tribler/gui/qt_resources", "qt_resources"),
("src/tribler/gui/images", "images"),
("src/tribler/gui/i18n", "i18n"),
("src/tribler/core", "tribler_source/tribler/core"),
("src/tribler/gui", "tribler_source/tribler/gui"),
("build/win/resources", "tribler_source/resources"),
]
# These packages will be excluded from the build
excluded_packages = [
'wx',
'PyQt4',
'FixTk',
'tcl',
'tk',
'_tkinter',
'tkinter',
'Tkinter',
'matplotlib'
]
_setup_options = {
"build_exe": {
"packages": included_packages,
"excludes": excluded_packages,
"include_files": included_files,
"include_msvcr": True,
'build_exe': 'dist/tribler'
}
}
app_name = "Tribler" if sys.platform != "linux" else "tribler"
app_script = "src/tribler/run.py"
app_icon_path = "build/win/resources/tribler.ico" if sys.platform == "win32" else "build/mac/resources/tribler.icns"
_setup_executables = [
Executable(
target_name=app_name,
script=app_script,
base="Win32GUI" if sys.platform == "win32" else None,
icon=app_icon_path,
)
]
return _setup, _setup_options, _setup_executables
# Based on the command line arguments, get the build options.
# If the command line arguments include 'setup.py' and 'bdist_wheel',
# then the options are for building a wheel package.
# Otherwise, the options are for building an executable (any other).
if {'setup.py', 'bdist_wheel'}.issubset(sys.argv):
setup, setup_options, setup_executables = get_wheel_build_options()
else:
setup, setup_options, setup_executables = get_freeze_build_options()