get_pypi_hashes.py 1000 B

1234567891011121314151617181920212223242526
  1. import requests
  2. import argparse
  3. from pathlib import Path
  4. def get_package_wheel_hashes(package, version, os):
  5. url = f"https://pypi.org/pypi/{package}/{version}/json"
  6. data = requests.get(url).json()
  7. print(f" {package}:")
  8. print(f" version: \"{version}\"")
  9. print(f" hashes:")
  10. for url in data["urls"]:
  11. if os is None or os in url["filename"]:
  12. print(f" - sha256:{url['digests']['sha256']}")
  13. if __name__ == "__main__":
  14. parser = argparse.ArgumentParser(
  15. description="Display the hashes of the wheel files to be inserted in pip_requirements")
  16. parser.add_argument("package", type=Path, help="Name of the target package")
  17. parser.add_argument("version", type=Path, help="Version of the target package")
  18. parser.add_argument('--os', type=str, help='Specific package OS', choices=['win', 'macosx', 'manylinux', 'musllinux'])
  19. args = parser.parse_args()
  20. get_package_wheel_hashes(args.package, args.version, args.os)