Skip to content

Commit a6d8a8a

Browse files
Watanabehatoclaude
andauthored
fix(SoundDodge): PEP 562 延迟加载 + CI 预装 patched soundcard (#207)
* fix(SoundDodge): PEP 562 延迟加载 + CI 预装 patched soundcard - __init__.py: 用 __getattr__ 延迟导入 Ear/Dodger,避免 import custom 时 module-level import soundcard 触发 cffi.dlopen('ole32') 崩溃 - install.yml: CI 打包时将 soundcard 预装进 embedded Python 并 patch mediafoundation.py 中 ole32 → ole32.dll,从源头修复 find_library 问题 * fix(ci): soundcard patch 前校验目标字符串存在,防止静默回归 replace() 找不到目标时静默成功,若 soundcard 未来改动 mediafoundation.py 则 ole32 崩溃会悄悄回来。加显式检查让 CI 硬失败。 * chore(SoundTrigger): remove blank lines inside if blocks for Black compliance Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * fix(ci): use heredoc for soundcard patch to fix YAML indentation Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 5d1a21a commit a6d8a8a

2 files changed

Lines changed: 36 additions & 3 deletions

File tree

.github/workflows/install.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,32 @@ jobs:
166166
cp -rpvn install/deps/. install-mxu/deps/
167167
fi
168168
169+
- name: Install and patch soundcard
170+
shell: bash
171+
run: |
172+
echo "Installing soundcard into embedded Python..."
173+
./install-mxu/python/python.exe -m pip install \
174+
--no-index \
175+
--find-links install-mxu/deps \
176+
soundcard
177+
178+
echo "Patching soundcard ole32 → ole32.dll..."
179+
./install-mxu/python/python.exe - << 'PYEOF'
180+
import sys, soundcard
181+
from pathlib import Path
182+
p = Path(soundcard.__path__[0]) / 'mediafoundation.py'
183+
c = p.read_text()
184+
if "_ffi.dlopen('ole32')" not in c:
185+
print(f'ERROR: expected ole32 patch target not found in {p}. soundcard may have changed.')
186+
sys.exit(1)
187+
c = c.replace("_ffi.dlopen('ole32')", "_ffi.dlopen('ole32.dll')")
188+
p.write_text(c)
189+
print('Patched:', p)
190+
PYEOF
191+
192+
echo "Removing soundcard wheel from deps to prevent re-install..."
193+
rm -f install-mxu/deps/soundcard-*.whl
194+
169195
- name: Copy MXU files to MXU version
170196
shell: bash
171197
run: |
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
from .SoundListener import Ear
2-
from .DodgeCounterTrigger import Dodger
3-
41
__all__ = ["Ear", "Dodger"]
2+
3+
4+
def __getattr__(name: str):
5+
if name == "Ear":
6+
from .SoundListener import Ear
7+
return Ear
8+
if name == "Dodger":
9+
from .DodgeCounterTrigger import Dodger
10+
return Dodger
11+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")

0 commit comments

Comments
 (0)