-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathdev.py
More file actions
161 lines (124 loc) · 4.27 KB
/
dev.py
File metadata and controls
161 lines (124 loc) · 4.27 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/usr/bin/env python3
"""
Development CLI tool for getstream SDK.
Essential dev commands for testing, linting, and type checking.
"""
import os
import shlex
import subprocess
import sys
from typing import Optional
import click
def run(
command: str, env: Optional[dict] = None, check: bool = True
) -> subprocess.CompletedProcess[str]:
"""Run a shell command with automatic argument parsing."""
click.echo(f"Running: {command}")
# Set up environment
full_env = os.environ.copy()
if env:
full_env.update(env)
cmd_list = shlex.split(command)
try:
result = subprocess.run(
cmd_list, check=check, capture_output=False, env=full_env, text=True
)
return result
except subprocess.CalledProcessError as e:
if check:
click.echo(f"Command failed with exit code {e.returncode}", err=True)
sys.exit(e.returncode)
# Return a CompletedProcess with the error info when check=False
return subprocess.CompletedProcess(
cmd_list, e.returncode, stdout=None, stderr=None
)
@click.group(invoke_without_command=True)
@click.pass_context
def cli(ctx):
"""Development CLI tool for getstream SDK. Runs 'check' by default."""
if ctx.invoked_subcommand is None:
ctx.invoke(check)
@cli.command()
def test_integration():
"""Run integration tests (requires secrets in place)."""
click.echo("Running integration tests...")
run("uv run pytest -m integration tests/ getstream/")
@cli.command()
def test():
"""Run all tests except integration tests."""
click.echo("Running unit tests...")
run("uv run pytest -m 'not integration' tests/ getstream/")
@cli.command()
def format():
"""Run ruff formatting with auto-fix."""
click.echo("Running ruff format...")
run("uv run ruff check --fix .")
run("uv run ruff format .")
@cli.command()
def lint():
"""Run ruff linting (check only)."""
click.echo("Running ruff lint...")
run("uv run ruff check .")
run("uv run ruff format --check .")
# Generated code patterns to exclude from type checking
TY_EXCLUDES = [
"getstream/models/",
"getstream/video/rtc/pb/",
"**/rest_client.py",
"**/async_rest_client.py",
"getstream/chat/channel.py",
"getstream/chat/async_channel.py",
"getstream/chat/client.py",
"getstream/chat/async_client.py",
"getstream/common/client.py",
"getstream/common/async_client.py",
"getstream/moderation/client.py",
"getstream/moderation/async_client.py",
"getstream/video/client.py",
"getstream/video/async_client.py",
"getstream/video/call.py",
"getstream/video/async_call.py",
"getstream/feeds/client.py",
"getstream/feeds/feeds.py",
"getstream/stream.py",
]
def _run_typecheck():
"""Internal function to run ty type checks."""
click.echo("Running ty type checker on getstream...")
excludes = " ".join(f'--exclude "{e}"' for e in TY_EXCLUDES)
run(f"uvx ty check getstream/ {excludes}")
@cli.command()
def typecheck():
"""Run ty type checks on getstream package (excludes generated code)."""
_run_typecheck()
@cli.command("ty")
def ty_alias():
"""Run ty type checks (alias for 'typecheck')."""
_run_typecheck()
@cli.command()
def check():
"""Run full check: ruff, ty, and unit tests."""
click.echo("Running full development check...")
# Run ruff
click.echo("\n=== 1. Ruff Linting ===")
run("uv run ruff check .")
run("uv run ruff format --check .")
# Run ty type checker on main package (excludes generated code)
click.echo("\n=== 2. Type Checking (ty) ===")
excludes = " ".join(f'--exclude "{e}"' for e in TY_EXCLUDES)
run(f"uvx ty check getstream/ {excludes}")
# Run unit tests
click.echo("\n=== 3. Unit Tests ===")
run("uv run pytest -m 'not integration' tests/ getstream/")
click.echo("\n✅ All checks passed!")
@cli.command()
def regen():
"""Regenerate all generated code (OpenAPI + WebRTC protobuf)."""
click.echo("Regenerating all generated code...")
click.echo("\n=== 1. OpenAPI Code Generation ===")
run("./generate.sh")
click.echo("\n=== 2. WebRTC Protobuf Generation ===")
run("./generate_webrtc.sh")
click.echo("\n✅ Code regeneration complete!")
if __name__ == "__main__":
cli()