get_pypi_hashes.py 802 B

12345678910111213141516171819202122
  1. import requests
  2. import argparse
  3. from pathlib import Path
  4. def get_package_wheel_hashes(package, version):
  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. print(f" - sha256:{url['digests']['sha256']}")
  12. if __name__ == "__main__":
  13. parser = argparse.ArgumentParser(description="Display the hashes of the wheel files to be inserted in pip_requirements")
  14. parser.add_argument("package", type=Path, help="Name of the target package")
  15. parser.add_argument("version", type=Path, help="Version of the target package")
  16. args = parser.parse_args()
  17. get_package_wheel_hashes(args.package, args.version)