xref: /aosp_15_r20/external/bazelbuild-rules_python/python/private/py_wheel_dist.py (revision 60517a1edbc8ecf509223e9af94a7adec7d736b8)
1"""A utility for generating the output directory for `py_wheel_dist`."""
2
3import argparse
4import shutil
5from pathlib import Path
6
7
8def parse_args() -> argparse.Namespace:
9    """Parse command line arguments."""
10    parser = argparse.ArgumentParser()
11
12    parser.add_argument(
13        "--wheel", type=Path, required=True, help="The path to a wheel."
14    )
15    parser.add_argument(
16        "--name_file",
17        type=Path,
18        required=True,
19        help="A file containing the sanitized name of the wheel.",
20    )
21    parser.add_argument(
22        "--output",
23        type=Path,
24        required=True,
25        help="The output location to copy the wheel to.",
26    )
27
28    return parser.parse_args()
29
30
31def main() -> None:
32    """The main entrypoint."""
33    args = parse_args()
34
35    wheel_name = args.name_file.read_text(encoding="utf-8").strip()
36    args.output.mkdir(exist_ok=True, parents=True)
37    shutil.copyfile(args.wheel, args.output / wheel_name)
38
39
40if __name__ == "__main__":
41    main()
42