8000 lib_updater --quick-upgrade by youknowone · Pull Request #6695 · RustPython/RustPython · GitHub
[go: up one dir, main page]

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions scripts/lib_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@
__doc__ = """
This tool helps with updating test files from CPython.

Quick Upgrade
-------------
./{fname} --quick-upgrade cpython/Lib/test/test_threading.py
./{fname} --quick-upgrade ../somewhere/Lib/threading.py

Any path containing `/Lib/` will auto-detect the target:
-> Extracts patches from Lib/... (auto-detected from path)
-> Applies them to the source file
-> Writes result to Lib/...

Examples
--------
To move the patches found in `Lib/test/foo.py` to ` ~/cpython/Lib/test/foo.py` then write the contents back to `Lib/test/foo.py`
To move the patches found in `Lib/test/foo.py` to `~/cpython/Lib/test/foo.py` then write the contents back to `Lib/test/foo.py`

>>> ./{fname} --from Lib/test/foo.py --to ~/cpython/Lib/test/foo.py -o Lib/test/foo.py

Expand Down Expand Up @@ -288,6 +298,12 @@ def build_argparse() -> argparse.ArgumentParser:
)

patches_group = parser.add_mutually_exclusive_group(required=True)
patches_group.add_argument(
"--quick-upgrade",
help="Quick upgrade: path containing /Lib/ (e.g., cpython/Lib/test/foo.py)",
type=pathlib.Path,
metavar="PATH",
)
patches_group.add_argument(
"-p",
"--patches",
Expand All @@ -301,7 +317,7 @@ def build_argparse() -> argparse.ArgumentParser:
type=pathlib.Path,
)

group = parser.add_mutually_exclusive_group(required=True)
group = parser.add_mutually_exclusive_group(required=False)
group.add_argument(
"--to",
help="File to apply patches to",
Expand All @@ -322,6 +338,28 @@ def build_argparse() -> argparse.ArgumentParser:
parser = build_argparse()
args = parser.parse_args()

# Quick upgrade: auto-fill --from, --to, -o from path
if args.quick_upgrade is not None:
path_str = str(args.quick_upgrade)
lib_marker = "/Lib/"

if lib_marker not in path_str:
parser.error(f"--quick-upgrade path must contain '/Lib/' (got: {path_str})")

idx = path_str.index(lib_marker)
lib_path = pathlib.Path(path_str[idx + 1 :])

args.gather_from = lib_path
args.to = args.quick_upgrade
if args.output == "-":
args.output = str(lib_path)

# Validate required arguments
if args.patches is None and args.gather_from is None:
parser.error("--from or --patches is required (or use --quick-upgrade)")
if args.to is None and not args.show_patches:
parser.error("--to or --show-patches is required")

if args.patches:
patches = {
cls_name: {
Expand Down
Loading
0