|
| 1 | +import json |
| 2 | +import platform |
| 3 | +import sys |
| 4 | +from typing import Dict |
| 5 | +from collections import OrderedDict |
| 6 | + |
| 7 | +from . import __version__ as openfga_sdk_version |
| 8 | + |
| 9 | +try: |
| 10 | + import urllib3 |
| 11 | + |
| 12 | + urllib3_version = urllib3.__version__ |
| 13 | +except ModuleNotFoundError: |
| 14 | + urllib3_version = "" |
| 15 | + |
| 16 | +try: |
| 17 | + import six |
| 18 | + |
| 19 | + six_version = six.__version__ |
| 20 | +except ModuleNotFoundError: |
| 21 | + six_version = "" |
| 22 | + |
| 23 | +try: |
| 24 | + import dateutil |
| 25 | + |
| 26 | + dateutil_version = dateutil.__version__ |
| 27 | +except ModuleNotFoundError: |
| 28 | + dateutil_version = "" |
| 29 | + |
| 30 | +try: |
| 31 | + import aiohttp |
| 32 | + |
| 33 | + aiohttp_version = aiohttp.__version__ |
| 34 | +except ModuleNotFoundError: |
| 35 | + aiohttp_version = "" |
| 36 | + |
| 37 | + |
| 38 | +def info() -> Dict[str, Dict[str, str]]: |
| 39 | + """ |
| 40 | + Generate information for a bug report. |
| 41 | + Based on the requests package help utility module. |
| 42 | + """ |
| 43 | + try: |
| 44 | + platform_info = { |
| 45 | + "system": platform.system(), |
| 46 | + "release": platform.release(), |
| 47 | + } |
| 48 | + except OSError: |
| 49 | + platform_info = {"system": "Unknown", "release": "Unknown"} |
| 50 | + |
| 51 | + implementation = platform.python_implementation() |
| 52 | + |
| 53 | + if implementation == "CPython": |
| 54 | + implementation_version = platform.python_version() |
| 55 | + elif implementation == "PyPy": |
| 56 | + pypy_version_info = sys.pypy_version_info # type: ignore[attr-defined] |
| 57 | + implementation_version = ( |
| 58 | + f"{pypy_version_info.major}." |
| 59 | + f"{pypy_version_info.minor}." |
| 60 | + f"{pypy_version_info.micro}" |
| 61 | + ) |
| 62 | + if pypy_version_info.releaselevel != "final": |
| 63 | + implementation_version = "".join( |
| 64 | + [implementation_version, pypy_version_info.releaselevel] |
| 65 | + ) |
| 66 | + else: |
| 67 | + implementation_version = "Unknown" |
| 68 | + |
| 69 | + return OrderedDict( |
| 70 | + { |
| 71 | + "platform": platform_info, |
| 72 | + "implementation": { |
| 73 | + "name": implementation, |
| 74 | + "version": implementation_version, |
| 75 | + }, |
| 76 | + "openfga_sdk": {"version": openfga_sdk_version}, |
| 77 | + "dependencies": { |
| 78 | + "urllib3": {"version": urllib3_version}, |
| 79 | + "six": {"version": six_version}, |
| 80 | + "python-dateutil": {"version": dateutil_version}, |
| 81 | + "aiohttp": {"version": aiohttp_version}, |
| 82 | + }, |
| 83 | + } |
| 84 | + ) |
| 85 | + |
| 86 | + |
| 87 | +def main() -> None: |
| 88 | + """Pretty-print the bug information as JSON.""" |
| 89 | + print(json.dumps(info(), indent=2)) |
| 90 | + |
| 91 | + |
| 92 | +if __name__ == "__main__": |
| 93 | + main() |
0 commit comments