khh
Some checks failed
smoke-mm / Install & smoke test mm --help (push) Has been cancelled
Some checks failed
smoke-mm / Install & smoke test mm --help (push) Has been cancelled
This commit is contained in:
@@ -33,6 +33,29 @@ _LYRIC_LOG_FH: Optional[Any] = None
|
||||
_MPV_AVAILABILITY_CACHE: Optional[Tuple[bool, Optional[str]]] = None
|
||||
|
||||
|
||||
def _windows_pythonw_exe(python_exe: Optional[str]) -> Optional[str]:
|
||||
"""Return a pythonw.exe adjacent to python.exe if available (Windows only)."""
|
||||
if platform.system() != "Windows":
|
||||
return python_exe
|
||||
try:
|
||||
exe = str(python_exe or "").strip()
|
||||
except Exception:
|
||||
exe = ""
|
||||
if not exe:
|
||||
return None
|
||||
low = exe.lower()
|
||||
if low.endswith("pythonw.exe"):
|
||||
return exe
|
||||
if low.endswith("python.exe"):
|
||||
try:
|
||||
candidate = exe[:-10] + "pythonw.exe"
|
||||
if os.path.exists(candidate):
|
||||
return candidate
|
||||
except Exception:
|
||||
pass
|
||||
return exe
|
||||
|
||||
|
||||
def _windows_hidden_subprocess_kwargs() -> Dict[str, Any]:
|
||||
"""Best-effort kwargs to avoid flashing console windows on Windows.
|
||||
|
||||
@@ -413,8 +436,12 @@ class MPV:
|
||||
except Exception:
|
||||
repo_root = Path.cwd()
|
||||
|
||||
py = sys.executable
|
||||
if platform.system() == "Windows":
|
||||
py = _windows_pythonw_exe(py) or py
|
||||
|
||||
cmd: List[str] = [
|
||||
sys.executable,
|
||||
py or "python",
|
||||
"-m",
|
||||
"MPV.lyric",
|
||||
"--ipc",
|
||||
@@ -448,7 +475,18 @@ class MPV:
|
||||
# Make the current directory the repo root so `-m MPV.lyric` resolves reliably.
|
||||
kwargs["cwd"] = str(repo_root)
|
||||
if platform.system() == "Windows":
|
||||
kwargs["creationflags"] = 0x00000008 # DETACHED_PROCESS
|
||||
# Ensure we don't flash a console window when spawning the helper.
|
||||
flags = 0
|
||||
try:
|
||||
flags |= int(getattr(subprocess, "DETACHED_PROCESS", 0x00000008))
|
||||
except Exception:
|
||||
flags |= 0x00000008
|
||||
try:
|
||||
flags |= int(getattr(subprocess, "CREATE_NO_WINDOW", 0x08000000))
|
||||
except Exception:
|
||||
flags |= 0x08000000
|
||||
kwargs["creationflags"] = flags
|
||||
kwargs.update({k: v for k, v in _windows_hidden_subprocess_kwargs().items() if k != "creationflags"})
|
||||
|
||||
_LYRIC_PROCESS = subprocess.Popen(cmd, **kwargs)
|
||||
debug(f"Lyric loader started (log={log_path})")
|
||||
@@ -582,6 +620,8 @@ class MPV:
|
||||
helper_path = (repo_root / "MPV" / "pipeline_helper.py").resolve()
|
||||
if helper_path.exists():
|
||||
py = sys.executable or "python"
|
||||
if platform.system() == "Windows":
|
||||
py = _windows_pythonw_exe(py) or py
|
||||
helper_cmd = [
|
||||
py,
|
||||
str(helper_path),
|
||||
@@ -591,6 +631,13 @@ class MPV:
|
||||
"30",
|
||||
]
|
||||
|
||||
helper_env = os.environ.copy()
|
||||
try:
|
||||
existing_pp = helper_env.get("PYTHONPATH")
|
||||
helper_env["PYTHONPATH"] = str(repo_root) if not existing_pp else (str(repo_root) + os.pathsep + str(existing_pp))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
helper_kwargs: Dict[str, Any] = {}
|
||||
if platform.system() == "Windows":
|
||||
flags = 0
|
||||
@@ -605,6 +652,9 @@ class MPV:
|
||||
helper_kwargs["creationflags"] = flags
|
||||
helper_kwargs.update({k: v for k, v in _windows_hidden_subprocess_kwargs().items() if k != "creationflags"})
|
||||
|
||||
helper_kwargs["cwd"] = str(repo_root)
|
||||
helper_kwargs["env"] = helper_env
|
||||
|
||||
subprocess.Popen(
|
||||
helper_cmd,
|
||||
stdin=subprocess.DEVNULL,
|
||||
|
||||
Reference in New Issue
Block a user