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

Function main

scripts/update_lib/cmd_patches.py:33–102  ·  view source on GitHub ↗
(argv: list[str] | None = None)

Source from the content-addressed store, hash-verified

31
32
33def main(argv: list[str] | None = None) -> int:
34 from update_lib import (
35 apply_patches,
36 extract_patches,
37 patches_from_json,
38 patches_to_json,
39 )
40
41 parser = argparse.ArgumentParser(
42 description=__doc__,
43 formatter_class=argparse.RawDescriptionHelpFormatter,
44 )
45
46 patches_group = parser.add_mutually_exclusive_group(required=True)
47 patches_group.add_argument(
48 "-p",
49 "--patches",
50 type=pathlib.Path,
51 help="File path to file containing patches in a JSON format",
52 )
53 patches_group.add_argument(
54 "--from",
55 dest="gather_from",
56 type=pathlib.Path,
57 help="File to gather patches from",
58 )
59
60 group = parser.add_mutually_exclusive_group(required=False)
61 group.add_argument(
62 "--to",
63 type=pathlib.Path,
64 help="File to apply patches to",
65 )
66 group.add_argument(
67 "--show-patches",
68 action="store_true",
69 help="Show the patches and exit",
70 )
71
72 parser.add_argument(
73 "-o",
74 "--output",
75 default="-",
76 help="Output file. Set to '-' for stdout",
77 )
78
79 args = parser.parse_args(argv)
80
81 # Validate required arguments
82 if args.to is None and not args.show_patches:
83 parser.error("--to or --show-patches is required")
84
85 try:
86 if args.patches:
87 patches = patches_from_json(json.loads(args.patches.read_text()))
88 else:
89 patches = extract_patches(args.gather_from.read_text())
90

Callers 1

cmd_patches.pyFile · 0.70

Calls 13

parse_argsMethod · 0.95
errorMethod · 0.95
patches_from_jsonFunction · 0.90
extract_patchesFunction · 0.90
patches_to_jsonFunction · 0.90
apply_patchesFunction · 0.90
write_outputFunction · 0.85
printFunction · 0.50
add_argumentMethod · 0.45
loadsMethod · 0.45
read_textMethod · 0.45

Tested by

no test coverage detected