|
11 | 11 | 2. Converts them to rust-example:: directives |
12 | 12 | 3. Optionally runs a compilation check to suggest appropriate attributes |
13 | 13 |
|
| 14 | +Supports both monolithic chapter files (*.rst) and per-guideline files (*.rst.inc). |
| 15 | +
|
14 | 16 | Usage: |
15 | 17 | # Preview changes (dry run) |
16 | 18 | uv run python scripts/migrate_rust_examples.py --dry-run |
|
56 | 58 |
|
57 | 59 |
|
58 | 60 | 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 |
61 | 77 |
|
62 | 78 |
|
63 | 79 | def extract_code_block_content(content: str, start_pos: int, base_indent: str) -> Tuple[str, int]: |
@@ -303,7 +319,7 @@ def process_file( |
303 | 319 | Process a single RST file. |
304 | 320 | |
305 | 321 | Args: |
306 | | - file_path: Path to the RST file |
| 322 | + file_path: Path to the RST file (supports .rst and .rst.inc) |
307 | 323 | dry_run: If True, don't write changes |
308 | 324 | detect_failures: Whether to detect compilation failures |
309 | 325 | prelude: Optional prelude code |
@@ -383,17 +399,17 @@ def main(): |
383 | 399 | else: |
384 | 400 | print(f"⚠️ Prelude file not found: {prelude_path}") |
385 | 401 |
|
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}") |
389 | 405 |
|
390 | 406 | if args.dry_run: |
391 | 407 | print("📋 DRY RUN - no files will be modified") |
392 | 408 |
|
393 | 409 | total_changes = 0 |
394 | 410 | files_changed = 0 |
395 | 411 |
|
396 | | - for file_path in rst_files: |
| 412 | + for file_path in all_files: |
397 | 413 | changes = process_file( |
398 | 414 | file_path, |
399 | 415 | dry_run=args.dry_run, |
|
0 commit comments