forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_platform_markers.py
More file actions
86 lines (67 loc) · 3.13 KB
/
Copy pathtest_platform_markers.py
File metadata and controls
86 lines (67 loc) · 3.13 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
from __future__ import annotations
from pathlib import Path
from packaging.requirements import Requirement
ROOT_DIR = Path(__file__).resolve().parent.parent
PYPROJECT_PATH = ROOT_DIR / "pyproject.toml"
REQUIREMENTS_PATH = ROOT_DIR / "requirements.txt"
PYOBJC_PACKAGES = {
"pyobjc-core",
"pyobjc-framework-Cocoa",
"pyobjc-framework-CoreBluetooth",
"pyobjc-framework-libdispatch",
}
def _read_pyproject_dependencies() -> list[Requirement]:
try:
import tomllib
except ImportError:
import tomli as tomllib # type: ignore
with open(PYPROJECT_PATH, "rb") as f:
data = tomllib.load(f)
deps = data.get("project", {}).get("dependencies", [])
return [Requirement(dep) for dep in deps]
def _read_requirements_dependencies() -> list[Requirement]:
lines = REQUIREMENTS_PATH.read_text(encoding="utf-8").splitlines()
reqs = []
for line in lines:
line = line.strip()
if not line or line.startswith("#"):
continue
reqs.append(Requirement(line))
return reqs
def test_pyproject_pyobjc_have_darwin_marker():
reqs = _read_pyproject_dependencies()
pyobjc_reqs = [r for r in reqs if r.name in PYOBJC_PACKAGES]
assert len(pyobjc_reqs) == 4, f"Expected 4 pyobjc dependencies, got {len(pyobjc_reqs)}"
for req in pyobjc_reqs:
assert req.marker is not None, f"{req.name} has no environment marker"
assert req.marker.evaluate({"sys_platform": "darwin"}) is True
assert req.marker.evaluate({"sys_platform": "linux"}) is False
assert req.marker.evaluate({"sys_platform": "win32"}) is False
def test_requirements_txt_pyobjc_have_darwin_marker():
reqs = _read_requirements_dependencies()
pyobjc_reqs = [r for r in reqs if r.name in PYOBJC_PACKAGES]
assert len(pyobjc_reqs) == 4, f"Expected 4 pyobjc dependencies, got {len(pyobjc_reqs)}"
for req in pyobjc_reqs:
assert req.marker is not None, f"{req.name} has no environment marker"
assert req.marker.evaluate({"sys_platform": "darwin"}) is True
assert req.marker.evaluate({"sys_platform": "linux"}) is False
assert req.marker.evaluate({"sys_platform": "win32"}) is False
def test_cross_platform_dependencies_selected_everywhere():
for get_reqs in (_read_pyproject_dependencies, _read_requirements_dependencies):
reqs = get_reqs()
common_pkgs = {"bleak", "opuslib", "websockets"}
common_reqs = [r for r in reqs if r.name in common_pkgs]
assert len(common_reqs) == len(common_pkgs)
for platform in ("linux", "win32", "darwin"):
active_names = {
r.name for r in reqs
if r.marker is None or r.marker.evaluate({"sys_platform": platform})
}
# Common dependencies must be active everywhere
for pkg in common_pkgs:
assert pkg in active_names, f"{pkg} missing on {platform}"
# PyObjC dependencies must only be active on darwin
if platform == "darwin":
assert PYOBJC_PACKAGES.issubset(active_names)
else:
assert not PYOBJC_PACKAGES.intersection(active_names)