Skip to content

Commit

Permalink
Format code with black and isort
Browse files Browse the repository at this point in the history
  • Loading branch information
amotl committed Feb 2, 2022
1 parent a7f9975 commit 17724a7
Show file tree
Hide file tree
Showing 24 changed files with 356 additions and 583 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
format:
black grafana_client test
isort grafana_client test
1 change: 1 addition & 0 deletions docs/backlog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
pep517.build is deprecated. Consider switching to https://pypi.org/project/build/
- Format code with `black` and `isort``
- Clarify *"To use admin API you need to use basic auth"*, see README.
- Check contents of PyPI package vs. `MANIFEST.in`
8 changes: 4 additions & 4 deletions grafana_client/api.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
from .client import GrafanaClient
from .elements import (
Admin,
Annotations,
Dashboard,
Datasource,
Folder,
Notifications,
Organization,
Organizations,
Search,
Snapshots,
Teams,
User,
Users,
Teams,
Snapshots,
Annotations,
Notifications
)


Expand Down
4 changes: 1 addition & 3 deletions grafana_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ class GrafanaBadInputError(GrafanaClientError):
"""

def __init__(self, response):
super(GrafanaBadInputError, self).__init__(
400, response, "Bad Input: `{0}`".format(response)
)
super(GrafanaBadInputError, self).__init__(400, response, "Bad Input: `{0}`".format(response))


class GrafanaUnauthorizedError(GrafanaClientError):
Expand Down
11 changes: 5 additions & 6 deletions grafana_client/elements/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from .base import Base
from .admin import Admin
from .annotations import Annotations
from .base import Base
from .dashboard import Dashboard
from .datasource import Datasource
from .folder import Folder
from .notifications import Notifications
from .organization import Organization, Organizations
from .search import Search
from .user import User, Users
from .team import Teams
from .annotations import Annotations
from .snapshots import Snapshots
from .notifications import Notifications

from .team import Teams
from .user import User, Users
4 changes: 1 addition & 3 deletions grafana_client/elements/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ def change_user_permissions(self, user_id, is_grafana_admin):
:return:
"""
change_user_permissions = "/admin/users/%s/permissions" % user_id
r = self.client.PUT(
change_user_permissions, json={"isGrafanaAdmin": is_grafana_admin}
)
r = self.client.PUT(change_user_permissions, json={"isGrafanaAdmin": is_grafana_admin})
return r

def delete_user(self, user_id):
Expand Down
74 changes: 28 additions & 46 deletions grafana_client/elements/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ def get_annotation(
return r

def add_annotation(
self,
dashboard_id=None,
panel_id=None,
time_from=None,
time_to=None,
tags=[],
text=None,
self,
dashboard_id=None,
panel_id=None,
time_from=None,
time_to=None,
tags=[],
text=None,
):

"""
Expand Down Expand Up @@ -108,11 +108,11 @@ def add_annotation(
return r

def add_annotation_graphite(
self,
what=None,
tags=[],
when=None,
data=None,
self,
what=None,
tags=[],
when=None,
data=None,
):
"""
https://grafana.com/docs/grafana/latest/http_api/annotations/#create-annotation-in-graphite-format
Expand All @@ -125,24 +125,19 @@ def add_annotation_graphite(
"""

annotations_path = "/annotations/graphite"
payload = {
"what": what,
"tags": tags,
"when": when,
"data": data
}
payload = {"what": what, "tags": tags, "when": when, "data": data}

r = self.client.POST(annotations_path, json=payload)

return r

def update_annotation(
self,
annotations_id,
time_from=None,
time_to=None,
tags=[],
text=None,
self,
annotations_id,
time_from=None,
time_to=None,
tags=[],
text=None,
):
"""
https://grafana.com/docs/grafana/latest/http_api/annotations/#update-annotation
Expand All @@ -154,24 +149,19 @@ def update_annotation(
:return:
"""
annotations_path = "/annotations/{}".format(annotations_id)
payload = {
"time": time_from,
"timeEnd": time_to,
"tags": tags,
"text": text
}
payload = {"time": time_from, "timeEnd": time_to, "tags": tags, "text": text}

r = self.client.PUT(annotations_path, json=payload)

return r

def partial_update_annotation(
self,
annotations_id,
time_from=None,
time_to=None,
tags=[],
text=None,
self,
annotations_id,
time_from=None,
time_to=None,
tags=[],
text=None,
):
"""
https://grafana.com/docs/grafana/latest/http_api/annotations/#patch-annotation
Expand All @@ -186,21 +176,13 @@ def partial_update_annotation(
annotations_path = "/annotations/{}".format(annotations_id)
payload = {}

payload = {
"time": time_from,
"timeEnd": time_to,
"tags": tags,
"text": text
}
payload = {"time": time_from, "timeEnd": time_to, "tags": tags, "text": text}

r = self.client.PATCH(annotations_path, json=payload)

return r

def delete_annotations_by_id(
self,
annotations_id=None
):
def delete_annotations_by_id(self, annotations_id=None):

"""
https://grafana.com/docs/grafana/latest/http_api/annotations/#delete-annotation-by-id
Expand Down
4 changes: 1 addition & 3 deletions grafana_client/elements/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ def update_dashboard_permissions(self, dashboard_id, items):
:param items:
:return:
"""
update_dashboard_permissions_path = (
"/dashboards/id/%s/permissions" % dashboard_id
)
update_dashboard_permissions_path = "/dashboards/id/%s/permissions" % dashboard_id
r = self.client.POST(update_dashboard_permissions_path, json=items)
return r
6 changes: 3 additions & 3 deletions grafana_client/elements/folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ def update_folder(self, uid, title, version=None, overwrite=False):
"""
body = {"title": title}
if version is not None:
body['version'] = version
body["version"] = version
if overwrite:
body['overwrite'] = True
body["overwrite"] = True

path = "/folders/%s" % uid
r = self.client.PUT(path, json=body)
Expand All @@ -76,7 +76,7 @@ def get_folder_by_id(self, folder_id):
r = self.client.GET(path)
return r

def get_folder_permissions(self,uid):
def get_folder_permissions(self, uid):
"""
:return:
Expand Down
4 changes: 1 addition & 3 deletions grafana_client/elements/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ def delete_notification_by_uid(self, notification_uid):
:param notification_uid: notification channel uid
:return: result of deletion
"""
delete_notification_by_uid_path = (
"/alert-notifications/uid/%s" % notification_uid
)
delete_notification_by_uid_path = "/alert-notifications/uid/%s" % notification_uid
return self.client.DELETE(delete_notification_by_uid_path)

def delete_notification_by_id(self, notification_id):
Expand Down
4 changes: 1 addition & 3 deletions grafana_client/elements/organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,7 @@ def organization_preference_get(self):
r = self.client.GET(update_preference)
return r

def organization_preference_update(
self, theme="", home_dashboard_id=0, timezone="utc"
):
def organization_preference_update(self, theme="", home_dashboard_id=0, timezone="utc"):
"""
:param theme:
Expand Down
14 changes: 3 additions & 11 deletions grafana_client/elements/snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ def create_new_snapshot(
"""

path = "/snapshots"
post_json = {
"dashboard": dashboard
}
post_json = {"dashboard": dashboard}
if name:
post_json["name"] = name
if expires:
Expand Down Expand Up @@ -63,10 +61,7 @@ def get_snapshot_by_key(self, key):
r = self.client.GET(path)
return r

def delete_snapshot_by_key(
self,
snapshot_id=None
):
def delete_snapshot_by_key(self, snapshot_id=None):
"""
:param snapshot_id:
Expand All @@ -77,10 +72,7 @@ def delete_snapshot_by_key(

return r

def delete_snapshot_by_delete_key(
self,
snapshot_delete_key=None
):
def delete_snapshot_by_delete_key(self, snapshot_delete_key=None):
"""
:param snapshot_delete_key:
Expand Down
4 changes: 1 addition & 3 deletions grafana_client/elements/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,7 @@ def change_actual_user_password(self, old_password, new_password):
"newPassword": new_password,
"confirmNew": new_password,
}
r = self.client.PUT(
change_actual_user_password_path, json=change_actual_user_password_json
)
r = self.client.PUT(change_actual_user_password_path, json=change_actual_user_password_json)
return r

def switch_user_organisation(self, user_id, organisation_id):
Expand Down
8 changes: 8 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,11 @@ requires = [
"wheel"
]
build-backend = "setuptools.build_meta"


[tool.black]
line-length = 120

[tool.isort]
profile = "black"
multi_line_output = 3
Loading

0 comments on commit 17724a7

Please sign in to comment.