Skip to content

Commit 14c3d92

Browse files
howethomasclaude
andcommitted
fix: Resolve ruff lint and mypy type check errors
- Fix F401 unused imports throughout codebase - Fix F541 f-strings without placeholders - Fix F841 unused local variables (e.g., task in start.py) - Convert Optional[X] to X | None (UP007) for modern Python - Fix mypy type errors in config_manager, config, health, and status - Apply ruff formatter to ensure consistent code style Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 3af8e5e commit 14c3d92

25 files changed

+127
-191
lines changed

conserver/cli.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"""
44

55
from pathlib import Path
6-
from typing import Optional
76

87
import typer
98
from rich.panel import Panel
@@ -74,7 +73,7 @@ def main(
7473
@app.command()
7574
def health(
7675
verbose: bool = typer.Option(False, "--verbose", "-v", help="Show detailed health info"),
77-
server_path: Optional[Path] = typer.Option(
76+
server_path: Path | None = typer.Option(
7877
None, "--server-path", help="Path to vcon-server installation"
7978
),
8079
) -> None:
@@ -145,7 +144,7 @@ def health(
145144

146145
@app.command()
147146
def init(
148-
server_path: Optional[Path] = typer.Option(
147+
server_path: Path | None = typer.Option(
149148
None, "--server-path", help="Path to vcon-server installation"
150149
),
151150
overwrite: bool = typer.Option(

conserver/commands/config.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import json
66
from enum import Enum
77
from pathlib import Path
8-
from typing import Any, Optional
8+
from typing import Any
99

1010
import typer
1111
import yaml
@@ -47,7 +47,7 @@ def show(
4747
output_format: OutputFormat = typer.Option(
4848
OutputFormat.YAML, "--format", help="Output format (for config/compose)"
4949
),
50-
server_path: Optional[Path] = typer.Option(
50+
server_path: Path | None = typer.Option(
5151
None, "--server-path", help="Path to vcon-server installation"
5252
),
5353
) -> None:
@@ -60,17 +60,16 @@ def show(
6060

6161
if not config_file.exists:
6262
print_error(f"File not found: {config_file.path}")
63-
console.print(
64-
"[dim]Hint: Run 'conserver config init' to create from example[/dim]"
65-
)
63+
console.print("[dim]Hint: Run 'conserver config init' to create from example[/dim]")
6664
raise typer.Exit(1)
6765

6866
console.print(f"[bold]File:[/bold] {config_file.path}\n")
6967

7068
if file == ConfigFileType.ENV:
7169
_show_env(config_manager, secrets)
7270
else:
73-
_show_yaml(config_file.content, output_format, config_manager, secrets)
71+
content = config_file.content if config_file.content is not None else {}
72+
_show_yaml(content, output_format, config_manager, secrets)
7473

7574
except ConserverError as e:
7675
print_error(e.message)
@@ -130,8 +129,8 @@ def edit(
130129
file: ConfigFileType = typer.Option(
131130
ConfigFileType.CONFIG, "--file", help="Which config file to edit"
132131
),
133-
editor: Optional[str] = typer.Option(None, "--editor", help="Editor to use"),
134-
server_path: Optional[Path] = typer.Option(
132+
editor: str | None = typer.Option(None, "--editor", help="Editor to use"),
133+
server_path: Path | None = typer.Option(
135134
None, "--server-path", help="Path to vcon-server installation"
136135
),
137136
) -> None:
@@ -144,9 +143,7 @@ def edit(
144143

145144
if not config_file.exists:
146145
print_error(f"File not found: {config_file.path}")
147-
console.print(
148-
"[dim]Hint: Run 'conserver config init' to create from example[/dim]"
149-
)
146+
console.print("[dim]Hint: Run 'conserver config init' to create from example[/dim]")
150147
raise typer.Exit(1)
151148

152149
console.print(f"Opening {config_file.path}...")
@@ -172,7 +169,7 @@ def set_value(
172169
"--file",
173170
help="Which config file to modify (env or config)",
174171
),
175-
server_path: Optional[Path] = typer.Option(
172+
server_path: Path | None = typer.Option(
176173
None, "--server-path", help="Path to vcon-server installation"
177174
),
178175
) -> None:
@@ -209,7 +206,7 @@ def set_value(
209206
@app.command("validate")
210207
def validate(
211208
fix: bool = typer.Option(False, "--fix", help="Attempt to fix simple validation issues"),
212-
server_path: Optional[Path] = typer.Option(
209+
server_path: Path | None = typer.Option(
213210
None, "--server-path", help="Path to vcon-server installation"
214211
),
215212
) -> None:
@@ -254,7 +251,7 @@ def init(
254251
False, "--overwrite", help="Overwrite existing configuration files"
255252
),
256253
force: bool = typer.Option(False, "--force", "-f", help="Skip confirmation prompts"),
257-
server_path: Optional[Path] = typer.Option(
254+
server_path: Path | None = typer.Option(
258255
None, "--server-path", help="Path to vcon-server installation"
259256
),
260257
) -> None:

conserver/commands/images.py

Lines changed: 26 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
"""
44

55
from pathlib import Path
6-
from typing import Optional
76

87
import typer
98
from rich.table import Table
109

1110
from conserver.console import console, print_error, print_success, print_warning
1211
from conserver.docker_ops import DockerOps
13-
from conserver.exceptions import ConserverError, ImageError
12+
from conserver.exceptions import ConserverError
1413
from conserver.image_registry import ImageRegistry
1514

1615
# Create images subcommand app
@@ -26,9 +25,7 @@ def list_images(
2625
False, "--remote", "-r", help="List available tags from remote registry"
2726
),
2827
limit: int = typer.Option(20, "--limit", help="Maximum number of tags to show"),
29-
registry: str = typer.Option(
30-
DEFAULT_REGISTRY, "--registry", help="Container registry URL"
31-
),
28+
registry: str = typer.Option(DEFAULT_REGISTRY, "--registry", help="Container registry URL"),
3229
) -> None:
3330
"""List available vcon-server images."""
3431
try:
@@ -64,9 +61,7 @@ def list_images(
6461

6562
if not images:
6663
print_warning("No local images found")
67-
console.print(
68-
"[dim]Use 'conserver images pull <tag>' to download an image[/dim]"
69-
)
64+
console.print("[dim]Use 'conserver images pull <tag>' to download an image[/dim]")
7065
return
7166

7267
table = Table(title="Local Images")
@@ -93,9 +88,7 @@ def list_images(
9388
@app.command("pull")
9489
def pull_image(
9590
tag: str = typer.Argument("main", help="Image tag to pull (e.g., 'main', 'v1.0.0')"),
96-
registry: str = typer.Option(
97-
DEFAULT_REGISTRY, "--registry", help="Container registry URL"
98-
),
91+
registry: str = typer.Option(DEFAULT_REGISTRY, "--registry", help="Container registry URL"),
9992
) -> None:
10093
"""Pull a vcon-server image from the registry."""
10194
try:
@@ -123,10 +116,8 @@ def use_image(
123116
restart: bool = typer.Option(
124117
False, "--restart", "-r", help="Restart containers after switching"
125118
),
126-
registry: str = typer.Option(
127-
DEFAULT_REGISTRY, "--registry", help="Container registry URL"
128-
),
129-
server_path: Optional[Path] = typer.Option(
119+
registry: str = typer.Option(DEFAULT_REGISTRY, "--registry", help="Container registry URL"),
120+
server_path: Path | None = typer.Option(
130121
None, "--server-path", help="Path to vcon-server installation"
131122
),
132123
) -> None:
@@ -182,9 +173,7 @@ def use_image(
182173
print_success(f"Updated .env to use {registry}:{tag}")
183174
else:
184175
# Create .env file with the image settings
185-
env_path.write_text(
186-
f"VCON_SERVER_IMAGE={registry}\nVCON_SERVER_TAG={tag}\n"
187-
)
176+
env_path.write_text(f"VCON_SERVER_IMAGE={registry}\nVCON_SERVER_TAG={tag}\n")
188177
print_success(f"Created .env with {registry}:{tag}")
189178

190179
if was_running and restart:
@@ -204,16 +193,14 @@ def use_image(
204193

205194
@app.command("upgrade")
206195
def upgrade_image(
207-
to_tag: Optional[str] = typer.Argument(
196+
to_tag: str | None = typer.Argument(
208197
None, help="Specific version to upgrade to (defaults to latest)"
209198
),
210199
restart: bool = typer.Option(
211200
True, "--restart/--no-restart", help="Restart containers after upgrade"
212201
),
213-
registry: str = typer.Option(
214-
DEFAULT_REGISTRY, "--registry", help="Container registry URL"
215-
),
216-
server_path: Optional[Path] = typer.Option(
202+
registry: str = typer.Option(DEFAULT_REGISTRY, "--registry", help="Container registry URL"),
203+
server_path: Path | None = typer.Option(
217204
None, "--server-path", help="Path to vcon-server installation"
218205
),
219206
) -> None:
@@ -256,7 +243,9 @@ def upgrade_image(
256243
print_warning(
257244
f"Target version {target_tag} is not newer than current {current_tag}"
258245
)
259-
console.print("[dim]Use 'conserver images downgrade' to switch to an older version[/dim]")
246+
console.print(
247+
"[dim]Use 'conserver images downgrade' to switch to an older version[/dim]"
248+
)
260249
return
261250

262251
console.print(f"\n[bold]Upgrading to {target_tag}...[/bold]")
@@ -313,13 +302,9 @@ def downgrade_image(
313302
restart: bool = typer.Option(
314303
True, "--restart/--no-restart", help="Restart containers after downgrade"
315304
),
316-
force: bool = typer.Option(
317-
False, "--force", "-f", help="Skip confirmation prompt"
318-
),
319-
registry: str = typer.Option(
320-
DEFAULT_REGISTRY, "--registry", help="Container registry URL"
321-
),
322-
server_path: Optional[Path] = typer.Option(
305+
force: bool = typer.Option(False, "--force", "-f", help="Skip confirmation prompt"),
306+
registry: str = typer.Option(DEFAULT_REGISTRY, "--registry", help="Container registry URL"),
307+
server_path: Path | None = typer.Option(
323308
None, "--server-path", help="Path to vcon-server installation"
324309
),
325310
) -> None:
@@ -335,12 +320,12 @@ def downgrade_image(
335320
# Warn if downgrading
336321
if image_registry.compare_versions(to_tag, current_tag) >= 0:
337322
print_warning(f"{to_tag} is not older than {current_tag}")
338-
console.print("[dim]Use 'conserver images upgrade' to switch to a newer version[/dim]")
323+
console.print(
324+
"[dim]Use 'conserver images upgrade' to switch to a newer version[/dim]"
325+
)
339326

340327
if not force:
341-
console.print(
342-
f"\n[yellow]Warning: Downgrading may cause compatibility issues.[/yellow]"
343-
)
328+
console.print("\n[yellow]Warning: Downgrading may cause compatibility issues.[/yellow]")
344329
if not typer.confirm(f"Downgrade to {to_tag}?"):
345330
console.print("[dim]Cancelled[/dim]")
346331
raise typer.Exit(0)
@@ -396,9 +381,7 @@ def downgrade_image(
396381
def remove_image(
397382
tag: str = typer.Argument(..., help="Image tag to remove"),
398383
force: bool = typer.Option(False, "--force", "-f", help="Force removal"),
399-
registry: str = typer.Option(
400-
DEFAULT_REGISTRY, "--registry", help="Container registry URL"
401-
),
384+
registry: str = typer.Option(DEFAULT_REGISTRY, "--registry", help="Container registry URL"),
402385
) -> None:
403386
"""Remove a local vcon-server image."""
404387
try:
@@ -425,9 +408,7 @@ def remove_image(
425408
@app.command("info")
426409
def image_info(
427410
tag: str = typer.Argument("main", help="Image tag to inspect"),
428-
registry: str = typer.Option(
429-
DEFAULT_REGISTRY, "--registry", help="Container registry URL"
430-
),
411+
registry: str = typer.Option(DEFAULT_REGISTRY, "--registry", help="Container registry URL"),
431412
) -> None:
432413
"""Show detailed information about an image."""
433414
try:
@@ -491,9 +472,7 @@ def image_info(
491472
def prune_images(
492473
keep: int = typer.Option(3, "--keep", "-k", help="Number of recent images to keep"),
493474
force: bool = typer.Option(False, "--force", "-f", help="Skip confirmation"),
494-
registry: str = typer.Option(
495-
DEFAULT_REGISTRY, "--registry", help="Container registry URL"
496-
),
475+
registry: str = typer.Option(DEFAULT_REGISTRY, "--registry", help="Container registry URL"),
497476
) -> None:
498477
"""Remove old local images, keeping only the most recent ones."""
499478
try:
@@ -508,7 +487,9 @@ def prune_images(
508487
to_remove = images[keep:]
509488

510489
console.print(f"[bold]Found {len(images)} local images[/bold]")
511-
console.print(f"[yellow]Will remove {len(to_remove)} images, keeping {keep} most recent[/yellow]")
490+
console.print(
491+
f"[yellow]Will remove {len(to_remove)} images, keeping {keep} most recent[/yellow]"
492+
)
512493

513494
if not force:
514495
console.print("\n[bold]Images to remove:[/bold]")

conserver/commands/logs.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
"""
44

55
import re
6-
import sys
76
from pathlib import Path
8-
from typing import Optional
97

108
import typer
119

@@ -15,17 +13,17 @@
1513

1614

1715
def logs(
18-
services: Optional[str] = typer.Argument(
16+
services: str | None = typer.Argument(
1917
None, help="Services to show logs for (comma-separated, or 'all')"
2018
),
2119
follow: bool = typer.Option(False, "--follow", "-f", help="Follow log output"),
22-
tail: Optional[int] = typer.Option(100, "--tail", help="Number of lines from end"),
23-
since: Optional[str] = typer.Option(
20+
tail: int | None = typer.Option(100, "--tail", help="Number of lines from end"),
21+
since: str | None = typer.Option(
2422
None, "--since", help="Show logs since timestamp (e.g., 2h, 30m, 2024-01-01)"
2523
),
2624
timestamps: bool = typer.Option(False, "--timestamps", "-t", help="Show timestamps"),
27-
grep_pattern: Optional[str] = typer.Option(None, "--grep", help="Filter logs by pattern"),
28-
server_path: Optional[Path] = typer.Option(
25+
grep_pattern: str | None = typer.Option(None, "--grep", help="Filter logs by pattern"),
26+
server_path: Path | None = typer.Option(
2927
None, "--server-path", help="Path to vcon-server installation"
3028
),
3129
) -> None:
@@ -34,7 +32,7 @@ def logs(
3432
docker = DockerOps(server_path)
3533

3634
# Parse services
37-
service_list: Optional[list[str]] = None
35+
service_list: list[str] | None = None
3836
if services and services.lower() != "all":
3937
service_list = [s.strip() for s in services.split(",")]
4038

@@ -45,7 +43,7 @@ def logs(
4543
raise typer.Exit(1)
4644

4745
# Compile grep pattern if provided
48-
compiled_pattern: Optional[re.Pattern[str]] = None
46+
compiled_pattern: re.Pattern[str] | None = None
4947
if grep_pattern:
5048
try:
5149
compiled_pattern = re.compile(grep_pattern, re.IGNORECASE)

conserver/commands/restart.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"""
44

55
from pathlib import Path
6-
from typing import Optional
76

87
import typer
98
from rich.progress import Progress, SpinnerColumn, TextColumn
@@ -14,11 +13,11 @@
1413

1514

1615
def restart(
17-
services: Optional[str] = typer.Option(
16+
services: str | None = typer.Option(
1817
None, "--services", help="Specific services to restart (comma-separated)"
1918
),
2019
timeout: int = typer.Option(30, "--timeout", help="Timeout for graceful shutdown"),
21-
server_path: Optional[Path] = typer.Option(
20+
server_path: Path | None = typer.Option(
2221
None, "--server-path", help="Path to vcon-server installation"
2322
),
2423
) -> None:
@@ -35,9 +34,7 @@ def restart(
3534
transient=True,
3635
) as progress:
3736
if service_list:
38-
progress.add_task(
39-
f"Restarting services: {', '.join(service_list)}...", total=None
40-
)
37+
progress.add_task(f"Restarting services: {', '.join(service_list)}...", total=None)
4138
else:
4239
progress.add_task("Restarting all services...", total=None)
4340

0 commit comments

Comments
 (0)