diff --git a/README.md b/README.md index 719c7d6..5914293 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,8 @@ git clone https://github.com/blw1138/Zordon.git pip3 install -r requirements.txt pip3 install pyinstaller pip3 install pyinstaller_versionfile -pyinstaller main.spec +pyinstaller client.spec +pyinstaller server.spec ``` ## License diff --git a/client.spec b/client.spec index 82b6a14..b71247f 100644 --- a/client.spec +++ b/client.spec @@ -1,121 +1,158 @@ # -*- mode: python ; coding: utf-8 -*- -from PyInstaller.utils.hooks import collect_all -# - get version from version file +from PyInstaller.utils.hooks import collect_all +from pathlib import Path import os import sys import platform -src_path = os.path.abspath("src") -sys.path.insert(0, src_path) -from version import APP_NAME, APP_VERSION, APP_AUTHOR -sys.path.insert(0, os.path.abspath('.')) -datas = [('resources', 'resources'), ('src/engines/blender/scripts/', 'src/engines/blender/scripts')] +# ------------------------------------------------------------ +# Project paths +# ------------------------------------------------------------ + +project_root = Path(SPECPATH).resolve() +src_dir = project_root / "src" + +# Ensure `src.*` imports work during analysis +sys.path.insert(0, str(project_root)) + +# ------------------------------------------------------------ +# Import version info +# ------------------------------------------------------------ + +from src.version import APP_NAME, APP_VERSION, APP_AUTHOR + +APP_NAME = f"{APP_NAME}-client" + +# ------------------------------------------------------------ +# PyInstaller data / imports +# ------------------------------------------------------------ + +datas = [ + ("resources", "resources"), + ("src/engines/blender/scripts", "src/engines/blender/scripts"), +] + binaries = [] -hiddenimports = ['zeroconf'] -tmp_ret = collect_all('zeroconf') -datas += tmp_ret[0]; binaries += tmp_ret[1]; hiddenimports += tmp_ret[2] +hiddenimports = ["zeroconf", "src.version"] +tmp_ret = collect_all("zeroconf") +datas += tmp_ret[0] +binaries += tmp_ret[1] +hiddenimports += tmp_ret[2] + +# ------------------------------------------------------------ +# Analysis +# ------------------------------------------------------------ a = Analysis( - ['client.py'], - pathex=[], - binaries=binaries, - datas=datas, - hiddenimports=hiddenimports, - hookspath=[], - hooksconfig={}, - runtime_hooks=[], - excludes=[], - noarchive=False, - optimize=1, # fyi: optim level 2 breaks on windows + ["client.py"], + pathex=[str(project_root)], + binaries=binaries, + datas=datas, + hiddenimports=hiddenimports, + hookspath=[], + hooksconfig={}, + runtime_hooks=[], + excludes=[], + noarchive=False, + optimize=1, # optimize=2 breaks Windows builds ) + pyz = PYZ(a.pure) -if platform.system() == 'Darwin': # macOS +# ------------------------------------------------------------ +# Platform targets +# ------------------------------------------------------------ - exe = EXE( - pyz, - a.scripts, - [], - exclude_binaries=True, - name=APP_NAME, - debug=False, - bootloader_ignore_signals=False, - strip=True, - upx=True, - console=False, - disable_windowed_traceback=False, - argv_emulation=False, - target_arch=None, - codesign_identity=None, - entitlements_file=None, - ) - app = BUNDLE( - exe, - a.binaries, - a.datas, - strip=True, - name=f'{APP_NAME}.app', - icon='resources/Server.png', - bundle_identifier=None, - version=APP_VERSION - ) +if platform.system() == "Darwin": # macOS -elif platform.system() == 'Windows': + exe = EXE( + pyz, + a.scripts, + [], + exclude_binaries=True, + name=APP_NAME, + debug=False, + bootloader_ignore_signals=False, + strip=True, + upx=True, + console=False, + disable_windowed_traceback=False, + argv_emulation=False, + target_arch=None, + codesign_identity=None, + entitlements_file=None, + ) - import pyinstaller_versionfile - import tempfile + app = BUNDLE( + exe, + a.binaries, + a.datas, + strip=True, + name=f"{APP_NAME}.app", + icon="resources/Server.png", + bundle_identifier=None, + version=APP_VERSION, + ) - version_file_path = os.path.join(tempfile.gettempdir(), 'versionfile.txt') +elif platform.system() == "Windows": - pyinstaller_versionfile.create_versionfile( - output_file=version_file_path, - version=APP_VERSION, - company_name=APP_AUTHOR, - file_description=APP_NAME, - internal_name=APP_NAME, - legal_copyright=f"© {APP_AUTHOR}", - original_filename=f"{APP_NAME}.exe", - product_name=APP_NAME - ) + import pyinstaller_versionfile + import tempfile - exe = EXE( - pyz, - a.scripts, - a.binaries, - a.datas, - [], - name=APP_NAME, - debug=False, - bootloader_ignore_signals=False, - strip=True, - upx=True, - console=False, - disable_windowed_traceback=False, - argv_emulation=False, - target_arch=None, - codesign_identity=None, - entitlements_file=None, - version=version_file_path - ) + version_file_path = os.path.join( + tempfile.gettempdir(), "versionfile.txt" + ) -else: # linux - exe = EXE( - pyz, - a.scripts, - a.binaries, - a.datas, - [], - name=APP_NAME, - debug=False, - bootloader_ignore_signals=False, - strip=True, - upx=True, - console=False, - disable_windowed_traceback=False, - argv_emulation=False, - target_arch=None, - codesign_identity=None, - entitlements_file=None - ) + pyinstaller_versionfile.create_versionfile( + output_file=version_file_path, + version=APP_VERSION, + company_name=APP_AUTHOR, + file_description=APP_NAME, + internal_name=APP_NAME, + legal_copyright=f"© {APP_AUTHOR}", + original_filename=f"{APP_NAME}.exe", + product_name=APP_NAME, + ) + + exe = EXE( + pyz, + a.scripts, + a.binaries, + a.datas, + [], + name=APP_NAME, + debug=False, + bootloader_ignore_signals=False, + strip=True, + upx=True, + console=False, + disable_windowed_traceback=False, + argv_emulation=False, + target_arch=None, + codesign_identity=None, + entitlements_file=None, + version=version_file_path, + ) + +else: # Linux + + exe = EXE( + pyz, + a.scripts, + a.binaries, + a.datas, + [], + name=APP_NAME, + debug=False, + bootloader_ignore_signals=False, + strip=True, + upx=True, + console=False, + disable_windowed_traceback=False, + argv_emulation=False, + target_arch=None, + codesign_identity=None, + entitlements_file=None, + ) \ No newline at end of file diff --git a/server.spec b/server.spec index 595138a..3d193cf 100644 --- a/server.spec +++ b/server.spec @@ -1,90 +1,158 @@ # -*- mode: python ; coding: utf-8 -*- -from PyInstaller.utils.hooks import collect_all -# - get version from version file +from PyInstaller.utils.hooks import collect_all +from pathlib import Path import os import sys import platform -sys.path.insert(0, os.path.abspath('.')) -from version import APP_NAME, APP_VERSION, APP_AUTHOR -APP_NAME = APP_NAME + " Server" -datas = [('resources', 'resources'), ('src/engines/blender/scripts/', 'src/engines/blender/scripts')] +# ------------------------------------------------------------ +# Project paths +# ------------------------------------------------------------ + +project_root = Path(SPECPATH).resolve() +src_dir = project_root / "src" + +# Ensure `src.*` imports work during analysis +sys.path.insert(0, str(project_root)) + +# ------------------------------------------------------------ +# Import version info +# ------------------------------------------------------------ + +from src.version import APP_NAME, APP_VERSION, APP_AUTHOR + +APP_NAME = f"{APP_NAME}-server" + +# ------------------------------------------------------------ +# PyInstaller data / imports +# ------------------------------------------------------------ + +datas = [ + ("resources", "resources"), + ("src/engines/blender/scripts", "src/engines/blender/scripts"), +] + binaries = [] -hiddenimports = ['zeroconf'] -tmp_ret = collect_all('zeroconf') -datas += tmp_ret[0]; binaries += tmp_ret[1]; hiddenimports += tmp_ret[2] +hiddenimports = ["zeroconf", "src.version"] +tmp_ret = collect_all("zeroconf") +datas += tmp_ret[0] +binaries += tmp_ret[1] +hiddenimports += tmp_ret[2] + +# ------------------------------------------------------------ +# Analysis +# ------------------------------------------------------------ a = Analysis( - ['server.py'], - pathex=[], - binaries=binaries, - datas=datas, - hiddenimports=hiddenimports, - hookspath=[], - hooksconfig={}, - runtime_hooks=[], - excludes=[], - noarchive=False, - optimize=1, # fyi: optim level 2 breaks on windows + ["server.py"], + pathex=[str(project_root)], + binaries=binaries, + datas=datas, + hiddenimports=hiddenimports, + hookspath=[], + hooksconfig={}, + runtime_hooks=[], + excludes=[], + noarchive=False, + optimize=1, # optimize=2 breaks Windows builds ) + pyz = PYZ(a.pure) -if platform.system() == 'Windows': +# ------------------------------------------------------------ +# Platform targets +# ------------------------------------------------------------ - import pyinstaller_versionfile - import tempfile +if platform.system() == "Darwin": # macOS - version_file_path = os.path.join(tempfile.gettempdir(), 'versionfile.txt') + exe = EXE( + pyz, + a.scripts, + [], + exclude_binaries=True, + name=APP_NAME, + debug=False, + bootloader_ignore_signals=False, + strip=True, + upx=True, + console=False, + disable_windowed_traceback=False, + argv_emulation=False, + target_arch=None, + codesign_identity=None, + entitlements_file=None, + ) - pyinstaller_versionfile.create_versionfile( - output_file=version_file_path, - version=APP_VERSION, - company_name=APP_AUTHOR, - file_description=APP_NAME, - internal_name=APP_NAME, - legal_copyright=f"© {APP_AUTHOR}", - original_filename=f"{APP_NAME}.exe", - product_name=APP_NAME - ) + app = BUNDLE( + exe, + a.binaries, + a.datas, + strip=True, + name=f"{APP_NAME}.app", + icon="resources/Server.png", + bundle_identifier=None, + version=APP_VERSION, + ) - exe = EXE( - pyz, - a.scripts, - a.binaries, - a.datas, - [], - name=APP_NAME, - debug=False, - bootloader_ignore_signals=False, - strip=True, - upx=True, - console=True, - disable_windowed_traceback=False, - argv_emulation=False, - target_arch=None, - codesign_identity=None, - entitlements_file=None, - version=version_file_path - ) +elif platform.system() == "Windows": -else: # linux / macOS - exe = EXE( - pyz, - a.scripts, - a.binaries, - a.datas, - [], - name=APP_NAME, - debug=False, - bootloader_ignore_signals=False, - strip=True, - upx=True, - console=False, - disable_windowed_traceback=False, - argv_emulation=False, - target_arch=None, - codesign_identity=None, - entitlements_file=None - ) + import pyinstaller_versionfile + import tempfile + + version_file_path = os.path.join( + tempfile.gettempdir(), "versionfile.txt" + ) + + pyinstaller_versionfile.create_versionfile( + output_file=version_file_path, + version=APP_VERSION, + company_name=APP_AUTHOR, + file_description=APP_NAME, + internal_name=APP_NAME, + legal_copyright=f"© {APP_AUTHOR}", + original_filename=f"{APP_NAME}.exe", + product_name=APP_NAME, + ) + + exe = EXE( + pyz, + a.scripts, + a.binaries, + a.datas, + [], + name=APP_NAME, + debug=False, + bootloader_ignore_signals=False, + strip=True, + upx=True, + console=False, + disable_windowed_traceback=False, + argv_emulation=False, + target_arch=None, + codesign_identity=None, + entitlements_file=None, + version=version_file_path, + ) + +else: # Linux + + exe = EXE( + pyz, + a.scripts, + a.binaries, + a.datas, + [], + name=APP_NAME, + debug=False, + bootloader_ignore_signals=False, + strip=True, + upx=True, + console=False, + disable_windowed_traceback=False, + argv_emulation=False, + target_arch=None, + codesign_identity=None, + entitlements_file=None, + ) \ No newline at end of file