Skip to content

Commit 210a31f

Browse files
abrichrclaude
andcommitted
fix(cli): resolve ruff linter errors
- Replace bare `except:` with `except Exception:` - Remove unused f-string prefixes - Remove unused variable assignments - Remove unused imports Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent fea0a10 commit 210a31f

1 file changed

Lines changed: 37 additions & 42 deletions

File tree

openadapt_ml/benchmarks/cli.py

Lines changed: 37 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ def cmd_pool_create(args):
783783
working_region = region
784784
working_cost = cost
785785
# Delete the test VM and wait for completion
786-
log("POOL", f" Found working combo, cleaning up test VM...")
786+
log("POOL", " Found working combo, cleaning up test VM...")
787787
subprocess.run(
788788
["az", "vm", "delete", "-g", RESOURCE_GROUP, "-n", test_name, "--yes", "--force-deletion", "true"],
789789
capture_output=True,
@@ -1089,7 +1089,7 @@ def start_container(worker) -> tuple[str, bool, str]:
10891089
workers_ready.append(worker)
10901090
del workers_pending[name]
10911091
registry.update_worker(name, waa_ready=True, status="ready")
1092-
except Exception as e:
1092+
except Exception:
10931093
pass # Keep trying
10941094

10951095
if workers_pending:
@@ -1494,7 +1494,6 @@ def cmd_pool_logs(args):
14941494
Shows Docker container logs from each worker with [worker-name] prefix.
14951495
Use Ctrl+C to stop.
14961496
"""
1497-
import sys
14981497
import threading
14991498
from queue import Queue, Empty
15001499

@@ -1516,7 +1515,7 @@ def cmd_pool_logs(args):
15161515

15171516
pool_id = pool.get("pool_id", "unknown")
15181517
print(f"[pool-logs] Streaming logs from {len(workers)} workers (pool: {pool_id})")
1519-
print(f"[pool-logs] Press Ctrl+C to stop\n", flush=True)
1518+
print("[pool-logs] Press Ctrl+C to stop\n", flush=True)
15201519

15211520
# Queue for collecting output from all workers
15221521
output_queue = Queue()
@@ -2041,10 +2040,10 @@ def cmd_start(args):
20412040
log("START", "Starting container with VERSION=11e...")
20422041

20432042
# Get agent and model from args (defaults match WAA defaults)
2044-
agent = getattr(args, "agent", "navi")
2045-
model = getattr(args, "model", "gpt-4o")
2046-
som_origin = getattr(args, "som_origin", "oss")
2047-
a11y_backend = getattr(args, "a11y_backend", "uia")
2043+
getattr(args, "agent", "navi")
2044+
getattr(args, "model", "gpt-4o")
2045+
getattr(args, "som_origin", "oss")
2046+
getattr(args, "a11y_backend", "uia")
20482047

20492048
# The vanilla windowsarena/winarena:latest image uses --entrypoint /bin/bash
20502049
# and requires entry.sh as the command argument
@@ -2210,20 +2209,20 @@ def cmd_test_golden_image(args):
22102209

22112210
if "FAIL" not in result.stdout and result.stdout.strip():
22122211
elapsed = time.time() - start_time
2213-
log("TEST", f"")
2214-
log("TEST", f"✅ GOLDEN IMAGE TEST PASSED")
2212+
log("TEST", "")
2213+
log("TEST", "✅ GOLDEN IMAGE TEST PASSED")
22152214
log("TEST", f" Boot time: {elapsed:.1f} seconds")
22162215
log("TEST", f" Image size: {image_size}")
22172216
log("TEST", f" Response: {result.stdout.strip()[:80]}")
22182217
return 0
22192218

22202219
elapsed = time.time() - start_time
22212220
if elapsed > timeout:
2222-
log("TEST", f"")
2223-
log("TEST", f"❌ GOLDEN IMAGE TEST FAILED")
2221+
log("TEST", "")
2222+
log("TEST", "❌ GOLDEN IMAGE TEST FAILED")
22242223
log("TEST", f" WAA server did not respond after {timeout}s")
2225-
log("TEST", f" This may indicate a corrupted golden image")
2226-
log("TEST", f" Try: cli.py start --fresh # to create new golden image")
2224+
log("TEST", " This may indicate a corrupted golden image")
2225+
log("TEST", " Try: cli.py start --fresh # to create new golden image")
22272226
return 1
22282227

22292228
# Progress display
@@ -2289,7 +2288,7 @@ def cmd_test_blob_access(args):
22892288
if "NOT_FOUND" in result.stdout:
22902289
log("TEST-BLOB", f"❌ Storage account '{storage_account}' not found or not accessible")
22912290
return 1
2292-
log("TEST-BLOB", f" ✓ Storage account accessible")
2291+
log("TEST-BLOB", " ✓ Storage account accessible")
22932292

22942293
# Check container exists - try candidates in order
22952294
log("TEST-BLOB", "3. Checking for usable container...")
@@ -2306,7 +2305,7 @@ def cmd_test_blob_access(args):
23062305
break
23072306

23082307
if not container_name:
2309-
log("TEST-BLOB", f"❌ No suitable container found")
2308+
log("TEST-BLOB", "❌ No suitable container found")
23102309
log("TEST-BLOB", f" Available: {available_containers}")
23112310
log("TEST-BLOB", f" Create one with: az storage container create --name waa-golden-images --account-name {storage_account}")
23122311
return 1
@@ -2325,7 +2324,7 @@ def cmd_test_blob_access(args):
23252324
if not blob_output or "Name" not in blob_output:
23262325
log("TEST-BLOB", " ⚠ Container is empty (no golden image uploaded yet)")
23272326
else:
2328-
log("TEST-BLOB", f" ✓ Blobs found:")
2327+
log("TEST-BLOB", " ✓ Blobs found:")
23292328
for line in blob_output.split("\n")[:10]: # Show first 10
23302329
log("TEST-BLOB", f" {line}")
23312330

@@ -2383,7 +2382,7 @@ def cmd_test_api_key(args):
23832382

23842383
if response.status_code == 200:
23852384
log("TEST-API", "✅ API KEY TEST PASSED")
2386-
log("TEST-API", f" Model: gpt-4o-mini responded successfully")
2385+
log("TEST-API", " Model: gpt-4o-mini responded successfully")
23872386
return 0
23882387
elif response.status_code == 401:
23892388
log("TEST-API", "❌ API KEY INVALID (401 Unauthorized)")
@@ -2439,7 +2438,7 @@ def cmd_test_waa_tasks(args):
24392438
if "NOT_FOUND" in result.stdout:
24402439
log("TEST-TASKS", "❌ Task directory not found")
24412440
return 1
2442-
log("TEST-TASKS", f"Task files found:")
2441+
log("TEST-TASKS", "Task files found:")
24432442
for line in result.stdout.strip().split("\n")[:10]:
24442443
log("TEST-TASKS", f" {line}")
24452444
else:
@@ -3819,7 +3818,6 @@ def check_golden_image_in_blob(storage_account: str, storage_key: str, blob_cont
38193818
# Check for required files (only data.img is truly required, OVMF files come from Docker image)
38203819
# windows.vars contains UEFI variables for the specific Windows install
38213820
required_files = ["data.img"]
3822-
optional_files = ["windows.vars", "windows.ver", "windows.rom", "windows.mac", "windows.base"]
38233821
found_files = [f["name"].replace("storage/", "") for f in files]
38243822
has_required = all(rf in found_files for rf in required_files)
38253823

@@ -4527,7 +4525,7 @@ def show_azure_ml_resources() -> dict:
45274525
code_share = get_azure_ml_file_share_name()
45284526
if code_share:
45294527
log("AZURE-ML", f" Share: {code_share}")
4530-
log("AZURE-ML", f" - Users/openadapt/compute-instance-startup.sh")
4528+
log("AZURE-ML", " - Users/openadapt/compute-instance-startup.sh")
45314529
result["file_share_files"].append("Users/openadapt/compute-instance-startup.sh")
45324530
else:
45334531
log("AZURE-ML", " (not found)")
@@ -4599,7 +4597,7 @@ def teardown_azure_ml_resources(confirm: bool = False, keep_image: bool = False)
45994597
log("AZURE-ML", "")
46004598
log("AZURE-ML", " File Share:")
46014599
if code_share:
4602-
log("AZURE-ML", f" - Users/openadapt/compute-instance-startup.sh")
4600+
log("AZURE-ML", " - Users/openadapt/compute-instance-startup.sh")
46034601
else:
46044602
log("AZURE-ML", " (none)")
46054603

@@ -4723,7 +4721,7 @@ def cmd_run_azure_ml_auto(args):
47234721
skip_benchmark = getattr(args, "skip_benchmark", False)
47244722
fast_vm = getattr(args, "fast", False)
47254723

4726-
log("AUTO", f"Configuration:")
4724+
log("AUTO", "Configuration:")
47274725
log("AUTO", f" Workers: {num_workers}")
47284726
log("AUTO", f" Setup timeout: {timeout_minutes} min")
47294727
log("AUTO", f" Probe timeout: {probe_timeout} sec")
@@ -4742,7 +4740,7 @@ def cmd_run_azure_ml_auto(args):
47424740
if state and "running" in state.lower():
47434741
log("AUTO", f" VM already running at {ip}")
47444742
elif state and "deallocated" in state.lower():
4745-
log("AUTO", f" VM deallocated, starting...")
4743+
log("AUTO", " VM deallocated, starting...")
47464744
result = subprocess.run(
47474745
["az", "vm", "start", "-g", RESOURCE_GROUP, "-n", VM_NAME],
47484746
capture_output=True,
@@ -4866,7 +4864,7 @@ class CreateArgs:
48664864
# Step 3: Wait for WAA server to become ready
48674865
# =========================================================================
48684866
log("AUTO", "[Step 3/5] Waiting for WAA server...")
4869-
log("AUTO", f" (This may take 15-20 minutes on first run)")
4867+
log("AUTO", " (This may take 15-20 minutes on first run)")
48704868
log("AUTO", f" Timeout: {probe_timeout} seconds")
48714869

48724870
probe_start = time.time()
@@ -5016,7 +5014,7 @@ class CreateArgs:
50165014
result = subprocess.run(cmd, cwd=waa_scripts)
50175015

50185016
if result.returncode != 0:
5019-
log("AUTO", f" ERROR: run_azure.py failed")
5017+
log("AUTO", " ERROR: run_azure.py failed")
50205018
return 1
50215019

50225020
# =========================================================================
@@ -5883,7 +5881,7 @@ def find_best_region_for_vm(vm_size: str, min_vcpus: int = 8, preferred_regions:
58835881
"warning": warning
58845882
}
58855883

5886-
except Exception as e:
5884+
except Exception:
58875885
continue
58885886

58895887
# No ideal region found - return best available
@@ -6196,7 +6194,6 @@ def cmd_azure_ml_monitor(args):
61966194

61976195
# Set up VNC if requested
61986196
vnc_port = 8007
6199-
tunnel_proc = None
62006197

62016198
if auto_vnc:
62026199
# Find compute instance for this job
@@ -6350,7 +6347,6 @@ def cmd_azure_ml_logs(args):
63506347
log("AZURE-ML-LOGS", "=" * 60)
63516348

63526349
last_size = 0
6353-
process = None
63546350

63556351
try:
63566352
while True:
@@ -6388,7 +6384,7 @@ def cmd_azure_ml_logs(args):
63886384
# Clean up temp file
63896385
try:
63906386
os.unlink(temp_file)
6391-
except:
6387+
except Exception:
63926388
pass
63936389

63946390
if not follow:
@@ -6591,7 +6587,7 @@ def download_blob(blob_name: str, local_path: str) -> bool:
65916587
log("PROGRESS", f"Last: {progress['messages'][-1].get('text', '')}")
65926588
last_progress = progress.copy()
65936589
log("STREAM", "")
6594-
except Exception as e:
6590+
except Exception:
65956591
pass # Progress file may be partially written
65966592

65976593
# Show events if requested
@@ -6604,10 +6600,10 @@ def download_blob(blob_name: str, local_path: str) -> bool:
66046600
try:
66056601
event = json.loads(line.strip())
66066602
log("EVENT", f"{event['type']}: {json.dumps(event.get('data', {}))}")
6607-
except:
6603+
except Exception:
66086604
pass
66096605
last_event_count = len(lines)
6610-
except:
6606+
except Exception:
66116607
pass
66126608

66136609
# Show log content (default)
@@ -6620,7 +6616,7 @@ def download_blob(blob_name: str, local_path: str) -> bool:
66206616
new_content = content[last_log_size:]
66216617
print(new_content, end='', flush=True)
66226618
last_log_size = len(content)
6623-
except:
6619+
except Exception:
66246620
pass
66256621

66266622
# If no logs available yet
@@ -6631,7 +6627,7 @@ def download_blob(blob_name: str, local_path: str) -> bool:
66316627
try:
66326628
job = ml_client.jobs.get(job_name)
66336629
status = job.status
6634-
except:
6630+
except Exception:
66356631
status = "Unknown"
66366632

66376633
if not follow:
@@ -6762,11 +6758,11 @@ def show_progress():
67626758
print(f"Last Update: {progress.get('last_update', 'N/A')}")
67636759

67646760
if progress.get('messages'):
6765-
print(f"\nRecent Messages:")
6761+
print("\nRecent Messages:")
67666762
for msg in progress['messages'][-5:]:
67676763
print(f" {msg.get('time', '')} - {msg.get('text', '')}")
67686764
return
6769-
except Exception as e:
6765+
except Exception:
67706766
# If can't download, just show job status
67716767
pass
67726768

@@ -6778,7 +6774,7 @@ def show_progress():
67786774

67796775
try:
67806776
if watch:
6781-
log("PROGRESS", f"Watching progress (Ctrl+C to stop)")
6777+
log("PROGRESS", "Watching progress (Ctrl+C to stop)")
67826778
while True:
67836779
show_progress()
67846780

@@ -6788,7 +6784,7 @@ def show_progress():
67886784
if job.status in ["Completed", "Failed", "Canceled"]:
67896785
print(f"\nJob {job.status}")
67906786
break
6791-
except:
6787+
except Exception:
67926788
pass
67936789

67946790
time.sleep(poll_interval)
@@ -6862,7 +6858,6 @@ def cmd_azure_ml_delete_compute(args):
68626858
uv run python -m openadapt_ml.benchmarks.cli azure-ml-delete-compute --all # Deletes all instances
68636859
"""
68646860
init_logging()
6865-
from openadapt_ml.config import settings
68666861

68676862
compute_name = getattr(args, "name", None)
68686863
delete_all = getattr(args, "all", False)
@@ -7129,7 +7124,7 @@ def cmd_azure_ml_cost(args):
71297124
log("COST", f" {name}")
71307125
log("COST", f" Status: {state}")
71317126
log("COST", f" Size: {vm_size} (${hourly_rate:.2f}/hr)")
7132-
log("COST", f" Created: (unknown)")
7127+
log("COST", " Created: (unknown)")
71337128

71347129
log("COST", "=" * 60)
71357130
log("COST", f"Total Running Cost: ${total_cost:.2f}")
@@ -7265,7 +7260,7 @@ def cmd_azure_ml_teardown(args):
72657260
text=True,
72667261
)
72677262
if result.returncode == 0:
7268-
log("TEARDOWN", f"Resource group deletion initiated (async)")
7263+
log("TEARDOWN", "Resource group deletion initiated (async)")
72697264
else:
72707265
log("TEARDOWN", f"Failed to delete resource group: {result.stderr}")
72717266

0 commit comments

Comments
 (0)