MCPcopy Index your code
hub / github.com/RustPython/RustPython / patch_file

Function patch_file

scripts/update_lib/cmd_migrate.py:51–77  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

49
50
51def 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
80def patch_directory(

Callers 4

quickFunction · 0.90
mainFunction · 0.85

Calls 7

parse_lib_pathFunction · 0.90
patch_single_contentFunction · 0.85
printFunction · 0.50
existsMethod · 0.45
read_textMethod · 0.45
mkdirMethod · 0.45
write_textMethod · 0.45