mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-29 03:04:38 +08:00
* Preserve interpolation source text and canonical metadata Source-only checkpoint; candidate validation and the existing annotation expectation reconciliation remain pending. Assisted-by: OpenAI Codex:model version unavailable * Align existing annotation expectations with CPython metadata Update only the nine existing expected strings confirmed against pinned CPython 3.15, with explicit user approval. Assisted-by: OpenAI Codex:model version unavailable * Preserve template metadata through compilation and interactive input Escape literal debug prefixes, retain None AST expression metadata internally, and continue incomplete triple-quoted t-strings in the existing shell. Assisted-by: OpenAI Codex:model version unavailable * Classify normalized unclosed brackets as REPL line continuations Assisted-by: OpenAI Codex:model version unavailable * Nest equivalent REPL parse-error alternatives for Clippy Assisted-by: OpenAI Codex:model version unavailable * Remove fulfilled annotation migration lint workaround The canonical expected strings no longer trigger literal_string_with_formatting_args, so the previous lint expectation is obsolete. Assisted-by: OpenAI Codex:model version unavailable * Complete lazy-import exception and traceback library closure Copy canonical traceback and legacy exception mappings with preserved RustPython guards. Copy explicit non-Python library assets by exact path so exception hierarchy data does not expand into the entire test package. Assisted-by: OpenAI Codex:model version unavailable * Provide Python 3.15 traceback metadata for missing modules and attributes Preserve AttributeError context for missing class attribute deletion, matching type_update_dict. Expose canonical generated missing-stdlib messages through the native sysconfig modules without importing CPython build-specific disabled-module assumptions. Assisted-by: OpenAI Codex:model version unavailable
128 lines
3.6 KiB
Python
128 lines
3.6 KiB
Python
#!/usr/bin/env python
|
|
"""
|
|
Copy library files from CPython.
|
|
|
|
Usage:
|
|
# Single file
|
|
python scripts/update_lib copy-lib cpython/Lib/dataclasses.py
|
|
|
|
# Directory
|
|
python scripts/update_lib copy-lib cpython/Lib/json
|
|
"""
|
|
|
|
import argparse
|
|
import pathlib
|
|
import shutil
|
|
import sys
|
|
|
|
|
|
def _ignore_bytecode_caches(directory: str, names: list[str]) -> set[str]:
|
|
return {
|
|
name
|
|
for name in names
|
|
if name == "__pycache__" and (pathlib.Path(directory) / name).is_dir()
|
|
}
|
|
|
|
|
|
def _copy_single(
|
|
src_path: pathlib.Path,
|
|
lib_path: pathlib.Path,
|
|
verbose: bool = True,
|
|
) -> None:
|
|
"""Copy a single file or directory."""
|
|
# Remove existing file/directory
|
|
if lib_path.exists():
|
|
if lib_path.is_dir():
|
|
if verbose:
|
|
print(f"Removing directory: {lib_path}")
|
|
shutil.rmtree(lib_path)
|
|
else:
|
|
if verbose:
|
|
print(f"Removing file: {lib_path}")
|
|
lib_path.unlink()
|
|
|
|
# Copy
|
|
if src_path.is_dir():
|
|
if verbose:
|
|
print(f"Copying directory: {src_path} -> {lib_path}")
|
|
lib_path.parent.mkdir(parents=True, exist_ok=True)
|
|
shutil.copytree(src_path, lib_path, ignore=_ignore_bytecode_caches)
|
|
else:
|
|
if verbose:
|
|
print(f"Copying file: {src_path} -> {lib_path}")
|
|
lib_path.parent.mkdir(parents=True, exist_ok=True)
|
|
shutil.copy2(src_path, lib_path)
|
|
|
|
|
|
def copy_lib(
|
|
src_path: pathlib.Path,
|
|
verbose: bool = True,
|
|
) -> None:
|
|
"""
|
|
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
|
|
"""
|
|
from update_lib.deps import get_lib_paths
|
|
from update_lib.file_utils import parse_lib_path
|
|
|
|
# Extract module name and cpython prefix from path
|
|
path_str = str(src_path).replace("\\", "/")
|
|
if "/Lib/" not in path_str:
|
|
raise ValueError(f"Path must contain '/Lib/' (got: {src_path})")
|
|
if not src_path.exists():
|
|
raise FileNotFoundError(f"Source path does not exist: {src_path}")
|
|
|
|
# Data files name an exact asset, not the containing top-level module.
|
|
# Expanding Lib/test/data.txt as "test" would replace the entire test tree.
|
|
if src_path.is_file() and src_path.suffix != ".py":
|
|
_copy_single(src_path, parse_lib_path(src_path), verbose)
|
|
return
|
|
|
|
cpython_prefix, after_lib = path_str.split("/Lib/", 1)
|
|
# Get module name (first component, without .py)
|
|
name = after_lib.split("/")[0]
|
|
if name.endswith(".py"):
|
|
name = name[:-3]
|
|
|
|
# Get all paths to copy from DEPENDENCIES table
|
|
all_src_paths = get_lib_paths(name, cpython_prefix)
|
|
|
|
# Copy each file
|
|
for src in all_src_paths:
|
|
if src.exists():
|
|
lib_path = parse_lib_path(src)
|
|
_copy_single(src, lib_path, verbose)
|
|
|
|
|
|
def main(argv: list[str] | None = None) -> int:
|
|
parser = argparse.ArgumentParser(
|
|
description=__doc__,
|
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
)
|
|
parser.add_argument(
|
|
"path",
|
|
type=pathlib.Path,
|
|
help="Source path containing /Lib/ (e.g., cpython/Lib/dataclasses.py)",
|
|
)
|
|
|
|
args = parser.parse_args(argv)
|
|
|
|
try:
|
|
copy_lib(args.path)
|
|
return 0
|
|
except ValueError as e:
|
|
print(f"Error: {e}", file=sys.stderr)
|
|
return 1
|
|
except FileNotFoundError as e:
|
|
print(f"Error: {e}", file=sys.stderr)
|
|
return 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|