Skip to content

Commit 79d9f17

Browse files
committed
fix: update migrate_rust_examples.py to handle separate guidelines
1 parent d7864ab commit 79d9f17

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

scripts/migrate_rust_examples.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
2. Converts them to rust-example:: directives
1212
3. Optionally runs a compilation check to suggest appropriate attributes
1313
14+
Supports both monolithic chapter files (*.rst) and per-guideline files (*.rst.inc).
15+
1416
Usage:
1517
# Preview changes (dry run)
1618
uv run python scripts/migrate_rust_examples.py --dry-run
@@ -56,8 +58,22 @@
5658

5759

5860
def find_rst_files(src_dir: Path) -> List[Path]:
59-
"""Find all RST files in the source directory."""
60-
return list(src_dir.glob("**/*.rst"))
61+
"""
62+
Find all RST files in the source directory.
63+
64+
Searches for both:
65+
- *.rst files (chapter index files, monolithic chapter files)
66+
- *.rst.inc files (per-guideline include files)
67+
68+
Args:
69+
src_dir: Directory to search
70+
71+
Returns:
72+
List of Path objects for all RST files found
73+
"""
74+
rst_files = list(src_dir.glob("**/*.rst"))
75+
rst_inc_files = list(src_dir.glob("**/*.rst.inc"))
76+
return rst_files + rst_inc_files
6177

6278

6379
def extract_code_block_content(content: str, start_pos: int, base_indent: str) -> Tuple[str, int]:
@@ -303,7 +319,7 @@ def process_file(
303319
Process a single RST file.
304320
305321
Args:
306-
file_path: Path to the RST file
322+
file_path: Path to the RST file (supports .rst and .rst.inc)
307323
dry_run: If True, don't write changes
308324
detect_failures: Whether to detect compilation failures
309325
prelude: Optional prelude code
@@ -383,17 +399,17 @@ def main():
383399
else:
384400
print(f"⚠️ Prelude file not found: {prelude_path}")
385401

386-
# Find and process RST files
387-
rst_files = find_rst_files(src_dir)
388-
print(f"🔍 Found {len(rst_files)} RST files in {src_dir}")
402+
# Find and process RST files (both .rst and .rst.inc)
403+
all_files = find_rst_files(src_dir)
404+
print(f"🔍 Found {len(all_files)} RST files in {src_dir}")
389405

390406
if args.dry_run:
391407
print("📋 DRY RUN - no files will be modified")
392408

393409
total_changes = 0
394410
files_changed = 0
395411

396-
for file_path in rst_files:
412+
for file_path in all_files:
397413
changes = process_file(
398414
file_path,
399415
dry_run=args.dry_run,

0 commit comments

Comments
 (0)