Patch a single file from source to lib. Args: src_path: Source file path (e.g., cpython/Lib/test/foo.py) lib_path: Target lib path. If None, derived from src_path. verbose: Print progress messages
(
src_path: pathlib.Path,
lib_path: pathlib.Path | None = None,
verbose: bool = True,
)
| 49 | |
| 50 | |
| 51 | def patch_file( |
| 52 | src_path: pathlib.Path, |
| 53 | lib_path: pathlib.Path | None = None, |
| 54 | verbose: bool = True, |
| 55 | ) -> None: |
| 56 | """ |
| 57 | Patch a single file from source to lib. |
| 58 | |
| 59 | Args: |
| 60 | src_path: Source file path (e.g., cpython/Lib/test/foo.py) |
| 61 | lib_path: Target lib path. If None, derived from src_path. |
| 62 | verbose: Print progress messages |
| 63 | """ |
| 64 | if lib_path is None: |
| 65 | lib_path = parse_lib_path(src_path) |
| 66 | |
| 67 | if lib_path.exists(): |
| 68 | if verbose: |
| 69 | print(f"Patching: {src_path} -> {lib_path}") |
| 70 | content = patch_single_content(src_path, lib_path) |
| 71 | else: |
| 72 | if verbose: |
| 73 | print(f"Copying: {src_path} -> {lib_path}") |
| 74 | content = src_path.read_text(encoding="utf-8") |
| 75 | |
| 76 | lib_path.parent.mkdir(parents=True, exist_ok=True) |
| 77 | lib_path.write_text(content, encoding="utf-8") |
| 78 | |
| 79 | |
| 80 | def patch_directory( |