This repository has been archived by the owner on Aug 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
tribler.spec
150 lines (125 loc) · 5.39 KB
/
tribler.spec
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
# -*- mode: python -*-
from packaging.version import Version
block_cipher = None
import imp
import os
import re
import shutil
import sys
import aiohttp_apispec
from PyInstaller.utils.hooks import collect_data_files, collect_submodules
root_dir = os.path.abspath(os.path.dirname(__name__))
src_dir = os.path.join(root_dir, "src")
sys.path.append(src_dir)
pyipv8_dir = os.path.join(root_dir, "pyipv8")
sys.path.append(pyipv8_dir)
# Import components that are not imported by the main script
import tribler.core.components as known_components
# Turn the tag into a sequence of integer values and normalize into a period-separated string.
raw_version = os.getenv("GITHUB_TAG")
version_numbers = [str(value) for value in map(int, re.findall(r"\d+", raw_version))]
version_str = str(Version(".".join(version_numbers)))
# On macOS, we always show the console to prevent the double-dock bug (although the OS does not actually show the console).
# See https://github.com/Tribler/tribler/issues/3817
show_console = os.environ.get('SHOW_CONSOLE', 'false') == 'true'
if sys.platform == 'darwin':
show_console = True
data_to_copy = [
(os.path.join(src_dir, "tribler", "core"), 'tribler_source/tribler/core'),
(os.path.join(src_dir, "tribler", "ui", "public"), 'tribler_source/tribler/ui/public'),
(os.path.join(src_dir, "tribler", "ui", "dist"), 'tribler_source/tribler/ui/dist'),
(os.path.join(root_dir, "build", "win", "resources"), 'tribler_source/resources'),
(os.path.dirname(aiohttp_apispec.__file__), 'aiohttp_apispec')
]
# Importing lib2to3 as hidden import does not import all the necessary files for some reason so had to import as data.
try:
lib2to3_dir = imp.find_module('lib2to3')[1]
data_to_copy += [(lib2to3_dir, 'lib2to3')]
except ImportError:
pass
if sys.platform.startswith('darwin'):
# Create the right version info in the Info.plist file
with open('build/mac/resources/Info.plist', 'r') as f:
content = f.read()
content = content.replace('__VERSION__', version_str)
os.unlink('build/mac/resources/Info.plist')
with open('build/mac/resources/Info.plist', 'w') as f:
f.write(content)
# Embed the "Noto Color Emoji" font on Linux
ttf_path = os.path.join("/usr", "share", "fonts", "truetype", "noto", "NotoColorEmoji.ttf")
if sys.platform.startswith('linux') and os.path.exists(ttf_path):
data_to_copy += [(ttf_path, 'fonts')]
excluded_libs = ['wx', 'PyQt4', 'FixTk', 'tcl', 'tk', '_tkinter', 'tkinter', 'Tkinter', 'matplotlib']
# Pony dependencies; each packages need to be added separatedly; added as hidden import
pony_deps = ['pony', 'pony.orm', 'pony.orm.dbproviders', 'pony.orm.dbproviders.sqlite']
# Hidden imports
hiddenimports = [
'csv',
'dataclasses', # https://github.com/pyinstaller/pyinstaller/issues/5432
'ecdsa',
'ipv8',
'PIL',
'pkg_resources',
# 'pkg_resources.py2_warn', # Workaround PyInstaller & SetupTools, https://github.com/pypa/setuptools/issues/1963
'pyaes',
'pydantic',
'requests',
'scrypt', '_scrypt',
'sqlalchemy', 'sqlalchemy.ext.baked', 'sqlalchemy.ext.declarative',
'tribler.core.logger.logger_streams',
'typing_extensions',
]
hiddenimports += pony_deps
hiddenimports += [x for member in known_components.__dict__.values() for x in getattr(member, "hiddenimports", set())]
# Fix for issue: Could not load a pixbuf from icon theme.
# Unrecognized image file format (gdk-pixbuf-error-quark, 3).
# See: https://github.com/Tribler/tribler/issues/7457
if sys.platform.startswith('linux'):
hiddenimports += ['gi', 'gi.repository.GdkPixbuf']
# https://github.com/pyinstaller/pyinstaller/issues/5359
hiddenimports += collect_submodules('pydantic')
sys.modules['FixTk'] = None
a = Analysis(['src/run_tribler.py'],
pathex=[''],
binaries=None,
datas=data_to_copy,
hiddenimports=hiddenimports,
hookspath=[],
runtime_hooks=[],
excludes=excluded_libs,
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
# Add libsodium.dylib on OS X
if sys.platform == 'darwin':
a.binaries = a.binaries - TOC([('/usr/local/lib/libsodium.so', None, None), ])
a.binaries = a.binaries + TOC([('libsodium.dylib', '/usr/local/lib/libsodium.dylib', None), ])
exe = EXE(pyz,
a.scripts,
exclude_binaries=True,
name='tribler',
debug=False,
strip=False,
upx=True,
console=show_console,
icon='build/win/resources/tribler.ico')
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
name='tribler')
app = BUNDLE(coll,
name='Tribler.app',
icon='build/mac/resources/tribler.icns',
bundle_identifier='nl.tudelft.tribler',
info_plist={'CFBundleName': 'Tribler', 'CFBundleDisplayName': 'Tribler', 'NSHighResolutionCapable': 'True',
'CFBundleInfoDictionaryVersion': 1.0, 'CFBundleVersion': version_str,
'CFBundleShortVersionString': version_str},
console=show_console)
# Replace the Info.plist file on MacOS
if sys.platform == 'darwin':
shutil.copy('build/mac/resources/Info.plist', 'dist/Tribler.app/Contents/Info.plist')