Add simple manual configuration options to the build spec

This commit is contained in:
DevilXD committed 2025-09-12 14:03:07 +02:00
1 parent b029428cb3
commit 05d97321ea
1 file changed
+50 -33
+50 -33
View File
@@ -5,7 +5,9 @@ import sys
import platform import platform
import fnmatch import fnmatch
from pathlib import Path from pathlib import Path
from typing import Any, TYPE_CHECKING from collections import abc
from traceback import format_exc
from typing import Any, TypeAlias, TYPE_CHECKING
SELF_PATH = str(Path(".").resolve()) SELF_PATH = str(Path(".").resolve())
if SELF_PATH not in sys.path: if SELF_PATH not in sys.path:
@@ -14,8 +16,22 @@ if SELF_PATH not in sys.path:
from constants import WORKING_DIR, SITE_PACKAGES_PATH, DEFAULT_LANG from constants import WORKING_DIR, SITE_PACKAGES_PATH, DEFAULT_LANG
if TYPE_CHECKING: if TYPE_CHECKING:
from PyInstaller.building.api import PYZ, EXE from PyInstaller.building.splash import Splash
from PyInstaller.building.build_main import Analysis from PyInstaller.building.build_main import Analysis
from PyInstaller.building.datastruct import _TOCTuple
from PyInstaller.building.api import PYZ, EXE, COLLECT
PYZTypeCOLLECT: TypeAlias = "abc.Iterable[_TOCTuple] | PYZ"
PYZTypeEXE: TypeAlias = "abc.Iterable[_TOCTuple] | PYZ | Splash"
# Simple configuration
upx: bool = False # Use UPX compression (reduces file size, may increase AV detections)
console: bool = False # True if you'd want to add a console window (useful for debugging)
one_dir: bool = False # True for one-dir, False for one-file
optimize: int | None = None # -1/None/0=none, 1=remove asserts, 2=also remove docstrings
app_name: str = "Twitch Drops Miner (by DevilXD)"
# (source_path, dest_path, required) # (source_path, dest_path, required)
@@ -75,21 +91,12 @@ if sys.platform == "linux":
} }
} }
block_cipher = None
a = Analysis( a = Analysis(
["main.py"], ["main.py"],
pathex=[],
datas=datas, datas=datas,
excludes=[],
hookspath=[],
noarchive=False,
runtime_hooks=[],
binaries=binaries, binaries=binaries,
cipher=block_cipher,
hooksconfig=hooksconfig, hooksconfig=hooksconfig,
hiddenimports=hiddenimports, hiddenimports=hiddenimports,
win_private_assemblies=False,
win_no_prefer_redirects=False,
) )
# Exclude unneeded Linux libraries (supports globbing) # Exclude unneeded Linux libraries (supports globbing)
@@ -102,26 +109,36 @@ a.binaries = [
b for b in a.binaries b for b in a.binaries
if not any(fnmatch.fnmatch(b[0], pattern) for pattern in excluded_binaries) if not any(fnmatch.fnmatch(b[0], pattern) for pattern in excluded_binaries)
] ]
if one_dir:
exe_args: PYZTypeEXE = tuple()
collect_args: PYZTypeCOLLECT = (a.datas, a.binaries)
else:
exe_args = (a.datas, a.binaries)
collect_args = tuple()
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher) pyz = PYZ(a.pure)
exe = EXE( try:
pyz, exe = EXE(
a.scripts, pyz,
a.binaries, a.scripts,
a.zipfiles, *exe_args,
a.datas, upx=upx,
[], debug=False,
upx=True, name=app_name,
debug=False, console=console,
strip=False, optimize=optimize,
console=False, exclude_binaries=one_dir,
upx_exclude=[], icon="icons/pickaxe.ico",
target_arch=None, )
runtime_tmpdir=None, except PermissionError as exc:
codesign_identity=None, exc_text: str = format_exc()
entitlements_file=None, if any(t in exc_text for t in ("os.remove", "os.unlink")):
icon="icons/pickaxe.ico", raise PermissionError("Ensure the executable isn't running when rebuilding.") from exc
bootloader_ignore_signals=False, raise
disable_windowed_traceback=False, if one_dir:
name="Twitch Drops Miner (by DevilXD)", coll = COLLECT(
) exe,
*collect_args,
upx=upx,
name=app_name,
)