help.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. from __future__ import print_function
  2. import json
  3. import platform
  4. import sys
  5. from . import __version__ as pyjwt_version
  6. try:
  7. import cryptography
  8. except ImportError:
  9. cryptography = None
  10. try:
  11. import ecdsa
  12. except ImportError:
  13. ecdsa = None
  14. def info():
  15. """
  16. Generate information for a bug report.
  17. Based on the requests package help utility module.
  18. """
  19. try:
  20. platform_info = {"system": platform.system(), "release": platform.release()}
  21. except IOError:
  22. platform_info = {"system": "Unknown", "release": "Unknown"}
  23. implementation = platform.python_implementation()
  24. if implementation == "CPython":
  25. implementation_version = platform.python_version()
  26. elif implementation == "PyPy":
  27. implementation_version = "%s.%s.%s" % (
  28. sys.pypy_version_info.major,
  29. sys.pypy_version_info.minor,
  30. sys.pypy_version_info.micro,
  31. )
  32. if sys.pypy_version_info.releaselevel != "final":
  33. implementation_version = "".join(
  34. [implementation_version, sys.pypy_version_info.releaselevel]
  35. )
  36. else:
  37. implementation_version = "Unknown"
  38. return {
  39. "platform": platform_info,
  40. "implementation": {"name": implementation, "version": implementation_version},
  41. "cryptography": {"version": getattr(cryptography, "__version__", "")},
  42. "pyjwt": {"version": pyjwt_version},
  43. }
  44. def main():
  45. """Pretty-print the bug information as JSON."""
  46. print(json.dumps(info(), sort_keys=True, indent=2))
  47. if __name__ == "__main__":
  48. main()