Coverage for orchestrant/yolo/__init__.py: 65%

17 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-10-19 17:06 +0000

1from __future__ import annotations 

2 

3import importlib 

4from typing import TYPE_CHECKING, Any 

5 

6 

7if TYPE_CHECKING: 

8 from orchestrant.monitoring.gpu import AMD_AVAILABLE, PYNVML_AVAILABLE 

9 from orchestrant.pipeline.capture import CameraCapture, OpenCVCapture 

10 from orchestrant.pipeline.capture.gstreamer import ( 

11 GStreamerSubprocessCapture, 

12 find_gstreamer_launch, 

13 get_gstreamer_env, 

14 ) 

15 from orchestrant.pipeline.logging import configure_logging 

16 from orchestrant.pipeline.metrics.performance import PerformanceTracker 

17 from orchestrant.pipeline.monitoring.system import ( 

18 SystemMonitor, 

19 ) 

20 from orchestrant.pipeline.tracking.centroid import SimpleCentroidTracker 

21 from orchestrant.pipeline.types import ( 

22 CameraConfig, 

23 CaptureBackend, 

24 PerformanceMetrics, 

25 SystemStats, 

26 Track, 

27 ) 

28 from orchestrant.pipeline.ui.flet_viewer import FletViewer 

29 from orchestrant.yolo.cli import parse_args 

30 from orchestrant.yolo.core.constants import CLASS_NAMES, COLORS 

31 from orchestrant.yolo.core.postprocess import postprocess 

32 from orchestrant.yolo.core.preprocess import infer_input_size, preprocess 

33 from orchestrant.yolo.ui.draw import ( 

34 draw_2d_running_map, 

35 draw_cpu_process_history_plot, 

36 draw_detections, 

37 get_color_by_percent, 

38 ) 

39 

40# Loaded on first use (PEP 562), so a pure-numpy submodule imports where OpenCV has no wheel (free-threaded 3.14t). 

41_LAZY_EXPORTS: dict[str, str] = { 

42 "AMD_AVAILABLE": "orchestrant.monitoring.gpu", 

43 "PYNVML_AVAILABLE": "orchestrant.monitoring.gpu", 

44 "CameraCapture": "orchestrant.pipeline.capture", 

45 "OpenCVCapture": "orchestrant.pipeline.capture", 

46 "GStreamerSubprocessCapture": "orchestrant.pipeline.capture.gstreamer", 

47 "find_gstreamer_launch": "orchestrant.pipeline.capture.gstreamer", 

48 "get_gstreamer_env": "orchestrant.pipeline.capture.gstreamer", 

49 "configure_logging": "orchestrant.pipeline.logging", 

50 "PerformanceTracker": "orchestrant.pipeline.metrics.performance", 

51 "SystemMonitor": "orchestrant.pipeline.monitoring.system", 

52 "SimpleCentroidTracker": "orchestrant.pipeline.tracking.centroid", 

53 "CameraConfig": "orchestrant.pipeline.types", 

54 "CaptureBackend": "orchestrant.pipeline.types", 

55 "PerformanceMetrics": "orchestrant.pipeline.types", 

56 "SystemStats": "orchestrant.pipeline.types", 

57 "Track": "orchestrant.pipeline.types", 

58 "FletViewer": "orchestrant.pipeline.ui.flet_viewer", 

59 "parse_args": "orchestrant.yolo.cli", 

60 "CLASS_NAMES": "orchestrant.yolo.core.constants", 

61 "COLORS": "orchestrant.yolo.core.constants", 

62 "postprocess": "orchestrant.yolo.core.postprocess", 

63 "infer_input_size": "orchestrant.yolo.core.preprocess", 

64 "preprocess": "orchestrant.yolo.core.preprocess", 

65 "draw_2d_running_map": "orchestrant.yolo.ui.draw", 

66 "draw_cpu_process_history_plot": "orchestrant.yolo.ui.draw", 

67 "draw_detections": "orchestrant.yolo.ui.draw", 

68 "get_color_by_percent": "orchestrant.yolo.ui.draw", 

69} 

70 

71 

72def __getattr__(name: str) -> Any: # noqa: ANN401 

73 """Import a re-exported name on first access.""" 

74 if name in _LAZY_EXPORTS: 

75 value = getattr(importlib.import_module(_LAZY_EXPORTS[name]), name) 

76 else: 

77 msg = f"module {__name__!r} has no attribute {name!r}" 

78 raise AttributeError(msg) 

79 globals()[name] = value 

80 return value 

81 

82 

83def __dir__() -> list[str]: 

84 """List the lazy re-exports too, as the eager ones were listed before.""" 

85 return sorted(__all__) 

86 

87 

88def run_yolo_monitor(argv: list[str] | None = None) -> int: 

89 """Run the YOLO monitor entry point via lazy import.""" 

90 module = importlib.import_module("orchestrant.yolo.monitor") 

91 return module.run_yolo_monitor(argv) 

92 

93 

94__all__ = [ 

95 "AMD_AVAILABLE", 

96 "CLASS_NAMES", 

97 "COLORS", 

98 "PYNVML_AVAILABLE", 

99 "CameraCapture", 

100 "CameraConfig", 

101 "CaptureBackend", 

102 "FletViewer", 

103 "GStreamerSubprocessCapture", 

104 "OpenCVCapture", 

105 "PerformanceMetrics", 

106 "PerformanceTracker", 

107 "SimpleCentroidTracker", 

108 "SystemMonitor", 

109 "SystemStats", 

110 "Track", 

111 "configure_logging", 

112 "draw_2d_running_map", 

113 "draw_cpu_process_history_plot", 

114 "draw_detections", 

115 "find_gstreamer_launch", 

116 "get_color_by_percent", 

117 "get_gstreamer_env", 

118 "infer_input_size", 

119 "parse_args", 

120 "postprocess", 

121 "preprocess", 

122 "run_yolo_monitor", 

123]