-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpackage.py
67 lines (57 loc) · 2.22 KB
/
package.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
import PyInstaller.__main__
import os
import shutil
import platform
import contextlib
from src.hide_it.__about__ import (
__version__,
__title__,
)
project_name = __title__
approot = os.path.dirname(os.path.abspath(__file__))
src_dir = os.path.join(approot, 'src')
build_dir = os.path.join(approot, 'build')
dist_dir = os.path.join(approot, 'dist')
"""
NOTE: to understand reasons of multiple ugly builds being present instead of one,
check 7 y.o issues with pyinstaller multi-executable builds support, starting from
https://github.com/pyinstaller/pyinstaller/issues/167
"""
data = [
(os.path.join(src_dir, project_name, 'locales'), os.sep.join(['locales'])),
(os.path.join(src_dir, project_name, 'assets'), os.sep.join(['assets'])),
]
data_zipped = [ ('--add-data', os.pathsep.join(entry)) for entry in data ] # https://pyinstaller.readthedocs.io/en/stable/spec-files.html#adding-data-files
data_flat = [ item for sublist in data_zipped for item in sublist ]
builds = [
{
'entry': os.path.join(src_dir, project_name, '__main__.py'),
'name': project_name,
'data': data_flat,
'console': '--noconsole',
'icon': os.path.join(src_dir, project_name, 'assets', '%s.ico' % project_name),
}
]
for build in builds:
arguments = [
build['entry'],
'--name', build['name'],
build['console'],
'--onedir',
'--distpath', dist_dir,
'--clean',
'--noconfirm',
'--icon', build['icon']
]
if 'data' in build: arguments += build['data']
PyInstaller.__main__.run(arguments)
artifact_dir = os.path.join(approot, 'artifacts')
archive_name = '_'.join([build['name'], platform.system(), __version__]).lower()
archive_file = '%s.zip' % archive_name
archive_path = os.path.join(artifact_dir, archive_file)
archive_path_temp = os.path.join(approot, archive_file)
if not os.path.exists(artifact_dir): os.mkdir(artifact_dir)
if os.path.exists(archive_path): os.remove(archive_path)
if os.path.exists(archive_path_temp): os.remove(archive_path_temp)
shutil.make_archive(archive_name, 'zip', os.path.join(dist_dir, build['name']))
shutil.move(os.path.join(approot, archive_file), artifact_dir)