Copy library file or directory from CPython. Also copies additional files if defined in DEPENDENCIES table. Args: src_path: Source path (e.g., cpython/Lib/dataclasses.py or cpython/Lib/json) verbose: Print progress messages
(
src_path: pathlib.Path,
verbose: bool = True,
)
| 47 | |
| 48 | |
| 49 | def copy_lib( |
| 50 | src_path: pathlib.Path, |
| 51 | verbose: bool = True, |
| 52 | ) -> None: |
| 53 | """ |
| 54 | Copy library file or directory from CPython. |
| 55 | |
| 56 | Also copies additional files if defined in DEPENDENCIES table. |
| 57 | |
| 58 | Args: |
| 59 | src_path: Source path (e.g., cpython/Lib/dataclasses.py or cpython/Lib/json) |
| 60 | verbose: Print progress messages |
| 61 | """ |
| 62 | from update_lib.deps import get_lib_paths |
| 63 | from update_lib.file_utils import parse_lib_path |
| 64 | |
| 65 | # Extract module name and cpython prefix from path |
| 66 | path_str = str(src_path).replace("\\", "/") |
| 67 | if "/Lib/" not in path_str: |
| 68 | raise ValueError(f"Path must contain '/Lib/' (got: {src_path})") |
| 69 | |
| 70 | cpython_prefix, after_lib = path_str.split("/Lib/", 1) |
| 71 | # Get module name (first component, without .py) |
| 72 | name = after_lib.split("/")[0] |
| 73 | if name.endswith(".py"): |
| 74 | name = name[:-3] |
| 75 | |
| 76 | # Get all paths to copy from DEPENDENCIES table |
| 77 | all_src_paths = get_lib_paths(name, cpython_prefix) |
| 78 | |
| 79 | # Copy each file |
| 80 | for src in all_src_paths: |
| 81 | if src.exists(): |
| 82 | lib_path = parse_lib_path(src) |
| 83 | _copy_single(src, lib_path, verbose) |
| 84 | |
| 85 | |
| 86 | def main(argv: list[str] | None = None) -> int: |