ci: add optimized build scripts using Nuitka

This commit is contained in:
BuildTools 2024-08-12 20:59:01 -07:00
parent ac725c678b
commit a8ed4a87b1
No known key found for this signature in database
GPG Key ID: 3270C066C15D530B
5 changed files with 37 additions and 4 deletions

4
.gitignore vendored
View File

@ -24,12 +24,14 @@ src/*
docs/*
!docs/*.py
# Allow assets folder, but only .svg, .png, and .ico files
# Allow assets folder, but only .svg, .png, .rc and .ico files
!assets/
assets/*
!assets/*.svg
!assets/*.png
!assets/*.ico
!assets/*.rc
!assets/*.res
# Allow .github folder and its contents
!.github/

BIN
assets/icon.RES Normal file

Binary file not shown.

1
assets/icon.rc Normal file
View File

@ -0,0 +1 @@
IDI_ICON1 ICON "favicon.ico"

26
build_fast.bat Normal file
View File

@ -0,0 +1,26 @@
@echo off
if "%1"=="" (
echo Usage: build_fast.bat [RELEASE^|DEV]
exit /b 1
)
set COMMON_FLAGS=--standalone --enable-plugin=pyside6 --include-data-dir=assets=assets
if /I "%1"=="RELEASE" (
echo Building RELEASE version...
python -m nuitka %COMMON_FLAGS% --windows-console-mode=disable --output-dir=build\release src\main.py --lto=yes
) else if /I "%1"=="DEV" (
echo Building DEV version...
python -m nuitka %COMMON_FLAGS% --output-dir=build\dev src\main.py
) else (
echo Invalid argument. Use RELEASE or DEV.
exit /b 1
)
if errorlevel 1 (
echo Build failed.
exit /b 1
) else (
echo Build completed successfully.
)

View File

@ -57,10 +57,14 @@ def open_file_safe(file_path, mode="r"):
def resource_path(relative_path):
try:
# PyInstaller creates a temp folder and stores path in _MEIPASS
if hasattr(sys, "_MEIPASS"):
# PyInstaller path
base_path = sys._MEIPASS
except Exception:
elif "__compiled__" in globals():
# Nuitka path
base_path = os.path.dirname(sys.executable)
else:
# Regular Python path
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)