Skip to content

Commit a57f068

Browse files
committed
Merge remote-tracking branch 'origin/main' into riedgar-ms/selfask-jsonschema-01
2 parents c6aecaf + 599ab00 commit a57f068

95 files changed

Lines changed: 36988 additions & 9649 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.pre-commit-config.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ repos:
44
hooks:
55
- id: nbstripout
66
args: [--keep-output, '--extra-keys=metadata.kernelspec']
7-
files: ^doc/*\.(ipynb)$
7+
files: ^doc/.*\.ipynb$
88

99
- repo: local
1010
hooks:
@@ -13,6 +13,11 @@ repos:
1313
entry: python ./build_scripts/sanitize_notebook_paths.py
1414
language: python
1515
files: ^doc.*\.(ipynb)$
16+
- id: strip-notebook-progress-bars
17+
name: Strip Notebook Progress Bars
18+
entry: python ./build_scripts/strip_notebook_progress_bars.py
19+
language: python
20+
files: ^doc.*\.(ipynb)$
1621
- id: validate-docs
1722
name: Validate Documentation Structure
1823
entry: python ./build_scripts/validate_docs.py
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT license.
3+
4+
import json
5+
import re
6+
import sys
7+
8+
# tqdm text-mode progress bar patterns:
9+
# - "%|" separates percentage from the bar
10+
# - Block characters (━, █, ▏-▉) are used for the bar itself
11+
# - "\r" carriage returns are used for in-place updates
12+
_TQDM_PATTERNS = [
13+
re.compile(r"%\|"), # " 0%|" or " 50%|..."
14+
re.compile(r"[━█▏▎▍▌▋▊▉]"), # progress bar block characters
15+
]
16+
17+
18+
def _is_tqdm_line(line: str) -> bool:
19+
"""
20+
Check if a line is part of a tqdm progress bar output.
21+
22+
Args:
23+
line (str): A single line of text from stderr output.
24+
25+
Returns:
26+
bool: True if the line matches tqdm progress bar patterns.
27+
"""
28+
stripped = line.strip()
29+
if not stripped or stripped == "\r":
30+
# Bare carriage returns or blank lines between tqdm updates
31+
return False
32+
return any(pattern.search(line) for pattern in _TQDM_PATTERNS)
33+
34+
35+
def strip_notebook_progress_bars(file_path: str) -> bool:
36+
"""
37+
Remove tqdm progress bar outputs from notebook cell stderr streams.
38+
39+
Strips stderr stream outputs that contain tqdm progress bar patterns.
40+
If all lines in a stderr output are tqdm lines, the entire output is removed.
41+
If only some lines are tqdm, those lines are stripped and the output is kept.
42+
43+
Args:
44+
file_path (str): Path to the .ipynb file.
45+
46+
Returns:
47+
bool: True if the file was modified.
48+
"""
49+
if not file_path.endswith(".ipynb"):
50+
return False
51+
52+
with open(file_path, encoding="utf-8") as f:
53+
content = json.load(f)
54+
55+
modified = False
56+
57+
for cell in content.get("cells", []):
58+
outputs = cell.get("outputs", [])
59+
new_outputs = []
60+
61+
for output in outputs:
62+
if output.get("output_type") == "stream" and output.get("name") == "stderr":
63+
text_lines = output.get("text", [])
64+
non_tqdm_lines = [line for line in text_lines if not _is_tqdm_line(line)]
65+
66+
if len(non_tqdm_lines) < len(text_lines):
67+
modified = True
68+
# Keep output only if there are meaningful non-tqdm lines
69+
remaining = [line for line in non_tqdm_lines if line.strip()]
70+
if remaining:
71+
output["text"] = non_tqdm_lines
72+
new_outputs.append(output)
73+
# else: drop the entire output (all tqdm or only whitespace left)
74+
else:
75+
new_outputs.append(output)
76+
else:
77+
new_outputs.append(output)
78+
79+
if len(new_outputs) != len(outputs):
80+
cell["outputs"] = new_outputs
81+
82+
if not modified:
83+
return False
84+
85+
with open(file_path, "w", encoding="utf-8") as f:
86+
json.dump(content, f, indent=1, ensure_ascii=False)
87+
f.write("\n")
88+
89+
return True
90+
91+
92+
if __name__ == "__main__":
93+
modified_files = [file_path for file_path in sys.argv[1:] if strip_notebook_progress_bars(file_path)]
94+
if modified_files:
95+
print("Stripped tqdm progress bars from:", modified_files)
96+
sys.exit(1)

doc/code/auxiliary_attacks/1_gcg_azure_ml.ipynb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@
202202
"Example: azcopy copy './git/PyRIT' 'https://romanlutz0437468309.blob.core.windows.net/3f52e8b9-0bac-4c48-9e4a-a92e85a582c4-10s61nn9uso4b2p89xjypawyc7/PyRIT' \n",
203203
"\n",
204204
"See https://learn.microsoft.com/azure/storage/common/storage-use-azcopy-v10 for more information.\n",
205-
"\u001b[32mUploading PyRIT (194.65 MBs): 100%|##########| 194652493/194652493 [01:19<00:00, 2447407.71it/s] \n",
206205
"\u001b[39m\n",
207206
"\n"
208207
]

doc/code/converters/7_human_converter.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"metadata": {},
77
"source": [
88
"> ⚠️ **Deprecated:** The `HumanInTheLoopConverter` is deprecated and will be removed in PyRIT v0.13.0.\n",
9-
"> Use the React-based GUI (CoPyRIT) instead. See the [GUI documentation](../gui/0_gui.md) for details.\n",
9+
"> Use the React-based GUI (CoPyRIT) instead. See the [GUI documentation](../../gui/0_gui.md) for details.\n",
1010
"\n",
1111
"# 7. Human in the Loop Converter\n",
1212
"\n",

doc/code/converters/7_human_converter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
# %% [markdown]
1212
# > ⚠️ **Deprecated:** The `HumanInTheLoopConverter` is deprecated and will be removed in PyRIT v0.13.0.
13-
# > Use the React-based GUI (CoPyRIT) instead. See the [GUI documentation](../gui/0_gui.md) for details.
13+
# > Use the React-based GUI (CoPyRIT) instead. See the [GUI documentation](../../gui/0_gui.md) for details.
1414
#
1515
# # 7. Human in the Loop Converter
1616
#

doc/code/datasets/5_simulated_conversation.ipynb

Lines changed: 14 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"cells": [
33
{
44
"cell_type": "markdown",
5-
"id": "e88a2a30",
5+
"id": "0",
66
"metadata": {},
77
"source": [
88
"# 5. Simulated Conversations\n",
@@ -31,16 +31,9 @@
3131
},
3232
{
3333
"cell_type": "code",
34-
"execution_count": 1,
35-
"id": "0e4097b9",
36-
"metadata": {
37-
"execution": {
38-
"iopub.execute_input": "2026-04-08T14:43:58.449045Z",
39-
"iopub.status.busy": "2026-04-08T14:43:58.448892Z",
40-
"iopub.status.idle": "2026-04-08T14:44:23.536340Z",
41-
"shell.execute_reply": "2026-04-08T14:44:23.534625Z"
42-
}
43-
},
34+
"execution_count": null,
35+
"id": "1",
36+
"metadata": {},
4437
"outputs": [
4538
{
4639
"name": "stdout",
@@ -90,7 +83,7 @@
9083
},
9184
{
9285
"cell_type": "markdown",
93-
"id": "1b3f2a33",
86+
"id": "2",
9487
"metadata": {},
9588
"source": [
9689
"## Inspecting the Results\n",
@@ -104,16 +97,9 @@
10497
},
10598
{
10699
"cell_type": "code",
107-
"execution_count": 2,
108-
"id": "b6a517b3",
109-
"metadata": {
110-
"execution": {
111-
"iopub.execute_input": "2026-04-08T14:44:23.538379Z",
112-
"iopub.status.busy": "2026-04-08T14:44:23.538095Z",
113-
"iopub.status.idle": "2026-04-08T14:44:23.543978Z",
114-
"shell.execute_reply": "2026-04-08T14:44:23.542643Z"
115-
}
116-
},
100+
"execution_count": null,
101+
"id": "3",
102+
"metadata": {},
117103
"outputs": [
118104
{
119105
"name": "stdout",
@@ -183,7 +169,7 @@
183169
},
184170
{
185171
"cell_type": "markdown",
186-
"id": "8604fef5",
172+
"id": "4",
187173
"metadata": {},
188174
"source": [
189175
"## Replaying on a Different Target\n",
@@ -198,16 +184,9 @@
198184
},
199185
{
200186
"cell_type": "code",
201-
"execution_count": 3,
202-
"id": "153c5476",
203-
"metadata": {
204-
"execution": {
205-
"iopub.execute_input": "2026-04-08T14:44:23.546118Z",
206-
"iopub.status.busy": "2026-04-08T14:44:23.545878Z",
207-
"iopub.status.idle": "2026-04-08T14:45:52.821098Z",
208-
"shell.execute_reply": "2026-04-08T14:45:52.819962Z"
209-
}
210-
},
187+
"execution_count": null,
188+
"id": "5",
189+
"metadata": {},
211190
"outputs": [
212191
{
213192
"name": "stdout",
@@ -546,7 +525,7 @@
546525
},
547526
{
548527
"cell_type": "markdown",
549-
"id": "625f4681",
528+
"id": "6",
550529
"metadata": {},
551530
"source": [
552531
"> **Note:** If the Crescendo result shows `backtrack_count: 0` even on failure, this is expected.\n",
@@ -557,7 +536,7 @@
557536
},
558537
{
559538
"cell_type": "markdown",
560-
"id": "58bb69b5",
539+
"id": "7",
561540
"metadata": {},
562541
"source": [
563542
"## Key Parameters\n",
@@ -580,11 +559,6 @@
580559
}
581560
],
582561
"metadata": {
583-
"kernelspec": {
584-
"display_name": "pyrit-dev",
585-
"language": "python",
586-
"name": "pyrit-dev"
587-
},
588562
"language_info": {
589563
"codemirror_mode": {
590564
"name": "ipython",

0 commit comments

Comments
 (0)