/
pyinstaller.spec
96 lines (80 loc) · 2.8 KB
/
pyinstaller.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
#!/usr/bin/env python3
#
# Copyright (C) 2018 Zubax Robotics OU
#
# This file is part of Kucher.
# Kucher is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
# Kucher is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along with Kucher.
# If not, see <http://www.gnu.org/licenses/>.
#
# Author: Pavel Kirienko <pavel.kirienko@zubax.com>
#
#
# This is a spec file for PyInstaller.
# Docs: https://pyinstaller.readthedocs.io/en/stable/spec-files.html
#
import os
import sys
import glob
import typing
sys.path.insert(0, os.getcwd())
import kucher
try:
# noinspection PyUnresolvedReferences
sys.getwindowsversion()
RUNNING_ON_WINDOWS = True
except AttributeError:
RUNNING_ON_WINDOWS = False
name = 'Kucher'
paths = kucher.THIRDPARTY_PATH + [
'kucher',
]
# Pack up the entire source tree with the redistributed archive.
# It adds a bit of redundant data to the resulting package, but greatly simplifies maintenance and
# ensures that the layout used for development exactly reflects the environment used in production.
# The added size penalty is insignificant.
datas = [
('kucher', '.'),
]
def detect_hidden_imports() -> typing.List[str]:
"""
Makes a brute-force search for ALL python files, including third-party packages,
and transforms that into a list of Python module names that is then fed to PyInstaller.
This way we may also end up with unused stuff, but it's easier to maintain.
"""
all_sources = glob.glob('kucher/**/*.py', recursive=True)
out = set()
for s in all_sources:
module = s.replace('.py', '').replace(os.sep, '.').replace('.__init__', '')
out.add(module)
return list(out)
# noinspection PyUnresolvedReferences
a = Analysis(['zubax-kucher'],
pathex=paths,
binaries=[],
datas=datas,
hiddenimports=detect_hidden_imports(),
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=None)
# noinspection PyUnresolvedReferences
pyz = PYZ(a.pure, a.zipped_data,
cipher=None)
# noinspection PyUnresolvedReferences
exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
name=name,
debug=False,
strip=False,
upx=False,
runtime_tmpdir=None,
console=False)