vendor.py 1.8 KB

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