-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplatform_check.py
More file actions
48 lines (38 loc) · 1.27 KB
/
Copy pathplatform_check.py
File metadata and controls
48 lines (38 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from __future__ import annotations
import ctypes.util
import os
import shutil
import sys
REQUIRED_LIBRARIES = [
"xcb-cursor",
]
INSTALL_HINTS = [
("apt", "sudo apt install libxcb-cursor0"),
("dnf", "sudo dnf install libxcb-cursor"),
("yum", "sudo yum install libxcb-cursor"),
("pacman", "sudo pacman -S libxcb-cursor"),
("zypper", "sudo zypper install libxcb-cursor0"),
]
def missing_libraries() -> list[str]:
absent: list[str] = []
for library in REQUIRED_LIBRARIES:
if ctypes.util.find_library(library) is None:
absent.append(library)
return absent
def install_hint() -> str:
for manager, command in INSTALL_HINTS:
if shutil.which(manager):
return command
return "Install libxcb-cursor0 using your distribution package manager"
def ensure_platform_ready() -> int:
if os.environ.get("QT_QPA_PLATFORM") == "offscreen":
return 0
absent = missing_libraries()
if not absent:
return 0
names = ", ".join(absent)
print("Amper could not start because required system libraries are missing.", file=sys.stderr)
print(f"Missing: {names}", file=sys.stderr)
print(f"Fix: {install_hint()}", file=sys.stderr)
print("Then run: python main.py", file=sys.stderr)
return 1