Skip to content

Commit ddde4bf

Browse files
Improve docstrings and bump pypi version
Updated module documentation and improved CLI argument parsing. Signed-off-by: Muhammad Rizwan Munawar <muhammadrizwanmunawar123@gmail.com>
1 parent 17f3003 commit ddde4bf

1 file changed

Lines changed: 68 additions & 7 deletions

File tree

streamgrid/__init__.py

Lines changed: 68 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
1-
"""StreamGrid - Ultra-fast multi-stream video display."""
1+
"""
2+
StreamGrid - Ultra-fast multi-stream video display.
23
3-
__version__ = "1.0.9"
4+
This module provides a command-line interface (CLI) for launching the
5+
StreamGrid application, enabling real-time visualization of multiple
6+
video streams in a grid layout.
7+
8+
Key Features:
9+
- Supports multiple video sources (RTSP, files, webcams, URLs)
10+
- Optional integration with Ultralytics YOLO models for inference
11+
- Flexible configuration using key=value CLI arguments
12+
- Robust parsing of lists, booleans, integers, and floats
13+
14+
Example:
15+
python -m streamgrid sources=cam1.mp4,cam2.mp4 model=yolo11n.pt imgsz=640
16+
"""
17+
18+
__version__ = "1.0.10"
419
__all__ = ["StreamGrid"]
520

621
import argparse
@@ -12,19 +27,47 @@
1227

1328

1429
def parse_args(args):
15-
"""Parse key=value arguments into dict."""
30+
"""
31+
Parse CLI arguments provided as key=value pairs into a dictionary.
32+
33+
This function supports automatic type inference for:
34+
- Lists (e.g., [1, 2, 3])
35+
- Booleans (true / false)
36+
- Integers
37+
- Floats
38+
- Strings (default)
39+
40+
Args:
41+
args (list[str]): List of command-line arguments in key=value format.
42+
43+
Returns:
44+
dict: Parsed configuration dictionary with inferred value types.
45+
46+
Example:
47+
Input:
48+
["sources=[cam1.mp4,cam2.mp4]", "imgsz=640", "show=true"]
49+
50+
Output:
51+
{
52+
"sources": ["cam1.mp4", "cam2.mp4"],
53+
"imgsz": 640,
54+
"show": True
55+
}
56+
"""
1657
config = {}
1758
kv_pairs = re.findall(r"(\w+)=([^=]+?)(?=\s+\w+=|$)", " ".join(args))
1859

1960
for k, v in kv_pairs:
2061
v = v.strip()
62+
2163
# Handle lists
2264
if v.startswith("[") and v.endswith("]"):
2365
try:
2466
config[k] = ast.literal_eval(v)
2567
continue
26-
except: # noqa
68+
except Exception:
2769
pass
70+
2871
# Handle booleans and numbers
2972
if v.lower() in ("true", "false"):
3073
config[k] = v.lower() == "true"
@@ -34,11 +77,31 @@ def parse_args(args):
3477
config[k] = float(v)
3578
else:
3679
config[k] = v
80+
3781
return config
3882

3983

4084
def main():
41-
"""StreamGrid CLI entry point."""
85+
"""
86+
StreamGrid CLI entry point.
87+
88+
This function:
89+
1. Parses command-line arguments
90+
2. Processes video sources
91+
3. Loads an optional YOLO model
92+
4. Initializes and runs the StreamGrid application
93+
94+
Exit Conditions:
95+
- Gracefully exits on keyboard interrupt (Ctrl+C)
96+
- Prints error messages and exits on runtime failures
97+
98+
CLI Usage:
99+
streamgrid sources=cam1.mp4,cam2.mp4 model=yolo11n.pt
100+
101+
Notes:
102+
- Use `model=none` to disable inference
103+
- Multiple sources can be separated by commas or semicolons
104+
"""
42105
parser = argparse.ArgumentParser(description="StreamGrid")
43106
parser.add_argument("args", nargs="*", help="key=value pairs")
44107
config = parse_args(parser.parse_args().args)
@@ -68,7 +131,5 @@ def main():
68131
except Exception as e:
69132
print(f"Error: {e}")
70133
sys.exit(1)
71-
72-
73134
if __name__ == "__main__":
74135
main()

0 commit comments

Comments
 (0)