Skip to content

Commit a489566

Browse files
committed
chore: ruff format + full type annotations on CLI commands
- ruff format all three changed files - Add complete type annotations to all command functions: ctx: click.Context, typed params, -> Any / -> None return types - Import Optional and Any from typing - context_grounding group annotated -> None - ingest/delete return bare (no 'return None') for cleaner style - Under project mypy config: 0 errors - Under strict mypy: only 4 pre-existing get_client() untyped-call errors (same infrastructure gap as cli_buckets.py which has 17)
1 parent e408dd5 commit a489566

3 files changed

Lines changed: 250 additions & 73 deletions

File tree

src/uipath/_cli/services/cli_context_grounding.py

Lines changed: 61 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
"""
1212
# ruff: noqa: D301 - Using regular """ strings (not r""") for Click \b formatting
1313

14+
from typing import Any, Optional
15+
1416
import click
1517

1618
from .._utils._service_base import (
@@ -22,14 +24,18 @@
2224

2325

2426
def _not_found(index_name: str, e: Exception) -> None:
25-
"""Re-raise as a clean ClickException when the SDK reports index not found."""
27+
"""Raise a clean ClickException for any SDK error from context-grounding commands.
28+
29+
Surfaces "not found" as a structured error; wraps all other exceptions so
30+
raw SDK tracebacks never reach the user.
31+
"""
2632
if "not found" in str(e).lower():
2733
handle_not_found_error("Index", index_name)
2834
raise click.ClickException(str(e)) from e
2935

3036

3137
@click.group(name="context-grounding")
32-
def context_grounding():
38+
def context_grounding() -> None:
3339
"""Manage UiPath Context Grounding indexes and perform semantic search.
3440
3541
Context Grounding indexes documents from storage buckets or cloud drives
@@ -59,10 +65,19 @@ def context_grounding():
5965

6066

6167
@context_grounding.command("retrieve")
62-
@click.option("--index", "index_name", required=True, help="Name of the index to retrieve.")
68+
@click.option(
69+
"--index", "index_name", required=True, help="Name of the index to retrieve."
70+
)
6371
@common_service_options
6472
@service_command
65-
def retrieve(ctx, index_name, folder_path, folder_key, format, output):
73+
def retrieve(
74+
ctx: click.Context,
75+
index_name: str,
76+
folder_path: Optional[str],
77+
folder_key: Optional[str],
78+
format: Optional[str],
79+
output: Optional[str],
80+
) -> Any:
6681
"""Retrieve details of a context grounding index by name.
6782
6883
\b
@@ -84,7 +99,9 @@ def retrieve(ctx, index_name, folder_path, folder_key, format, output):
8499

85100
@context_grounding.command("search")
86101
@click.argument("query")
87-
@click.option("--index", "index_name", required=True, help="Name of the index to search.")
102+
@click.option(
103+
"--index", "index_name", required=True, help="Name of the index to search."
104+
)
88105
@click.option(
89106
"--results",
90107
"-n",
@@ -96,7 +113,16 @@ def retrieve(ctx, index_name, folder_path, folder_key, format, output):
96113
)
97114
@common_service_options
98115
@service_command
99-
def search(ctx, query, index_name, number_of_results, folder_path, folder_key, format, output):
116+
def search(
117+
ctx: click.Context,
118+
query: str,
119+
index_name: str,
120+
number_of_results: int,
121+
folder_path: Optional[str],
122+
folder_key: Optional[str],
123+
format: Optional[str],
124+
output: Optional[str],
125+
) -> Any:
100126
"""Search an index with a natural language query.
101127
102128
QUERY is the natural language search string.
@@ -148,10 +174,19 @@ def search(ctx, query, index_name, number_of_results, folder_path, folder_key, f
148174

149175

150176
@context_grounding.command("ingest")
151-
@click.option("--index", "index_name", required=True, help="Name of the index to re-ingest.")
177+
@click.option(
178+
"--index", "index_name", required=True, help="Name of the index to re-ingest."
179+
)
152180
@common_service_options
153181
@service_command
154-
def ingest(ctx, index_name, folder_path, folder_key, format, output):
182+
def ingest(
183+
ctx: click.Context,
184+
index_name: str,
185+
folder_path: Optional[str],
186+
folder_key: Optional[str],
187+
format: Optional[str],
188+
output: Optional[str],
189+
) -> None:
155190
"""Trigger re-ingestion of a context grounding index.
156191
157192
\b
@@ -183,16 +218,28 @@ def ingest(ctx, index_name, folder_path, folder_key, format, output):
183218
) from e
184219

185220
click.echo(f"Triggered ingestion for index '{index_name}'.", err=True)
186-
return None
187221

188222

189223
@context_grounding.command("delete")
190-
@click.option("--index", "index_name", required=True, help="Name of the index to delete.")
224+
@click.option(
225+
"--index", "index_name", required=True, help="Name of the index to delete."
226+
)
191227
@click.option("--confirm", is_flag=True, help="Skip confirmation prompt.")
192-
@click.option("--dry-run", is_flag=True, help="Show what would be deleted without deleting.")
228+
@click.option(
229+
"--dry-run", is_flag=True, help="Show what would be deleted without deleting."
230+
)
193231
@common_service_options
194232
@service_command
195-
def delete(ctx, index_name, confirm, dry_run, folder_path, folder_key, format, output):
233+
def delete(
234+
ctx: click.Context,
235+
index_name: str,
236+
confirm: bool,
237+
dry_run: bool,
238+
folder_path: Optional[str],
239+
folder_key: Optional[str],
240+
format: Optional[str],
241+
output: Optional[str],
242+
) -> None:
196243
"""Delete a context grounding index by name.
197244
198245
\b
@@ -213,12 +260,12 @@ def delete(ctx, index_name, confirm, dry_run, folder_path, folder_key, format, o
213260

214261
if dry_run:
215262
click.echo(f"Would delete index '{index_name}'.", err=True)
216-
return None
263+
return
217264

218265
if not confirm:
219266
if not click.confirm(f"Delete index '{index_name}'?"):
220267
click.echo("Deletion cancelled.", err=True)
221-
return None
268+
return
222269

223270
client.context_grounding.delete_index(
224271
index=index,
@@ -227,4 +274,3 @@ def delete(ctx, index_name, confirm, dry_run, folder_path, folder_key, format, o
227274
)
228275

229276
click.echo(f"Deleted index '{index_name}'.", err=True)
230-
return None

tests/cli/contract/test_sdk_cli_alignment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ def _get_service_group(name: str):
252252
# Nested subgroup (e.g., "buckets_files")
253253
parts = service.split("_", 1)
254254
service_group = _get_service_group(parts[0]) # Get "buckets"
255-
subgroup = service_group.commands[parts[1]] # Get "files" subgroup
255+
subgroup = service_group.commands[parts[1]] # Get "files" subgroup
256256
cli_cmd = subgroup.commands[command.replace("_", "-")]
257257
else:
258258
# Top-level service group (plain name or hyphenated like "context-grounding")

0 commit comments

Comments
 (0)