Merge tag 'pull-nbd-2024-08-26' of https://repo.or.cz/qemu/ericb into staging
[qemu/armbru.git] / python / scripts / vendor.py
blob07aff97ccad4f6fdbaa1de284174909821e01bf9
1 #!/usr/bin/env python3
2 """
3 vendor - QEMU python vendoring utility
5 usage: vendor [-h]
7 QEMU python vendoring utility
9 options:
10 -h, --help show this help message and exit
11 """
13 # Copyright (C) 2023 Red Hat, Inc.
15 # Authors:
16 # John Snow <jsnow@redhat.com>
18 # This work is licensed under the terms of the GNU GPL, version 2 or
19 # later. See the COPYING file in the top-level directory.
21 import argparse
22 import os
23 from pathlib import Path
24 import subprocess
25 import sys
26 import tempfile
29 def main() -> int:
30 """Run the vendoring utility. See module-level docstring."""
31 loud = False
32 if os.environ.get("DEBUG") or os.environ.get("V"):
33 loud = True
35 # No options or anything for now, but I guess
36 # you'll figure that out when you run --help.
37 parser = argparse.ArgumentParser(
38 prog="vendor",
39 description="QEMU python vendoring utility",
41 parser.parse_args()
43 packages = {
44 "meson==1.2.3":
45 "4533a43c34548edd1f63a276a42690fce15bde9409bcf20c4b8fa3d7e4d7cac1",
48 vendor_dir = Path(__file__, "..", "..", "wheels").resolve()
50 with tempfile.NamedTemporaryFile(mode="w", encoding="utf-8") as file:
51 for dep_spec, checksum in packages.items():
52 print(f"{dep_spec} --hash=sha256:{checksum}", file=file)
53 file.flush()
55 cli_args = [
56 "pip",
57 "download",
58 "--dest",
59 str(vendor_dir),
60 "--require-hashes",
61 "-r",
62 file.name,
64 if loud:
65 cli_args.append("-v")
67 print(" ".join(cli_args))
68 subprocess.run(cli_args, check=True)
70 return 0
73 if __name__ == "__main__":
74 sys.exit(main())