Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: setup openfga_sdk.help for bug info #50

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ By submitting an issue to this repository, you agree to the terms within the [Op

### Version of SDK

> v0.2.0

```
$ python -m openfga_sdk.help
<paste here>
```

This command is only available on openfga_sdk v0.3.2 and greater. Otherwise, please provide some basic information about your system.

### Version of OpenFGA (if known)

Expand Down Expand Up @@ -61,4 +67,4 @@ By submitting an issue to this repository, you agree to the terms within the [Op
> A clear and concise description of what you expected to happen.

### Additional context
> Add any other context about the problem here.
> Add any other context about the problem here.
38 changes: 0 additions & 38 deletions .github/ISSUE_TEMPLATES/bug_report.md

This file was deleted.

30 changes: 0 additions & 30 deletions .github/ISSUE_TEMPLATES/feature_request.md

This file was deleted.

93 changes: 93 additions & 0 deletions openfga_sdk/help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import json
import platform
import sys
from typing import Dict
from collections import OrderedDict

from . import __version__ as openfga_sdk_version

try:
import urllib3

urllib3_version = urllib3.__version__
except ModuleNotFoundError:
urllib3_version = ""

try:
import six

six_version = six.__version__
except ModuleNotFoundError:
six_version = ""

try:
import dateutil

dateutil_version = dateutil.__version__
except ModuleNotFoundError:
dateutil_version = ""

try:
import aiohttp

aiohttp_version = aiohttp.__version__
except ModuleNotFoundError:
aiohttp_version = ""


def info() -> Dict[str, Dict[str, str]]:
"""
Generate information for a bug report.
Based on the requests package help utility module.
"""
try:
platform_info = {
"system": platform.system(),
"release": platform.release(),
}
except OSError:
platform_info = {"system": "Unknown", "release": "Unknown"}

implementation = platform.python_implementation()

if implementation == "CPython":
implementation_version = platform.python_version()
elif implementation == "PyPy":
pypy_version_info = sys.pypy_version_info # type: ignore[attr-defined]
implementation_version = (
f"{pypy_version_info.major}."
f"{pypy_version_info.minor}."
f"{pypy_version_info.micro}"
)
if pypy_version_info.releaselevel != "final":
implementation_version = "".join(
[implementation_version, pypy_version_info.releaselevel]
)
else:
implementation_version = "Unknown"

return OrderedDict(
{
"platform": platform_info,
"implementation": {
"name": implementation,
"version": implementation_version,
},
"openfga_sdk": {"version": openfga_sdk_version},
"dependencies": {
"urllib3": {"version": urllib3_version},
"six": {"version": six_version},
"python-dateutil": {"version": dateutil_version},
"aiohttp": {"version": aiohttp_version},
},
}
)


def main() -> None:
"""Pretty-print the bug information as JSON."""
print(json.dumps(info(), indent=2))


if __name__ == "__main__":
main()