Skip to content

Commit 38229f5

Browse files
authored
feat: setup openfga_sdk.help for bug info (#50)
2 parents 86359f3 + 86d4d3c commit 38229f5

4 files changed

Lines changed: 101 additions & 70 deletions

File tree

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ By submitting an issue to this repository, you agree to the terms within the [Op
1919
2020
### Version of SDK
2121

22-
> v0.2.0
22+
23+
```
24+
$ python -m openfga_sdk.help
25+
<paste here>
26+
```
27+
28+
This command is only available on openfga_sdk v0.3.2 and greater. Otherwise, please provide some basic information about your system.
2329

2430
### Version of OpenFGA (if known)
2531

@@ -61,4 +67,4 @@ By submitting an issue to this repository, you agree to the terms within the [Op
6167
> A clear and concise description of what you expected to happen.
6268
6369
### Additional context
64-
> Add any other context about the problem here.
70+
> Add any other context about the problem here.

.github/ISSUE_TEMPLATES/bug_report.md

Lines changed: 0 additions & 38 deletions
This file was deleted.

.github/ISSUE_TEMPLATES/feature_request.md

Lines changed: 0 additions & 30 deletions
This file was deleted.

openfga_sdk/help.py

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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

Comments
 (0)