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

Function patch_directory

scripts/update_lib/cmd_migrate.py:80–118  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

78
79
80def 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
121def main(argv: list[str] | None = None) -> int:

Callers 4

quickFunction · 0.90
mainFunction · 0.85

Calls 11

parse_lib_pathFunction · 0.90
sortedFunction · 0.85
patch_single_contentFunction · 0.85
printFunction · 0.50
globMethod · 0.45
is_fileMethod · 0.45
relative_toMethod · 0.45
existsMethod · 0.45
read_textMethod · 0.45
mkdirMethod · 0.45
write_textMethod · 0.45