Skip to content

Commit cdbaf4b

Browse files
authored
[AVC] Resolve dependabot alerts (#15943)
* Resolve dependabot alerts. * Fix pylint
1 parent 2bc6502 commit cdbaf4b

30 files changed

Lines changed: 509 additions & 360 deletions

packages/python-packages/apiview-copilot/cli.py

Lines changed: 23 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -96,58 +96,42 @@
9696
BOLD_BLUE = BOLD + BLUE
9797

9898

99-
helps[
100-
"review"
101-
] = """
99+
helps["review"] = """
102100
type: group
103101
short-summary: Commands for creating and managing APIView reviews.
104102
"""
105103

106-
helps[
107-
"agent"
108-
] = """
104+
helps["agent"] = """
109105
type: group
110106
short-summary: Commands for interacting with the agent.
111107
"""
112108

113-
helps[
114-
"apiview"
115-
] = """
109+
helps["apiview"] = """
116110
type: group
117111
short-summary: Commands for querying APIView data.
118112
"""
119113

120-
helps[
121-
"test"
122-
] = """
114+
helps["test"] = """
123115
type: group
124116
short-summary: Commands for development and testing.
125117
"""
126118

127-
helps[
128-
"ops"
129-
] = """
119+
helps["ops"] = """
130120
type: group
131121
short-summary: Commands for deployment and infrastructure.
132122
"""
133123

134-
helps[
135-
"kb"
136-
] = """
124+
helps["kb"] = """
137125
type: group
138126
short-summary: Commands for interacting with the knowledge base.
139127
"""
140128

141-
helps[
142-
"db"
143-
] = """
129+
helps["db"] = """
144130
type: group
145131
short-summary: Commands for managing the database.
146132
"""
147133

148-
helps[
149-
"report"
150-
] = """
134+
helps["report"] = """
151135
type: group
152136
short-summary: Commands for analytics, auditing, and reporting.
153137
"""
@@ -1653,10 +1637,7 @@ def db_ingest_guidelines(
16531637
)
16541638

16551639
if result.total_memories:
1656-
print(
1657-
f"Memories: {len(result.memories_absorbed)} to absorb, "
1658-
f"{len(result.memories_retained)} to retain"
1659-
)
1640+
print(f"Memories: {len(result.memories_absorbed)} to absorb, " f"{len(result.memories_retained)} to retain")
16601641

16611642
if result.errors:
16621643
print(f"{Fore.RED}Errors ({len(result.errors)}):{RESET}")
@@ -1906,7 +1887,9 @@ def list_opened_revisions(
19061887
Queries Application Insights for reviews that had page views, then enriches
19071888
with revision metadata from Cosmos DB.
19081889
"""
1909-
data = get_opened_revisions(start_date, end_date, environment=environment, exclude_languages=exclude, created_in_window=created_in_window)
1890+
data = get_opened_revisions(
1891+
start_date, end_date, environment=environment, exclude_languages=exclude, created_in_window=created_in_window
1892+
)
19101893
_print_revision_table(data, empty_msg="No opened revisions found in the specified date range.")
19111894

19121895

@@ -2415,9 +2398,7 @@ def get_architect_comments(
24152398
params.append({"name": param_name, "value": rid})
24162399
review_query = f"SELECT c.id, c.Language FROM c WHERE ({' OR '.join(clauses)})"
24172400
review_results = list(
2418-
reviews_container.query_items(
2419-
query=review_query, parameters=params, enable_cross_partition_query=True
2420-
)
2401+
reviews_container.query_items(query=review_query, parameters=params, enable_cross_partition_query=True)
24212402
)
24222403
review_lang_map = {r["id"]: get_language_pretty_name(r.get("Language", "")) for r in review_results}
24232404

@@ -2430,19 +2411,13 @@ def get_architect_comments(
24302411
start_iso = to_iso8601(start_date)
24312412
end_iso = to_iso8601(end_date, end_of_day=True)
24322413
thread_starts = get_thread_start_dates(filtered, environment=environment)
2433-
started_in_window = {
2434-
key for key, min_created in thread_starts.items() if start_iso <= min_created <= end_iso
2435-
}
2414+
started_in_window = {key for key, min_created in thread_starts.items() if start_iso <= min_created <= end_iso}
24362415

24372416
# By default, exclude replies — keep only the thread-starting comment for threads
24382417
# that actually *started* in the date window (not merely replied to).
24392418
if not include_replies:
24402419
# Keep only comments belonging to threads that started in the window
2441-
filtered = [
2442-
c
2443-
for c in filtered
2444-
if (c.get("ThreadId") or c.get("ElementId")) in started_in_window
2445-
]
2420+
filtered = [c for c in filtered if (c.get("ThreadId") or c.get("ElementId")) in started_in_window]
24462421

24472422
# Keep only the first (earliest) comment per thread
24482423
seen_threads = {}
@@ -2466,11 +2441,7 @@ def get_architect_comments(
24662441
# When including replies, identify threads started by an approver and include
24672442
# *all* comments in those threads (not just approver-authored ones).
24682443
# First, restrict to threads that actually started in the date window.
2469-
filtered = [
2470-
c
2471-
for c in filtered
2472-
if (c.get("ThreadId") or c.get("ElementId")) in started_in_window
2473-
]
2444+
filtered = [c for c in filtered if (c.get("ThreadId") or c.get("ElementId")) in started_in_window]
24742445

24752446
if allowed_commenters is not None:
24762447
# Find who authored the earliest comment per thread
@@ -2485,20 +2456,18 @@ def get_architect_comments(
24852456
thread_earliest_in_window[thread_key] = created
24862457
thread_starters[thread_key] = c.get("CreatedBy", "")
24872458

2488-
approver_threads = {
2489-
k for k, author in thread_starters.items() if author in allowed_commenters
2490-
}
2491-
filtered = [
2492-
c
2493-
for c in filtered
2494-
if (c.get("ThreadId") or c.get("ElementId")) in approver_threads
2495-
]
2459+
approver_threads = {k for k, author in thread_starters.items() if author in allowed_commenters}
2460+
filtered = [c for c in filtered if (c.get("ThreadId") or c.get("ElementId")) in approver_threads]
24962461

24972462
comments = [APIViewComment(**c) for c in filtered]
24982463

24992464
results = [
25002465
{
2501-
**{k: v for k, v in comment.model_dump(by_alias=True, mode="json").items() if k in _APIVIEW_COMMENT_SELECT_FIELDS},
2466+
**{
2467+
k: v
2468+
for k, v in comment.model_dump(by_alias=True, mode="json").items()
2469+
if k in _APIVIEW_COMMENT_SELECT_FIELDS
2470+
},
25022471
"Language": review_lang_map.get(comment.review_id, ""),
25032472
}
25042473
for comment in comments

packages/python-packages/apiview-copilot/dev_requirements.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# regular requirements
2-
aiohttp==3.13.3
2+
aiohttp==3.14.0
33
azure-ai-agents==1.1.0
44
azure-ai-inference==1.0.0b9
55
azure-monitor-opentelemetry==1.6.7
@@ -11,27 +11,27 @@ azure-keyvault-keys==4.11.0
1111
azure-keyvault-secrets==4.10.0
1212
azure-search-documents==11.5.2
1313
beautifulsoup4==4.13.4
14-
black==25.1.0
14+
black==26.3.1
1515
colorama==0.4.6
1616
fastapi==0.121.2
1717
httpx==0.28.1
1818
knack==0.12.0
1919
matplotlib==3.10.0
2020
markdown-it-py==3.0.0
2121
openai==2.4.0
22-
python-dotenv==1.0.1
22+
python-dotenv==1.2.2
2323
pydantic==2.10.6
2424
PyJWT==2.12.0
2525
pyyaml==6.0.2
26-
pytest==7.4.2
26+
pytest==9.0.3
2727
uvicorn[standard]==0.29.0
2828

2929
# scripts requirements
3030
azure-monitor-query==2.0.0
3131

3232
# evals requirements
3333
azure-ai-evaluation==1.15.3
34-
pytest==7.4.2
34+
pytest==9.0.3
3535
tabulate==0.9.0
3636

3737
# dev requirements
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
azure-ai-evaluation==1.15.3
2-
python-dotenv==1.0.1
2+
python-dotenv==1.2.2
33
tabulate==0.9.0
44
azure-identity==1.21.0
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
aiohttp==3.13.3
1+
aiohttp==3.14.0
22
azure-ai-agents==1.1.0
33
azure-ai-inference==1.0.0b9
44
azure-monitor-opentelemetry==1.6.7
@@ -10,17 +10,17 @@ azure-keyvault-keys==4.11.0
1010
azure-keyvault-secrets==4.10.0
1111
azure-search-documents==11.5.2
1212
beautifulsoup4==4.13.4
13-
black==25.1.0
13+
black==26.3.1
1414
colorama==0.4.6
1515
fastapi==0.121.2
1616
httpx==0.28.1
1717
knack==0.12.0
1818
matplotlib==3.10.0
1919
markdown-it-py==3.0.0
2020
openai==2.4.0
21-
python-dotenv==1.0.1
21+
python-dotenv==1.2.2
2222
pydantic==2.10.6
2323
PyJWT==2.12.0
2424
pyyaml==6.0.2
25-
pytest==7.4.2
25+
pytest==9.0.3
2626
uvicorn[standard]==0.29.0

packages/python-packages/apiview-copilot/scripts/find_multi_memory_items.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ def _query_all(container, language_filter=None):
3434
else:
3535
query = "SELECT * FROM c WHERE NOT IS_DEFINED(c.isDeleted) OR c.isDeleted = false"
3636
params = None
37-
return list(
38-
container.client.query_items(query=query, parameters=params, enable_cross_partition_query=True)
39-
)
37+
return list(container.client.query_items(query=query, parameters=params, enable_cross_partition_query=True))
4038

4139

4240
def main():
4341
parser = argparse.ArgumentParser(description="Find KB items with multiple related memories.")
4442
parser.add_argument("--language", type=str, default=None, help="Filter by language (e.g. python, dotnet).")
45-
parser.add_argument("--min-memories", type=int, default=2, help="Minimum number of related memories to include (default: 2).")
43+
parser.add_argument(
44+
"--min-memories", type=int, default=2, help="Minimum number of related memories to include (default: 2)."
45+
)
4646
args = parser.parse_args()
4747

4848
db = DatabaseManager.get_instance()

packages/python-packages/apiview-copilot/src/_apiview.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -826,9 +826,7 @@ def _get_implicit_bad_comments(
826826

827827
rev_query = f"SELECT c.id, c.ChangeHistory FROM c WHERE ({' OR '.join(rev_clauses)})"
828828
rev_results = list(
829-
revisions_container.query_items(
830-
query=rev_query, parameters=rev_params, enable_cross_partition_query=True
831-
)
829+
revisions_container.query_items(query=rev_query, parameters=rev_params, enable_cross_partition_query=True)
832830
)
833831

834832
for rev in rev_results:
@@ -1207,10 +1205,7 @@ def get_opened_revisions(
12071205
date_filter = "WHERE "
12081206

12091207
query = (
1210-
"SELECT c.ReviewId, c.APIRevisionType, c.Language "
1211-
"FROM c "
1212-
f"{date_filter}"
1213-
f"({' OR '.join(clauses)})"
1208+
"SELECT c.ReviewId, c.APIRevisionType, c.Language " "FROM c " f"{date_filter}" f"({' OR '.join(clauses)})"
12141209
)
12151210

12161211
revisions.extend(

packages/python-packages/apiview-copilot/src/_apiview_metrics.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -400,9 +400,7 @@ def build_compliance_reports(
400400
month_end_iso = to_iso8601(end.isoformat(), end_of_day=True)
401401

402402
# Filter revisions to this month's window
403-
month_revisions = [
404-
rev for rev in all_revisions if month_start_iso <= rev.get("CreatedOn", "") <= month_end_iso
405-
]
403+
month_revisions = [rev for rev in all_revisions if month_start_iso <= rev.get("CreatedOn", "") <= month_end_iso]
406404

407405
# Group by ReviewId and keep only the latest revision per review
408406
latest_by_review: dict[str, dict] = {}
@@ -460,7 +458,9 @@ def build_compliance_reports(
460458
"non_compliant": 0,
461459
"total": 0,
462460
"pct": 0.0,
463-
"buckets": {t: {"compliant": 0, "non_compliant": 0, "total": 0, "pct": 0.0} for t in _KNOWN_REVISION_TYPES},
461+
"buckets": {
462+
t: {"compliant": 0, "non_compliant": 0, "total": 0, "pct": 0.0} for t in _KNOWN_REVISION_TYPES
463+
},
464464
},
465465
)
466466
buckets = entry["buckets"]

packages/python-packages/apiview-copilot/src/_comment_bucket_trends.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,7 @@ def _build_language_comment_bucket_point(
127127
deleted_count = segment.deleted_ai_comment_count or 0
128128

129129
total_included = (
130-
good_count
131-
+ implicit_good_count
132-
+ neutral_count
133-
+ human_count
134-
+ implicit_bad_count
135-
+ bad_count
136-
+ deleted_count
130+
good_count + implicit_good_count + neutral_count + human_count + implicit_bad_count + bad_count + deleted_count
137131
)
138132

139133
good_percentage = _to_percentage(good_count, total_included)
@@ -243,8 +237,7 @@ def build_language_comment_bucket_reports(
243237
# Apply generic filter: keep non-AI comments as-is, filter AI comments by IsGeneric
244238
if generic_filter is not None:
245239
filtered_comments = [
246-
c for c in non_diag
247-
if c.get("CommentSource") != "AIGenerated" or bool(c.get("IsGeneric")) == generic_filter
240+
c for c in non_diag if c.get("CommentSource") != "AIGenerated" or bool(c.get("IsGeneric")) == generic_filter
248241
]
249242
else:
250243
filtered_comments = non_diag
@@ -295,8 +288,7 @@ def _query_items_by_id_batches(
295288
for start_index in range(0, len(ordered_ids), batch_size):
296289
id_batch = ordered_ids[start_index : start_index + batch_size]
297290
params = [
298-
{"name": f"@{id_parameter_prefix}_{index}", "value": item_id}
299-
for index, item_id in enumerate(id_batch)
291+
{"name": f"@{id_parameter_prefix}_{index}", "value": item_id} for index, item_id in enumerate(id_batch)
300292
]
301293
clauses = [f"c.id = @{id_parameter_prefix}_{index}" for index in range(len(id_batch))]
302294
query = f"SELECT {select_clause} FROM c WHERE ({' OR '.join(clauses)})"
@@ -588,7 +580,6 @@ def generate_comment_bucket_chart(
588580
return output_path
589581

590582

591-
592583
def print_comment_bucket_report(
593584
reports: dict[str, list[dict]],
594585
output_path: Optional[Path],

packages/python-packages/apiview-copilot/src/_database_manager.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,8 @@ def save_memory_with_links(
376376
# Track successful writes so we can undo them on failure.
377377
# - New items (examples, memory): rollback = soft-delete
378378
# - Existing items (guidelines): rollback = restore snapshot
379-
saved_new_items = [] # (container, id) for new items to soft-delete
380-
saved_guideline_ids = [] # DB-format IDs of guidelines we updated
379+
saved_new_items = [] # (container, id) for new items to soft-delete
380+
saved_guideline_ids = [] # DB-format IDs of guidelines we updated
381381

382382
def _rollback(error_msg: str):
383383
"""Best-effort undo of all successful writes."""
@@ -391,8 +391,10 @@ def _rollback(error_msg: str):
391391
self.guidelines.client.upsert_item(guideline_snapshots[g_db_id])
392392
except Exception as rb_err:
393393
print(f"Rollback warning: failed to restore guideline {g_db_id}: {rb_err}")
394-
print(f"Rolled back {len(saved_new_items)} new item(s) and "
395-
f"{len(saved_guideline_ids)} guideline update(s) after error: {error_msg}")
394+
print(
395+
f"Rolled back {len(saved_new_items)} new item(s) and "
396+
f"{len(saved_guideline_ids)} guideline update(s) after error: {error_msg}"
397+
)
396398

397399
# 1. Examples (new items)
398400
for example in examples:

packages/python-packages/apiview-copilot/src/_github_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def resolve_owner(production_owner: str = "Azure", staging_owner: Optional[str]
8787
Production traffic targets ``production_owner`` (default
8888
``Azure``); every other environment (local, staging, preview)
8989
targets the staging owner so test runs do not pollute the real
90-
repo.
90+
repo.
9191
"""
9292
if os.getenv("ENVIRONMENT_NAME") == "production":
9393
return production_owner

0 commit comments

Comments
 (0)