-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
90 lines (75 loc) · 3.34 KB
/
Copy pathbuild.py
File metadata and controls
90 lines (75 loc) · 3.34 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
"""
Script de compilação automatizada cross-platform do Gupy Alert.
Detecta o sistema operacional (Windows/macOS), cria um ambiente virtual isolado,
instala os pacotes necessários e empacota o app em um binário nativo (.app ou .exe)
usando o PyInstaller.
"""
import os
import sys
import subprocess
import shutil
import venv
def log(msg):
print(f"\n====== {msg} ======")
def main():
sistema = sys.platform
root_dir = os.path.dirname(os.path.abspath(__file__))
os.chdir(root_dir)
log(f"Sistema operacional detectado: {sistema.upper()}")
dist_dir = os.path.join(root_dir, "dist")
if os.path.exists(dist_dir):
log("Limpando diretório dist de compilação anterior...")
shutil.rmtree(dist_dir)
venv_dir = os.path.join(root_dir, ".build_venv")
if os.path.exists(venv_dir):
log("Limpando ambiente virtual de build anterior...")
shutil.rmtree(venv_dir)
log("Criando ambiente virtual isolado de compilação...")
venv.create(venv_dir, with_pip=True)
if sistema == "win32":
pip_path = os.path.join(venv_dir, "Scripts", "pip.exe")
python_path = os.path.join(venv_dir, "Scripts", "python.exe")
pyinstaller_path = os.path.join(venv_dir, "Scripts", "pyinstaller.exe")
else:
pip_path = os.path.join(venv_dir, "bin", "pip")
python_path = os.path.join(venv_dir, "bin", "python")
pyinstaller_path = os.path.join(venv_dir, "bin", "pyinstaller")
log("Instalando dependências necessárias para a build...")
try:
subprocess.run([python_path, "-m", "pip", "install", "--upgrade", "pip"], check=True)
subprocess.run([pip_path, "install", "-r", "requirements.txt"], check=True)
subprocess.run([pip_path, "install", "pyinstaller"], check=True)
except subprocess.CalledProcessError as e:
log("Erro ao instalar dependências. Certifique-se de ter acesso à internet.")
sys.exit(1)
log("Iniciando compilação do executável com PyInstaller...")
try:
subprocess.run([pyinstaller_path, "GupyAlert.spec", "--clean"], check=True)
except subprocess.CalledProcessError as e:
log("Erro na compilação do PyInstaller.")
sys.exit(1)
log("Limpando arquivos temporários de build...")
pastas_limpar = ["build", ".build_venv"]
for pasta in pastas_limpar:
caminho = os.path.join(root_dir, pasta)
if os.path.exists(caminho):
try:
shutil.rmtree(caminho)
except Exception as ex:
print(f"Aviso: Não foi possível remover a pasta temporária {pasta}: {ex}")
dist_dir = os.path.join(root_dir, "dist")
log("COMPILAÇÃO CONCLUÍDA COM SUCESSO!")
if sistema == "darwin":
app_path = os.path.join(dist_dir, "GupyAlert.app")
print(f"\n🎉 Seu aplicativo nativo do macOS foi gerado em:")
print(f"👉 {app_path}")
print("\nVocê pode abrir a pasta no Finder e arrastá-lo para seus Aplicativos.")
elif sistema == "win32":
exe_path = os.path.join(dist_dir, "GupyAlert.exe")
print(f"\n🎉 Seu executável nativo do Windows foi gerado em:")
print(f"👉 {exe_path}")
print("\nVocê já pode executá-lo diretamente com dois cliques!")
else:
print(f"\nCompilação concluída. Arquivos gerados na pasta: {dist_dir}")
if __name__ == "__main__":
main()