Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions examples/chatgpt_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,7 @@

# Simulate feedback: short completions get a thumbs down.
feedback_type = (
FeedbackType.THUMBS_UP
if len(completion) > 40
else FeedbackType.THUMBS_DOWN
FeedbackType.THUMBS_UP if len(completion) > 40 else FeedbackType.THUMBS_DOWN
)
handle.track_feedback(inference_id, feedback_type)

Expand Down
7 changes: 0 additions & 7 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Shared fixtures for the WildEdge SDK test suite."""

import sys
from types import SimpleNamespace
from unittest.mock import MagicMock, patch

Expand All @@ -10,12 +9,6 @@
from wildedge.device import DeviceInfo
from wildedge.model import ModelInfo

requires_linux = pytest.mark.skipif(sys.platform != "linux", reason="linux-only test")
requires_macos = pytest.mark.skipif(sys.platform != "darwin", reason="macos-only test")
requires_windows = pytest.mark.skipif(
sys.platform != "win32", reason="windows-only test"
)


@pytest.fixture
def device_info():
Expand Down
56 changes: 51 additions & 5 deletions tests/test_platform_adapters.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
from __future__ import annotations

import pytest

from wildedge.platforms.base import cuda_device_count
from wildedge.platforms.linux import LinuxPlatform
from wildedge.platforms.macos import MacOSPlatform
from wildedge.platforms.unknown import UnknownPlatform
from wildedge.platforms.windows import WindowsPlatform


@pytest.mark.requires_linux
def test_linux_gpu_accelerators_cuda_and_rocm_counts(monkeypatch):
platform = LinuxPlatform()
monkeypatch.setattr("wildedge.platforms.linux.cuda_device_count", lambda _: 1)
Expand All @@ -20,7 +17,6 @@ def test_linux_gpu_accelerators_cuda_and_rocm_counts(monkeypatch):
assert gpu_name == "A100"


@pytest.mark.requires_windows
def test_windows_gpu_accelerators_uses_device_count(monkeypatch):
platform = WindowsPlatform()
monkeypatch.setattr("wildedge.platforms.windows.cuda_device_count", lambda _: 0)
Expand All @@ -29,7 +25,6 @@ def test_windows_gpu_accelerators_uses_device_count(monkeypatch):
assert gpu_name is None


@pytest.mark.requires_macos
def test_macos_gpu_accelerators_for_arm64(monkeypatch):
platform = MacOSPlatform()
monkeypatch.setattr("platform.machine", lambda: "arm64")
Expand Down Expand Up @@ -70,6 +65,57 @@ def cuInit(self, _flags): # noqa: N802
assert cuda_device_count("libcuda.so.1") == 0


def test_macos_os_version_returns_mac_ver(monkeypatch):
monkeypatch.setattr("platform.mac_ver", lambda: ("15.3.0", ("", "", ""), ""))
assert MacOSPlatform().os_version() == "15.3.0"


def test_macos_os_version_returns_none_on_empty(monkeypatch):
monkeypatch.setattr("platform.mac_ver", lambda: ("", ("", "", ""), ""))
assert MacOSPlatform().os_version() is None


def test_linux_os_version_reads_os_release(monkeypatch, tmp_path):
os_release = tmp_path / "os-release"
os_release.write_text(
'ID=ubuntu\nPRETTY_NAME="Ubuntu 22.04.3 LTS"\nVERSION_ID="22.04"\n'
)
monkeypatch.setattr(
"wildedge.platforms.linux.Path",
lambda p: (
os_release if p == "/etc/os-release" else __import__("pathlib").Path(p)
),
)
assert LinuxPlatform().os_version() == "Ubuntu 22.04.3 LTS"


def test_linux_os_version_falls_back_to_platform_version(monkeypatch, tmp_path):
missing = tmp_path / "no-os-release"
monkeypatch.setattr(
"wildedge.platforms.linux.Path",
lambda p: missing if p == "/etc/os-release" else __import__("pathlib").Path(p),
)
monkeypatch.setattr(
"wildedge.platforms.linux.platform.version",
lambda: "#1 SMP Fri Jan 1 00:00:00 UTC 2021",
)
assert LinuxPlatform().os_version() == "#1 SMP Fri Jan 1 00:00:00 UTC 2021"


def test_windows_os_version_returns_platform_version(monkeypatch):
monkeypatch.setattr(
"wildedge.platforms.windows.platform.version", lambda: "10.0.22621"
)
assert WindowsPlatform().os_version() == "10.0.22621"


def test_unknown_os_version_returns_platform_version(monkeypatch):
monkeypatch.setattr(
"wildedge.platforms.unknown.platform.version", lambda: "some-kernel-version"
)
assert UnknownPlatform().os_version() == "some-kernel-version"


def test_platform_adapters_expose_state_and_cache_paths():
for adapter in (
LinuxPlatform(),
Expand Down
2 changes: 1 addition & 1 deletion wildedge/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def detect_device(
device_id=device_id,
device_type=CURRENT_PLATFORM.wire_type,
device_model=CURRENT_PLATFORM.device_model(),
os_version=platform.version(),
os_version=CURRENT_PLATFORM.os_version(),
locale=detect_locale(),
timezone=detect_timezone(),
cpu_arch=platform.machine() or None,
Expand Down
2 changes: 2 additions & 0 deletions wildedge/platforms/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ def cache_base(self) -> Path: ...

def device_model(self) -> str | None: ...

def os_version(self) -> str | None: ...

def ram_bytes(self) -> int | None: ...

def disk_bytes(self) -> int | None: ...
Expand Down
15 changes: 15 additions & 0 deletions wildedge/platforms/linux.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import os
import platform
import shutil
from pathlib import Path

Expand Down Expand Up @@ -37,6 +38,20 @@ def device_model(self) -> str | None:
debug_detection_failure(f"linux device_model ({path})", exc)
return None

def os_version(self) -> str | None:
try:
path = Path("/etc/os-release")
if path.exists():
for line in path.read_text().splitlines():
if line.startswith("PRETTY_NAME="):
return line.split("=", 1)[1].strip().strip('"') or None
except Exception as exc:
debug_detection_failure("linux os_version", exc)
try:
return platform.version() or None
except Exception:
return None

def ram_bytes(self) -> int | None:
try:
with open("/proc/meminfo") as f:
Expand Down
8 changes: 8 additions & 0 deletions wildedge/platforms/macos.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ def disk_bytes(self) -> int | None:
debug_detection_failure("macos disk_bytes", exc)
return None

def os_version(self) -> str | None:
try:
ver = platform.mac_ver()[0]
return ver or None
except Exception as exc:
debug_detection_failure("macos os_version", exc)
return None

def gpu_accelerators(self) -> tuple[list[str], str | None]:
if platform.machine() == "arm64":
return ["mps"], None
Expand Down
8 changes: 8 additions & 0 deletions wildedge/platforms/unknown.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import platform
import shutil
import sys
from pathlib import Path
Expand All @@ -22,6 +23,13 @@ def cache_base(self) -> Path:
def device_model(self) -> str | None:
return None

def os_version(self) -> str | None:
try:
return platform.version() or None
except Exception as exc:
debug_detection_failure("unknown os_version", exc)
return None

def ram_bytes(self) -> int | None:
return None

Expand Down
8 changes: 8 additions & 0 deletions wildedge/platforms/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import ctypes
import os
import platform
import shutil
from pathlib import Path

Expand Down Expand Up @@ -44,6 +45,13 @@ def device_model(self) -> str | None:
debug_detection_failure("windows device_model", exc)
return None

def os_version(self) -> str | None:
try:
return platform.version() or None
except Exception as exc:
debug_detection_failure("windows os_version", exc)
return None

def ram_bytes(self) -> int | None:
try:

Expand Down
Loading