mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-08 17:08:35 +08:00
fix: update runtime checks for supervisor restart
This commit is contained in:
@@ -82,7 +82,7 @@ def verify_platform_profile(
|
||||
expected_system: str,
|
||||
expected_machine: str,
|
||||
) -> None:
|
||||
"""验证运行平台、解释器 ABI 和 Windows Docker 能力边界。"""
|
||||
"""验证运行平台和解释器 ABI。"""
|
||||
current_system = platform.system()
|
||||
current_machine = platform.machine()
|
||||
if current_system != expected_system:
|
||||
@@ -97,37 +97,8 @@ def verify_platform_profile(
|
||||
if sys._is_gil_enabled() is expected_free_threaded:
|
||||
raise RuntimeError("解释器 GIL 状态与运行 profile 不匹配")
|
||||
|
||||
import_module("docker")
|
||||
if find_spec("pympler") is not None:
|
||||
raise RuntimeError("运行环境仍包含已移除的 Pympler")
|
||||
if current_system != "Windows":
|
||||
return
|
||||
|
||||
docker_transport = import_module("docker.transport")
|
||||
win32_modules = ("pywintypes", "win32api", "win32file", "win32pipe")
|
||||
installed_win32_modules = {
|
||||
module_name for module_name in win32_modules if find_spec(module_name) is not None
|
||||
}
|
||||
if expected_free_threaded:
|
||||
if installed_win32_modules:
|
||||
raise RuntimeError(
|
||||
"Windows free-threaded profile 意外安装 pywin32:"
|
||||
+ ", ".join(sorted(installed_win32_modules))
|
||||
)
|
||||
if getattr(docker_transport, "NpipeHTTPAdapter", None) is not None:
|
||||
raise RuntimeError("Windows free-threaded profile 意外启用了 Docker named-pipe 能力")
|
||||
return
|
||||
|
||||
missing_modules = set(win32_modules) - installed_win32_modules
|
||||
if missing_modules:
|
||||
raise RuntimeError(
|
||||
"Windows standard profile 缺少 pywin32 模块:"
|
||||
+ ", ".join(sorted(missing_modules))
|
||||
)
|
||||
for module_name in win32_modules:
|
||||
import_module(module_name)
|
||||
if getattr(docker_transport, "NpipeHTTPAdapter", None) is None:
|
||||
raise RuntimeError("Windows standard profile 缺少 Docker named-pipe 能力")
|
||||
|
||||
|
||||
def verify_application_lifecycle() -> None:
|
||||
|
||||
@@ -165,73 +165,6 @@ exclude-dependencies = [
|
||||
) == {actionable}
|
||||
|
||||
|
||||
def test_runtime_profile_probe_loads_standard_windows_named_pipe(monkeypatch):
|
||||
"""标准 Windows 必须真实加载 pywin32 与 Docker named-pipe adapter。"""
|
||||
imported = []
|
||||
win32_modules = {"pywintypes", "win32api", "win32file", "win32pipe"}
|
||||
|
||||
def fake_import_module(name: str):
|
||||
imported.append(name)
|
||||
if name == "docker.transport":
|
||||
return SimpleNamespace(NpipeHTTPAdapter=object())
|
||||
return SimpleNamespace()
|
||||
|
||||
monkeypatch.setattr(verify_runtime_profile.platform, "system", lambda: "Windows")
|
||||
monkeypatch.setattr(verify_runtime_profile.platform, "machine", lambda: "AMD64")
|
||||
monkeypatch.setattr(
|
||||
verify_runtime_profile.sysconfig,
|
||||
"get_config_var",
|
||||
lambda _name: 0,
|
||||
)
|
||||
monkeypatch.setattr(verify_runtime_profile.sys, "_is_gil_enabled", lambda: True)
|
||||
monkeypatch.setattr(
|
||||
verify_runtime_profile,
|
||||
"find_spec",
|
||||
lambda name: object() if name in win32_modules else None,
|
||||
)
|
||||
monkeypatch.setattr(verify_runtime_profile, "import_module", fake_import_module)
|
||||
|
||||
verify_runtime_profile.verify_platform_profile(
|
||||
expected_profile="standard",
|
||||
expected_system="Windows",
|
||||
expected_machine="AMD64",
|
||||
)
|
||||
|
||||
assert win32_modules <= set(imported)
|
||||
assert "docker.transport" in imported
|
||||
|
||||
|
||||
def test_runtime_profile_probe_rejects_pywin32_from_windows_free_threaded(
|
||||
monkeypatch,
|
||||
):
|
||||
"""Windows 3.14t 不得继承标准 ABI 的 pywin32。"""
|
||||
monkeypatch.setattr(verify_runtime_profile.platform, "system", lambda: "Windows")
|
||||
monkeypatch.setattr(verify_runtime_profile.platform, "machine", lambda: "AMD64")
|
||||
monkeypatch.setattr(
|
||||
verify_runtime_profile.sysconfig,
|
||||
"get_config_var",
|
||||
lambda _name: 1,
|
||||
)
|
||||
monkeypatch.setattr(verify_runtime_profile.sys, "_is_gil_enabled", lambda: False)
|
||||
monkeypatch.setattr(
|
||||
verify_runtime_profile,
|
||||
"find_spec",
|
||||
lambda name: object() if name == "win32api" else None,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
verify_runtime_profile,
|
||||
"import_module",
|
||||
lambda _name: SimpleNamespace(),
|
||||
)
|
||||
|
||||
with pytest.raises(RuntimeError, match="意外安装 pywin32"):
|
||||
verify_runtime_profile.verify_platform_profile(
|
||||
expected_profile="free-threaded",
|
||||
expected_system="Windows",
|
||||
expected_machine="AMD64",
|
||||
)
|
||||
|
||||
|
||||
def test_full_dependency_probe_rejects_psycopg_python_fallback(monkeypatch):
|
||||
"""V3t 构建不得把 psycopg 纯 Python 实现误认为可发布能力。"""
|
||||
modules = {
|
||||
|
||||
Reference in New Issue
Block a user