File: format_wheel_meta.py

package info (click to toggle)
xgboost 3.0.4-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 13,848 kB
  • sloc: cpp: 67,603; python: 35,537; java: 4,676; ansic: 1,426; sh: 1,352; xml: 1,226; makefile: 204; javascript: 19
file content (60 lines) | stat: -rw-r--r-- 1,868 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""
Script to generate meta.json to store metadata for a nightly build of
XGBoost Python package.
"""

import argparse
import json
import pathlib


def main(args: argparse.Namespace) -> None:
    wheel_path = pathlib.Path(args.wheel_path).expanduser().resolve()
    if not wheel_path.exists():
        raise ValueError(f"Wheel cannot be found at path {wheel_path}")
    if not wheel_path.is_file():
        raise ValueError(f"Path {wheel_path} is not a valid file")
    wheel_name = wheel_path.name

    meta_path = pathlib.Path(args.meta_path)
    if not meta_path.exists():
        raise ValueError(f"Path {meta_path} does not exist")
    if not meta_path.is_dir():
        raise ValueError(f"Path {meta_path} is not a valid directory")

    tokens = wheel_name.split("-")
    assert len(tokens) == 5
    version = tokens[1].split("+")[0]

    meta_info = {
        "wheel_path": f"{args.commit_hash}/{wheel_name}",
        "wheel_name": wheel_name,
        "platform_tag": args.platform_tag,
        "version": version,
        "commit_id": args.commit_hash,
    }
    with open(meta_path / "meta.json", "w") as f:
        json.dump(meta_info, f, indent=4)


if __name__ == "__main__":
    parser = argparse.ArgumentParser(
        description="Format meta.json encoding the latest nightly version of the Python wheel"
    )
    parser.add_argument(
        "--wheel-path", type=str, required=True, help="Path to the wheel"
    )
    parser.add_argument(
        "--commit-hash", type=str, required=True, help="Git commit hash"
    )
    parser.add_argument(
        "--platform-tag",
        type=str,
        required=True,
        help="Platform tag (e.g. manylinux_2_28_x86_64)",
    )
    parser.add_argument(
        "--meta-path", type=str, required=True, help="Directory to place meta.json"
    )
    parsed_args = parser.parse_args()
    main(parsed_args)