-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmake.py
89 lines (81 loc) · 3.15 KB
/
make.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
import os
import platform
import PyInstaller.__main__
import pyqtgraph
try:
import hypernav
except ImportError:
hypernav = None
root = os.path.join('.', 'bundle')
data_sep = ':'
icon_ext = 'ico'
# Set parameters specific to platform
if platform.system() not in ['Windows', 'Darwin', 'Linux']:
raise ValueError(f"Platform {platform.system()} not supported.")
os_specific_args = []
if platform.system() == 'Windows':
data_sep = ';'
# Windows 7 specific
# os_specific_args = ('--add-data=%s%s%s' % (os.path.join(PATH_TO_SITE_PACKAGES, 'kaleido', 'executable', '*'),
# OS_OPERATOR, os.path.join('kaleido', 'executable')),)
elif platform.system() == 'Darwin':
icon_ext = 'icns'
os_specific_args = [
# '--target-arch=universal2', # Fails on GitHub but bundle works on both architecture
# Required for code signing
'--osx-bundle-identifier=com.umaine.sms.inlinino'
# f'--codesign-identity={os.getenv("CODESIGN_HASH")}',
# f'--osx-entitlements-file={os.path.join("Bundled", "entitlements.plist")}',
]
# Get version number (without importing file)
version = None
with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'inlinino', '__init__.py'), 'r') as f:
for l in f:
if l.startswith('__version__'):
version = l.split('=')[1].strip(" \n'")
break
# Include all data files
add_data = []
ls = [
('README.md', '.'),
('LICENSE', '.'),
(os.path.join('inlinino', 'inlinino_cfg.json'), '.'),
(os.path.join('inlinino', 'resources'), 'resources'),
(os.path.join('inlinino', 'cfg', '*'), 'cfg'),
(os.path.join(os.path.dirname(pyqtgraph.__file__), 'icons', '*.png'), os.path.join('pyqtgraph', 'icons')),
(os.path.join(os.path.dirname(pyqtgraph.__file__), 'icons', '*.svg'), os.path.join('pyqtgraph', 'icons')),
]
if hypernav is not None:
ls.extend([
(os.path.join(os.path.dirname(hypernav.__file__), 'bin', '*.exe'), os.path.join('hypernav', 'bin')),
(os.path.join(os.path.dirname(hypernav.__file__), 'calibrate', 'templates', '*.txt'),
os.path.join('hypernav', 'calibrate', 'templates'))
])
for item, dest in ls:
add_data.append(f'--add-data={os.path.abspath(item)}{data_sep}{dest}')
# Require absolute path for GitHub workflow as data can be on different drive and relpath won't work.
# Include hidden imports
hidden_imports = []
for i in [
'pyqtgraph.graphicsItems.ViewBox.axisCtrlTemplate_pyqt5',
'pyqtgraph.graphicsItems.PlotItem.plotConfigTemplate_pyqt5',
'pyqtgraph.imageview.ImageViewTemplate_pyqt5',
]:
hidden_imports.append(f'--hidden-import={i}')
# Bundle application
PyInstaller.__main__.run([
f'--name=Inlinino-v{version}-{platform.system()}',
f"--icon={os.path.relpath(os.path.join('inlinino', 'resources', f'inlinino.{icon_ext}'), root)}",
f'--distpath={os.path.join(root, "dist")}',
f'--workpath={os.path.join(root, "build")}',
f'--specpath={root}',
'--windowed',
'--noconfirm',
# '--log-level=DEBUG',
# '--clean',
# '--debug=imports',
*add_data,
*hidden_imports,
*os_specific_args,
os.path.join('inlinino', '__main__.py')
])