Skip to content

Commit

Permalink
ci: add optimized build scripts using Nuitka
Browse files Browse the repository at this point in the history
  • Loading branch information
leafspark committed Aug 13, 2024
1 parent ac725c6 commit a8ed4a8
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
Binary file added assets/icon.RES
Binary file not shown.
1 change: 1 addition & 0 deletions assets/icon.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
IDI_ICON1 ICON "favicon.ico"
26 changes: 26 additions & 0 deletions build_fast.bat
Original file line number Diff line number Diff line change
@@ -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.
)
10 changes: 7 additions & 3 deletions src/imports_and_globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit a8ed4a8

Please sign in to comment.