From c89c244cb03e7f8906602633f78daf30c41477cb Mon Sep 17 00:00:00 2001 From: Sander Land <48946947+sanderland@users.noreply.github.com> Date: Thu, 12 Jun 2025 10:44:41 +0200 Subject: [PATCH] patch dmg --- spec/KaTrain.spec | 9 ++++++++ spec/hook-kivymd.py | 55 +++++++++++++++++++++++++++++++++++++++++++++ test_katrain.spec | 51 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 spec/hook-kivymd.py create mode 100644 test_katrain.spec diff --git a/spec/KaTrain.spec b/spec/KaTrain.spec index 0a0c16e..084268e 100644 --- a/spec/KaTrain.spec +++ b/spec/KaTrain.spec @@ -53,6 +53,8 @@ datas = [ (f"{base_path}/KataGo", "katrain/KataGo"), ] +# KivyMD data files will be handled by the custom hook + # Platform-specific binaries binaries = kivy_deps.get('binaries', []) if is_macos: @@ -71,11 +73,18 @@ if is_windows: # Platform-specific hooks and excludes hookspath = kivy_deps.get('hookspath', []) hookspath.append(kivymd_hooks_path) +# Add custom KivyMD hook directory +hookspath.append(SPECPATH) +# Exclude problematic modules excludes = kivy_deps.get('excludes', []) + ["scipy", "pandas", "numpy", "matplotlib", "docutils"] if is_windows: excludes.append("mkl") +# Fix SDL2 conflicts on macOS by excluding ffpyplayer +if is_macos: + excludes.extend(["ffpyplayer", "pygame"]) + # Entry point - relative to spec file location entry_point = f"{base_path}/__main__.py" diff --git a/spec/hook-kivymd.py b/spec/hook-kivymd.py new file mode 100644 index 0000000..b0009b3 --- /dev/null +++ b/spec/hook-kivymd.py @@ -0,0 +1,55 @@ +from PyInstaller.utils.hooks import collect_data_files, get_package_paths +import os + +# Collect all KivyMD data files +datas = collect_data_files('kivymd') + +# Add specific KivyMD paths +kivymd_path = get_package_paths('kivymd')[1] + +# Ensure KivyMD directories are included +kivymd_data_dirs = ['fonts', 'images', 'uix'] +for data_dir in kivymd_data_dirs: + dir_path = os.path.join(kivymd_path, data_dir) + if os.path.exists(dir_path): + datas.append((dir_path, f'kivymd/{data_dir}')) + +# Create missing .kv files for KivyMD components +# This is a workaround for KivyMD 1.2.0 missing .kv files +missing_kv_files = { + 'kivymd/uix/label/label.kv': ''' +: + disabled_color: self.theme_cls.disabled_hint_text_color + text_size: self.size +''', + 'kivymd/uix/button/button.kv': ''' +: + disabled_color: self.theme_cls.disabled_hint_text_color +''', + 'kivymd/uix/textfield/textfield.kv': ''' +: + disabled_color: self.theme_cls.disabled_hint_text_color +''', +} + +# Add the missing .kv files to datas +import tempfile +import shutil + +temp_dir = tempfile.mkdtemp() +for kv_path, kv_content in missing_kv_files.items(): + full_temp_path = os.path.join(temp_dir, kv_path) + os.makedirs(os.path.dirname(full_temp_path), exist_ok=True) + with open(full_temp_path, 'w') as f: + f.write(kv_content) + datas.append((full_temp_path, kv_path)) + +# Hidden imports for KivyMD +hiddenimports = [ + 'kivymd.icon_definitions', + 'kivymd.font_definitions', + 'kivymd.color_definitions', + 'kivymd.uix.label.label', + 'kivymd.uix.button.button', + 'kivymd.uix.textfield.textfield', +] \ No newline at end of file diff --git a/test_katrain.spec b/test_katrain.spec new file mode 100644 index 0000000..05a13da --- /dev/null +++ b/test_katrain.spec @@ -0,0 +1,51 @@ +# -*- mode: python ; coding: utf-8 -*- +from PyInstaller.utils.hooks import collect_all + +datas = [] +binaries = [] +hiddenimports = [] +tmp_ret = collect_all('kivymd') +datas += tmp_ret[0]; binaries += tmp_ret[1]; hiddenimports += tmp_ret[2] + + +a = Analysis( + ['katrain/__main__.py'], + pathex=[], + binaries=binaries, + datas=datas, + hiddenimports=hiddenimports, + hookspath=[], + hooksconfig={}, + runtime_hooks=[], + excludes=['ffpyplayer', 'pygame'], + noarchive=False, + optimize=0, +) +pyz = PYZ(a.pure) + +exe = EXE( + pyz, + a.scripts, + [], + exclude_binaries=True, + name='test_katrain', + debug=False, + bootloader_ignore_signals=False, + strip=False, + upx=True, + console=True, + disable_windowed_traceback=False, + argv_emulation=False, + target_arch=None, + codesign_identity=None, + entitlements_file=None, +) +coll = COLLECT( + exe, + a.binaries, + a.datas, + strip=False, + upx=True, + upx_exclude=[], + name='test_katrain', +)