Add command-line options to pyinstaller.py for automated building, finish pyqt5 multimedia sound, fix incorrect arguments in pyinstaller.py+setup.py

This commit is contained in:
Dpeta 2022-10-08 14:30:56 +02:00
parent a51e4dd69e
commit fc08a442fa
4 changed files with 162 additions and 83 deletions

View file

@ -2321,7 +2321,9 @@ class PesterWindow(MovingWindow):
self.namesound = soundclass("themes/namealarm.wav")
self.ceasesound = soundclass(self.theme["main/sounds/ceasesound"])
self.honksound = soundclass("themes/honk.wav")
elif "PyQt6.QtMultimedia" in sys.modules:
if ("PyQt6.QtMultimedia" in sys.modules) or (
"PyQt5.QtMultimedia" in sys.modules
):
if soundclass == QtMultimedia.QSoundEffect:
self.alarm = soundclass()
self.memosound = soundclass()
@ -2367,7 +2369,9 @@ class PesterWindow(MovingWindow):
if "pygame" in sys.modules:
if self.sound_type == pygame.mixer.Sound:
sound.set_volume(vol)
if "PyQt6.QtMultimedia" in sys.modules:
if ("PyQt6.QtMultimedia" in sys.modules) or (
"PyQt5.QtMultimedia" in sys.modules
):
if self.sound_type == QtMultimedia.QSoundEffect:
sound.setVolume(vol)
except Exception as err:

View file

@ -1,6 +1,8 @@
#!/usr/bin/env python3
import os
import sys
import shutil
import argparse
import PyInstaller.__main__
@ -49,7 +51,7 @@ upx_exclude = [
"Qt6Gui.dll",
"vcruntime140.dll",
"MSVCP140.dll",
"MSVCP140_1.dll" "api-ms-win-core-console-l1-1-0.dll",
"MSVCP140_1.dll",
"api-ms-win-core-console-l1-1-0.dll",
"api-ms-win-core-console-l1-2-0.dll",
"api-ms-win-core-datetime-l1-1-0.dll",
@ -100,21 +102,77 @@ upx_enabled = ""
package_universal_crt = ""
onefile = ""
windowed = ""
upx_dir = ""
try:
print("This is a script to make building with Pyinstaller a bit more conventient.")
# Command line options
parser = argparse.ArgumentParser()
parser.add_argument(
"--prompts",
help="Prompt for the options below on run",
action=argparse.BooleanOptionalAction,
)
parser.add_argument(
"--onefile",
help="Create a one-file bundled executable.",
action=argparse.BooleanOptionalAction,
)
parser.add_argument(
"--upx",
help="Try to compress binaries with UPX.",
action=argparse.BooleanOptionalAction,
)
parser.add_argument(
"--crt",
help="Try to bundle Universal CRT with the build",
action=argparse.BooleanOptionalAction,
)
parser.add_argument(
"--clean",
help="Remove build+dist directories with shutil before building.",
action=argparse.BooleanOptionalAction,
)
parser.add_argument(
"--windowed",
help="Build without console.",
action=argparse.BooleanOptionalAction,
)
_ARGUMENTS = parser.parse_args()
if _ARGUMENTS.clean == True:
delete_builddist = "y"
elif _ARGUMENTS.clean == False:
delete_builddist = "n"
if _ARGUMENTS.upx == True:
upx_enabled = "y"
elif _ARGUMENTS.upx == False:
upx_enabled = "n"
if _ARGUMENTS.crt == True:
package_universal_crt = "y"
elif _ARGUMENTS.crt == False:
package_universal_crt = "n"
if _ARGUMENTS.onefile == True:
onefile = "y"
elif _ARGUMENTS.onefile == False:
onefile = "n"
if _ARGUMENTS.windowed == True:
windowed = "y"
elif _ARGUMENTS.windowed == False:
windowed = "n"
parser.print_usage()
if _ARGUMENTS.prompts != False:
try:
print(
"This is a script to make building with Pyinstaller a bit more conventient."
)
while (delete_builddist != "y") and (delete_builddist != "n"):
delete_builddist = input("Delete build & dist folders? (Y/N): ").lower()
if delete_builddist == "y":
try:
shutil.rmtree("dist")
except FileNotFoundError as e:
print(e)
try:
shutil.rmtree("build")
except FileNotFoundError as e:
print(e)
while (upx_enabled != "y") and (upx_enabled != "n"):
upx_enabled = input("Enable UPX? (Y/N): ").lower()
@ -182,8 +240,30 @@ try:
while (onefile != "y") and (onefile != "n"):
onefile = input("Build with '--onefile'? (Y/N): ").lower()
except KeyboardInterrupt:
except KeyboardInterrupt:
sys.exit("KeyboardInterrupt")
else:
# no-prompt was given
if _ARGUMENTS.clean == None:
delete_builddist = "n"
if _ARGUMENTS.upx == None:
upx_enabled = "n"
if _ARGUMENTS.crt == None:
package_universal_crt = "y"
if _ARGUMENTS.onefile == None:
onefile = "y"
if _ARGUMENTS.windowed == None:
windowed = "y"
if delete_builddist == "y":
try:
shutil.rmtree("dist")
except FileNotFoundError as e:
print(e)
try:
shutil.rmtree("build")
except FileNotFoundError as e:
print(e)
# Windows
if sys.platform == "win32":
@ -221,9 +301,6 @@ if sys.platform == "win32":
run_win32.append('--paths="%s"' % crt_path)
if os.path.exists(crt_path):
if is_64bit == False:
run_win32.append(
"--add-binary=%s\\api-ms-win-core-console-l1-1-0.dll;." % crt_path
)
run_win32.append(
"--add-binary=%s\\api-ms-win-core-console-l1-1-0.dll;." % crt_path
)
@ -627,7 +704,8 @@ else:
run_generic = [
"pesterchum.py",
"--name=Pesterchum" "--clean", # Clear cache
"--name=Pesterchum",
"--clean", # Clear cache
]
if upx_enabled == "y":

View file

@ -69,9 +69,6 @@ build_exe_options = {
"PyQt6.QtAssistant",
"PyQt6.QtDesigner",
"PyQt6.QAxContainer",
"pygame.docs" # Hopefully we can just not have pygame at all at some point =3
# (when QtMultimedia stops relying on local codecs </3)
"pygame.examples",
"pygame.tests",
"pydoc_data",
],