-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCompile_Build_Executable_PyInstaller.py
44 lines (33 loc) · 1.77 KB
/
Compile_Build_Executable_PyInstaller.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
# Script Developer: Gabriel Mihai Sandu
# GitHub Profile: https://github.com/Gabrieliam42
import os
import shutil
import subprocess
import platform
def delete_older_directories(directory):
if os.path.exists(directory):
shutil.rmtree(directory)
print(f"Deleted directory: {directory}")
else:
print(f"Directory not found: {directory}")
def find_and_delete_dist_and_build(cwd):
delete_older_directories(os.path.join(cwd, 'dist'))
delete_older_directories(os.path.join(cwd, 'build'))
def find_and_activate_venv():
cwd = os.getcwd()
find_and_delete_dist_and_build(cwd)
for root, dirs, files in os.walk(cwd):
if 'Scripts' in dirs or 'bin' in dirs:
scripts_path = os.path.join(root, 'Scripts' if platform.system() == 'Windows' else 'bin')
required_files = {'activate.bat' if platform.system() == 'Windows' else 'activate'}
if required_files.issubset(set(os.listdir(scripts_path))):
print(f"Virtual environment found and activated at: {root}")
if platform.system() == 'Windows':
activate_command = f'cmd /k ""{os.path.join(scripts_path, "activate.bat")}" && python.exe -m pip install --upgrade pip && pyinstaller -F -c main.py"'
else:
activate_command = f'source "{os.path.join(scripts_path, "activate")}" && python3 -m pip install --upgrade pip && pyinstaller -F -c main.py'
subprocess.run(activate_command, shell=True, executable='/bin/bash' if platform.system() != 'Windows' else None)
return
print("No virtual environment found.")
if __name__ == "__main__":
find_and_activate_venv()