-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackage.py
More file actions
75 lines (64 loc) · 2.43 KB
/
package.py
File metadata and controls
75 lines (64 loc) · 2.43 KB
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
import PyInstaller.__main__
import os
import shutil
import platform
import contextlib
from src.tempgen.__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 nultiple 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
"""
gui_name = '%s_gui' % project_name
cli_name = '%s_cli' % project_name
gui_data = [
(os.path.join(src_dir, gui_name,'locales'), os.sep.join(['locales'])),
]
gui_data_zipped = [ ('--add-data', os.pathsep.join(entry)) for entry in gui_data ] # https://pyinstaller.readthedocs.io/en/stable/spec-files.html#adding-data-files
gui_data_flat = [item for sublist in gui_data_zipped for item in sublist]
builds = [
{
'entry': os.path.join(src_dir, cli_name, '__main__.py'),
'name': '%s_cli' % project_name,
'console': '--console',
'icon': os.path.join(src_dir, cli_name, 'assets', '%s.ico' % cli_name),
},
{
'entry': os.path.join(src_dir, gui_name, '__main__.py'),
'name': gui_name,
'data': gui_data_flat,
'console': '--noconsole',
'icon': os.path.join(src_dir, gui_name, 'assets', '%s.ico' % gui_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)