+ добавлено подсвечивание предупреждений и ошибок в таблице выбранных переменных
97 lines
3.2 KiB
Python
97 lines
3.2 KiB
Python
import subprocess
|
||
import shutil
|
||
import os
|
||
from pathlib import Path
|
||
from PIL import Image # нужна библиотека Pillow для конвертации PNG в ICO
|
||
import PySide2
|
||
from PyInstaller.utils.hooks import collect_data_files
|
||
|
||
# === Конфигурация ===
|
||
USE_NUITKA = True # True — сборка через Nuitka, False — через PyInstaller
|
||
SRC_PATH = Path("./Src/")
|
||
SCRIPT_PATH = SRC_PATH / "DebugVarEdit_GUI.py"
|
||
OUTPUT_NAME = "DebugVarEdit"
|
||
|
||
DIST_PATH = Path("./").resolve()
|
||
WORK_PATH = Path("./build_temp").resolve()
|
||
SPEC_PATH = WORK_PATH
|
||
SCRIPT_DIR = SRC_PATH
|
||
ICON_PATH = SRC_PATH / "icon.png"
|
||
ICON_ICO_PATH = SRC_PATH / "icon.ico"
|
||
|
||
# === Пути к DLL и прочим зависимостям ===
|
||
LIBS = {
|
||
"libclang.dll": SCRIPT_DIR / "libclang.dll"
|
||
}
|
||
|
||
# === PySide2 плагины ===
|
||
PySide2_path = Path(PySide2.__file__).parent
|
||
datas = []
|
||
datas += collect_data_files('PySide2', includes=['plugins/platforms/*'])
|
||
datas += collect_data_files('PySide2', includes=['plugins/styles/*'])
|
||
datas += collect_data_files('PySide2', includes=['plugins/imageformats/*'])
|
||
|
||
add_data_list = [f"{src};{dest}" for src, dest in datas]
|
||
|
||
# Проверка наличия DLL и добавление
|
||
add_binary_list = []
|
||
for name, path in LIBS.items():
|
||
if path.exists():
|
||
add_binary_list.append(f"{str(path)};{name}")
|
||
else:
|
||
print(f"WARNING: {path.name} не найден — он не будет включён в сборку")
|
||
|
||
def clean_temp():
|
||
for folder in ["build_temp", "__pycache__", "DebugVarEdit_GUI.build", "DebugVarEdit_GUI.dist", "DebugVarEdit_GUI.onefile-build"]:
|
||
path = Path(folder)
|
||
if path.exists():
|
||
shutil.rmtree(path, ignore_errors=True)
|
||
|
||
if USE_NUITKA:
|
||
# Формируем include-data-file только для DLL
|
||
include_data_files = [f"--include-data-file={str(path)}={name}" for name, path in LIBS.items() if path.exists()]
|
||
|
||
cmd = [
|
||
"python", "-m", "nuitka",
|
||
"--standalone",
|
||
"--onefile",
|
||
"--enable-plugin=pyside2",
|
||
"--windows-console-mode=disable",
|
||
f"--output-dir={DIST_PATH}",
|
||
f"--output-filename={OUTPUT_NAME}.exe",
|
||
f"--windows-icon-from-ico={ICON_ICO_PATH}",
|
||
*include_data_files,
|
||
str(SCRIPT_PATH)
|
||
]
|
||
else:
|
||
# PyInstaller
|
||
cmd = [
|
||
"pyinstaller",
|
||
"--name", OUTPUT_NAME,
|
||
"--distpath", str(DIST_PATH),
|
||
"--workpath", str(WORK_PATH),
|
||
"--specpath", str(SPEC_PATH),
|
||
"--windowed",
|
||
f"--icon={ICON_ICO_PATH}",
|
||
"--hidden-import=PySide2.QtWidgets",
|
||
"--hidden-import=PySide2.QtGui",
|
||
"--hidden-import=PySide2.QtCore",
|
||
*[arg for b in add_binary_list for arg in ("--add-binary", b)],
|
||
*[arg for d in add_data_list for arg in ("--add-data", d)],
|
||
str(SCRIPT_PATH)
|
||
]
|
||
|
||
# === Запуск сборки ===
|
||
print("Выполняется сборка с помощью " + ("Nuitka" if USE_NUITKA else "PyInstaller"))
|
||
print(" ".join(cmd))
|
||
|
||
try:
|
||
subprocess.run(cmd, check=True)
|
||
print("\nСборка успешно завершена!")
|
||
|
||
# Удаление временных папок после сборки
|
||
clean_temp()
|
||
|
||
except subprocess.CalledProcessError:
|
||
print("\nОшибка при сборке.")
|