rldyour-sysinfo 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ /daemon/target/
2
+ /extension/schemas/gschemas.compiled
3
+ /python/dist/
4
+ /python/.pytest_cache/
5
+ /python/**/__pycache__/
@@ -0,0 +1,30 @@
1
+ Metadata-Version: 2.5
2
+ Name: rldyour-sysinfo
3
+ Version: 0.2.0
4
+ Summary: Python client for the rldyour-sysinfo live metrics daemon
5
+ Project-URL: Homepage, https://github.com/NDDev-OpenNetwork/rldyour-sysinfo
6
+ Project-URL: Repository, https://github.com/NDDev-OpenNetwork/rldyour-sysinfo
7
+ Project-URL: Issues, https://github.com/NDDev-OpenNetwork/rldyour-sysinfo/issues
8
+ Author: NDDev OpenNetwork
9
+ License-Expression: AGPL-3.0-or-later
10
+ Classifier: Operating System :: MacOS
11
+ Classifier: Operating System :: Microsoft :: Windows :: Windows 10
12
+ Classifier: Operating System :: POSIX :: Linux
13
+ Classifier: Programming Language :: Python :: 3
14
+ Requires-Python: >=3.9
15
+ Description-Content-Type: text/markdown
16
+
17
+ # rldyour-sysinfo Python client
18
+
19
+ Typed, dependency-free client for the local JSON protocol exposed by the
20
+ `rldyour-sysinfod` Rust daemon.
21
+
22
+ ```python
23
+ from rldyour_sysinfo import samples
24
+
25
+ for sample in samples(interval=2):
26
+ print(sample["gpu"])
27
+ ```
28
+
29
+ The command `rldyour-sysinfo --once` prints one sample as JSON. Install the
30
+ daemon from the [main repository](https://github.com/NDDev-OpenNetwork/rldyour-sysinfo).
@@ -0,0 +1,14 @@
1
+ # rldyour-sysinfo Python client
2
+
3
+ Typed, dependency-free client for the local JSON protocol exposed by the
4
+ `rldyour-sysinfod` Rust daemon.
5
+
6
+ ```python
7
+ from rldyour_sysinfo import samples
8
+
9
+ for sample in samples(interval=2):
10
+ print(sample["gpu"])
11
+ ```
12
+
13
+ The command `rldyour-sysinfo --once` prints one sample as JSON. Install the
14
+ daemon from the [main repository](https://github.com/NDDev-OpenNetwork/rldyour-sysinfo).
@@ -0,0 +1,29 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.27"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "rldyour-sysinfo"
7
+ version = "0.2.0"
8
+ description = "Python client for the rldyour-sysinfo live metrics daemon"
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = "AGPL-3.0-or-later"
12
+ authors = [{ name = "NDDev OpenNetwork" }]
13
+ classifiers = [
14
+ "Programming Language :: Python :: 3",
15
+ "Operating System :: MacOS",
16
+ "Operating System :: Microsoft :: Windows :: Windows 10",
17
+ "Operating System :: POSIX :: Linux",
18
+ ]
19
+
20
+ [project.urls]
21
+ Homepage = "https://github.com/NDDev-OpenNetwork/rldyour-sysinfo"
22
+ Repository = "https://github.com/NDDev-OpenNetwork/rldyour-sysinfo"
23
+ Issues = "https://github.com/NDDev-OpenNetwork/rldyour-sysinfo/issues"
24
+
25
+ [project.scripts]
26
+ rldyour-sysinfo = "rldyour_sysinfo:main"
27
+
28
+ [tool.hatch.build.targets.wheel]
29
+ packages = ["src/rldyour_sysinfo"]
@@ -0,0 +1,74 @@
1
+ """Client for the rldyour-sysinfo local protocol."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import argparse
6
+ import json
7
+ import os
8
+ import socket
9
+ import sys
10
+ from collections.abc import Iterator
11
+ from pathlib import Path
12
+ from typing import Any, TypedDict
13
+
14
+ __version__ = "0.2.0"
15
+
16
+
17
+ class Pair(TypedDict):
18
+ usage: float | None
19
+ temp: float | None
20
+
21
+
22
+ class Sample(TypedDict):
23
+ v: int
24
+ cpu: dict[str, float | None]
25
+ memory: dict[str, float | None]
26
+ gpu: dict[str, float | None]
27
+ disk: dict[str, float | None]
28
+ net: dict[str, float | None]
29
+
30
+
31
+ def socket_path() -> Path:
32
+ """Return the daemon socket used by the current platform."""
33
+ if sys.platform == "darwin":
34
+ return Path.home() / "Library/Caches/rldyour-sysinfo/rldyour-sysinfo.sock"
35
+ if os.name == "nt":
36
+ root = os.environ.get("LOCALAPPDATA") or os.environ.get("TEMP")
37
+ if not root:
38
+ raise RuntimeError("LOCALAPPDATA and TEMP are unset")
39
+ return Path(root) / "rldyour-sysinfo/rldyour-sysinfo.sock"
40
+ runtime = os.environ.get("XDG_RUNTIME_DIR")
41
+ if not runtime:
42
+ runtime = f"/run/user/{os.getuid()}"
43
+ return Path(runtime) / "rldyour-sysinfo.sock"
44
+
45
+
46
+ def _decode(line: bytes) -> Sample:
47
+ value: Any = json.loads(line)
48
+ required = {"v", "cpu", "memory", "gpu", "disk", "net"}
49
+ if not isinstance(value, dict) or set(value) != required or value.get("v") != 1:
50
+ raise ValueError("unsupported rldyour-sysinfo sample")
51
+ return value
52
+
53
+
54
+ def samples(interval: float = 5, path: str | os.PathLike[str] | None = None) -> Iterator[Sample]:
55
+ """Yield live samples until the connection closes."""
56
+ if not 1 <= interval <= 60:
57
+ raise ValueError("interval must be between 1 and 60 seconds")
58
+ with socket.socket(socket.AF_UNIX) as connection:
59
+ connection.connect(str(Path(path) if path is not None else socket_path()))
60
+ connection.sendall(json.dumps({"interval": interval}).encode() + b"\n")
61
+ with connection.makefile("rb") as stream:
62
+ for line in stream:
63
+ yield _decode(line)
64
+
65
+
66
+ def main() -> None:
67
+ parser = argparse.ArgumentParser(description="Read live rldyour-sysinfo metrics")
68
+ parser.add_argument("--interval", type=float, default=5)
69
+ parser.add_argument("--once", action="store_true")
70
+ args = parser.parse_args()
71
+ for sample in samples(args.interval):
72
+ print(json.dumps(sample, separators=(",", ":")), flush=True)
73
+ if args.once:
74
+ break
@@ -0,0 +1,20 @@
1
+ import json
2
+
3
+ import pytest
4
+
5
+ from rldyour_sysinfo import _decode, samples
6
+
7
+
8
+ def test_decode_accepts_protocol_v1():
9
+ value = {"v": 1, "cpu": {}, "memory": {}, "gpu": {}, "disk": {}, "net": {}}
10
+ assert _decode(json.dumps(value).encode()) == value
11
+
12
+
13
+ def test_decode_rejects_unknown_shape():
14
+ with pytest.raises(ValueError):
15
+ _decode(b'{"v":2}')
16
+
17
+
18
+ def test_interval_is_bounded_before_connecting():
19
+ with pytest.raises(ValueError):
20
+ next(samples(0))