Patch content without writing to disk. Args: src_path: Source file path (e.g., cpython/Lib/test/foo.py) lib_path: Lib path to extract patches from (e.g., Lib/test/foo.py) Returns: The patched content.
(
src_path: pathlib.Path,
lib_path: pathlib.Path,
)
| 22 | |
| 23 | |
| 24 | def patch_single_content( |
| 25 | src_path: pathlib.Path, |
| 26 | lib_path: pathlib.Path, |
| 27 | ) -> str: |
| 28 | """ |
| 29 | Patch content without writing to disk. |
| 30 | |
| 31 | Args: |
| 32 | src_path: Source file path (e.g., cpython/Lib/test/foo.py) |
| 33 | lib_path: Lib path to extract patches from (e.g., Lib/test/foo.py) |
| 34 | |
| 35 | Returns: |
| 36 | The patched content. |
| 37 | """ |
| 38 | from update_lib import apply_patches, extract_patches |
| 39 | |
| 40 | # Extract patches from existing file (if exists) |
| 41 | if lib_path.exists(): |
| 42 | patches = extract_patches(lib_path.read_text(encoding="utf-8")) |
| 43 | else: |
| 44 | patches = {} |
| 45 | |
| 46 | # Apply patches to source content |
| 47 | src_content = src_path.read_text(encoding="utf-8") |
| 48 | return apply_patches(src_content, patches) |
| 49 | |
| 50 | |
| 51 | def patch_file( |