Patch all files in a directory from source to lib. Args: src_dir: Source directory path (e.g., cpython/Lib/test/test_foo/) lib_dir: Target lib directory. If None, derived from src_dir. verbose: Print progress messages
(
src_dir: pathlib.Path,
lib_dir: pathlib.Path | None = None,
verbose: bool = True,
)
| 78 | |
| 79 | |
| 80 | def patch_directory( |
| 81 | src_dir: pathlib.Path, |
| 82 | lib_dir: pathlib.Path | None = None, |
| 83 | verbose: bool = True, |
| 84 | ) -> None: |
| 85 | """ |
| 86 | Patch all files in a directory from source to lib. |
| 87 | |
| 88 | Args: |
| 89 | src_dir: Source directory path (e.g., cpython/Lib/test/test_foo/) |
| 90 | lib_dir: Target lib directory. If None, derived from src_dir. |
| 91 | verbose: Print progress messages |
| 92 | """ |
| 93 | if lib_dir is None: |
| 94 | lib_dir = parse_lib_path(src_dir) |
| 95 | |
| 96 | src_files = sorted(f for f in src_dir.glob("**/*") if f.is_file()) |
| 97 | |
| 98 | for src_file in src_files: |
| 99 | rel_path = src_file.relative_to(src_dir) |
| 100 | lib_file = lib_dir / rel_path |
| 101 | |
| 102 | if src_file.suffix == ".py": |
| 103 | if lib_file.exists(): |
| 104 | if verbose: |
| 105 | print(f"Patching: {src_file} -> {lib_file}") |
| 106 | content = patch_single_content(src_file, lib_file) |
| 107 | else: |
| 108 | if verbose: |
| 109 | print(f"Copying: {src_file} -> {lib_file}") |
| 110 | content = src_file.read_text(encoding="utf-8") |
| 111 | |
| 112 | lib_file.parent.mkdir(parents=True, exist_ok=True) |
| 113 | lib_file.write_text(content, encoding="utf-8") |
| 114 | else: |
| 115 | if verbose: |
| 116 | print(f"Copying: {src_file} -> {lib_file}") |
| 117 | lib_file.parent.mkdir(parents=True, exist_ok=True) |
| 118 | shutil.copy2(src_file, lib_file) |
| 119 | |
| 120 | |
| 121 | def main(argv: list[str] | None = None) -> int: |