-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.py
67 lines (57 loc) · 1.83 KB
/
build.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 os
import subprocess
import sys
import shutil
import venv
from src.constants import *
# Define paths and script name
script_name = MAINSCRIPTPATH
icon_path = os.path.join(DATAFILESPATH, 'pyDatalink_icon.ico')
output_directory = PROJECTPATH
requirements_file = 'requirements.txt'
spec_file = APPNAME + '.spec'
venv_dir = 'venv'
print('Create a virtual environment')
venv.create(venv_dir, with_pip=True)
print('Activate virtual environment')
if sys.platform == 'win32' :
activate_script = os.path.join(venv_dir, 'Scripts', 'activate')
venv_exe_path = os.path.join(venv_dir, 'Scripts')
else :
activate_script = os.path.join(venv_dir, 'bin', 'activate')
venv_exe_path = os.path.join(venv_dir, 'bin')
print('Install required python packages')
subprocess.run([f'{venv_exe_path}/python', '-m', 'pip', 'install', '-r', requirements_file])
print('Create the executable')
pyinstaller_command = [
f'{venv_exe_path}/pyinstaller',
'--name=' + APPNAME,
'--onefile',
'--icon=' + icon_path,
'--distpath=' + output_directory,
'--clean',
'--noconfirm',
'--noconsole',
'--add-data=' + DATAFILESPATH +';data',
script_name
]
try :
status = subprocess.run(pyinstaller_command)
finally :
if os.path.exists('build'):
shutil.rmtree('build')
if os.path.exists(spec_file):
os.remove(spec_file)
if sys.platform == 'win32':
deactivate_script = os.path.join(venv_dir, 'Scripts', 'deactivate.bat')
else:
deactivate_script = os.path.join(venv_dir, 'bin', 'deactivate')
subprocess.run(deactivate_script, shell=True)
shutil.rmtree(venv_dir)
try :
if status.returncode == 0 :
print('Build completed successfully!')
else :
print('Error while building the project')
except :
print('Error while building the project')