Skip to content

Commit 60b43ec

Browse files
committed
fix linting
1 parent 53369dd commit 60b43ec

File tree

11 files changed

+264
-200
lines changed

11 files changed

+264
-200
lines changed

.vscode/settings.json

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,41 @@
1010
"keepit",
1111
"notif",
1212
"werein"
13-
]
13+
],
14+
15+
"editor.formatOnSave": true,
16+
"editor.codeActionsOnSave": {
17+
"source.fixAll.ruff": "explicit",
18+
"source.organizeImports.ruff": "explicit"
19+
},
20+
"[python]": {
21+
"editor.defaultFormatter": "charliermarsh.ruff",
22+
"editor.formatOnSave": true,
23+
"editor.codeActionsOnSave": {
24+
"source.fixAll.ruff": "explicit",
25+
"source.organizeImports.ruff": "explicit"
26+
},
27+
"editor.rulers": [
28+
120
29+
],
30+
"editor.tabSize": 4
31+
},
32+
"ruff.enable": true,
33+
"ruff.organizeImports": true,
34+
"ruff.fixAll": true,
35+
"files.exclude": {
36+
"**/__pycache__": true,
37+
"**/.pytest_cache": true,
38+
"**/.mypy_cache": true,
39+
"**/.ruff_cache": true
40+
},
41+
"files.watcherExclude": {
42+
"**/.git/objects/**": true,
43+
"**/.git/subtree-cache/**": true,
44+
"**/node_modules/**": true,
45+
"**/.hg/store/**": true,
46+
"**/.venv/**": true,
47+
"**/.mypy_cache/**": true,
48+
"**/.ruff_cache/**": true
49+
}
1450
}

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,6 @@ update: ## Update dependencies
6868
uv sync --upgrade
6969

7070
sync: ## Sync dependencies
71-
uv sync
71+
uv sync
72+
73+
check: clean format lint pre-commit test ## Run all checks and tests

src/mistapi/__api_request.py

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
This package is licensed under the MIT License.
99
1010
--------------------------------------------------------------------------------
11-
This module manages API requests with Mist Cloud. It is used to
11+
This module manages API requests with Mist Cloud. It is used to
1212
* generate the URL based on the provided parameters
1313
* add the required HTTP Headers to the request
1414
* report error if any
@@ -64,13 +64,16 @@ def _url(self, uri) -> str:
6464
"""
6565
logger.debug("apirequest:_url:https://%s%s", self._cloud_uri, uri)
6666
return f"https://{self._cloud_uri}{uri}"
67-
67+
6868
def _log_proxy(self) -> None:
69-
pwd_regex = r':([^:@]*)@'
69+
pwd_regex = r":([^:@]*)@"
7070
if self._session.proxies.get("https"):
71-
logger.info(f"apirequest:sending request to proxy server {re.sub(pwd_regex, ':*********@', self._session.proxies['https'])}")
72-
print(f"apirequest:sending request to proxy server {re.sub(pwd_regex, ':*********@', self._session.proxies['https'])}")
73-
71+
logger.info(
72+
f"apirequest:sending request to proxy server {re.sub(pwd_regex, ':*********@', self._session.proxies['https'])}"
73+
)
74+
print(
75+
f"apirequest:sending request to proxy server {re.sub(pwd_regex, ':*********@', self._session.proxies['https'])}"
76+
)
7477

7578
def _next_apitoken(self) -> None:
7679
logger.info("apirequest:_next_apitoken:rotating API Token")
@@ -190,7 +193,9 @@ def mist_get(self, uri: str, query: dict = None) -> APIResponse:
190193
return self.mist_get(uri, query)
191194
logger.error(f"apirequest:mist_get:HTTP error occurred: {http_err}")
192195
if resp:
193-
logger.error(f"apirequest:mist_get:HTTP error description: {resp.json()}")
196+
logger.error(
197+
f"apirequest:mist_get:HTTP error description: {resp.json()}"
198+
)
194199
except Exception as err:
195200
logger.error(f"apirequest:mist_get:Other error occurred: {err}")
196201
logger.error("apirequest:mist_get:Exception occurred", exc_info=True)
@@ -232,7 +237,7 @@ def mist_post(self, uri: str, body: dict = None) -> APIResponse:
232237
logger.debug(f"apirequest:mist_post:request body:{resp.request.body}")
233238
resp.raise_for_status()
234239
except requests.exceptions.ProxyError as proxy_error:
235-
logger.error(f"apirequest:mist_post:Proxy Error: {proxy_error}")
240+
logger.error(f"apirequest:mist_post:Proxy Error: {proxy_error}")
236241
proxy_failed = True
237242
except requests.exceptions.ConnectionError as connexion_error:
238243
logger.error(f"Capirequest:mist_post:Connection Error: {connexion_error}")
@@ -246,7 +251,9 @@ def mist_post(self, uri: str, body: dict = None) -> APIResponse:
246251
return self.mist_post(uri, body)
247252
logger.error(f"apirequest:mist_post: HTTP error occurred: {http_err}")
248253
if resp:
249-
logger.error(f"apirequest:mist_post: HTTP error description: {resp.json()}")
254+
logger.error(
255+
f"apirequest:mist_post: HTTP error description: {resp.json()}"
256+
)
250257
except Exception as err:
251258
logger.error(f"apirequest:mist_post: Other error occurred: {err}")
252259
logger.error("apirequest:mist_post: Exception occurred", exc_info=True)
@@ -288,7 +295,7 @@ def mist_put(self, uri: str, body: dict = None) -> APIResponse:
288295
logger.debug(f"apirequest:mist_put:request body:{resp.request.body}")
289296
resp.raise_for_status()
290297
except requests.exceptions.ProxyError as proxy_error:
291-
logger.error(f"apirequest:mist_put:Proxy Error: {proxy_error}")
298+
logger.error(f"apirequest:mist_put:Proxy Error: {proxy_error}")
292299
proxy_failed = True
293300
except requests.exceptions.ConnectionError as connexion_error:
294301
logger.error(f"apirequest:mist_put:Connection Error: {connexion_error}")
@@ -302,7 +309,9 @@ def mist_put(self, uri: str, body: dict = None) -> APIResponse:
302309
return self.mist_put(uri, body)
303310
logger.error(f"apirequest:mist_put: HTTP error occurred: {http_err}")
304311
if resp:
305-
logger.error(f"apirequest:mist_put: HTTP error description: {resp.json()}")
312+
logger.error(
313+
f"apirequest:mist_put: HTTP error description: {resp.json()}"
314+
)
306315
except Exception as err:
307316
logger.error(f"apirequest:mist_put: Other error occurred: {err}")
308317
logger.error("apirequest:mist_put: Exception occurred", exc_info=True)
@@ -336,7 +345,7 @@ def mist_delete(self, uri: str, query: dict = None) -> APIResponse:
336345
)
337346
resp.raise_for_status()
338347
except requests.exceptions.ProxyError as proxy_error:
339-
logger.error(f"apirequest:mist_delete:Proxy Error: {proxy_error}")
348+
logger.error(f"apirequest:mist_delete:Proxy Error: {proxy_error}")
340349
proxy_failed = True
341350
except requests.exceptions.ConnectionError as connexion_error:
342351
logger.error(f"apirequest:mist_delete:Connection Error: {connexion_error}")
@@ -403,7 +412,7 @@ def mist_post_file(self, uri: str, multipart_form_data: dict = {}) -> APIRespons
403412
None,
404413
json.dumps(multipart_form_data[key]),
405414
)
406-
except:
415+
except (OSError, json.JSONDecodeError):
407416
logger.error(
408417
f"apirequest:mist_post_file:multipart_form_data:"
409418
f"Unable to parse JSON object {key} "
@@ -427,10 +436,12 @@ def mist_post_file(self, uri: str, multipart_form_data: dict = {}) -> APIRespons
427436
)
428437
resp.raise_for_status()
429438
except requests.exceptions.ProxyError as proxy_error:
430-
logger.error(f"apirequest:mist_post_file:Proxy Error: {proxy_error}")
439+
logger.error(f"apirequest:mist_post_file:Proxy Error: {proxy_error}")
431440
proxy_failed = True
432441
except requests.exceptions.ConnectionError as connexion_error:
433-
logger.error(f"apirequest:mist_post_file:Connection Error: {connexion_error}")
442+
logger.error(
443+
f"apirequest:mist_post_file:Connection Error: {connexion_error}"
444+
)
434445
except HTTPError as http_err:
435446
if http_err.response.status_code == 429:
436447
logger.warning(
@@ -441,7 +452,9 @@ def mist_post_file(self, uri: str, multipart_form_data: dict = {}) -> APIRespons
441452
return self.mist_post_file(uri, multipart_form_data)
442453
logger.error(f"apirequest:mist_post_file: HTTP error occurred: {http_err}")
443454
if resp:
444-
logger.error(f"apirequest:mist_post_file: HTTP error description: {resp.json()}")
455+
logger.error(
456+
f"apirequest:mist_post_file: HTTP error description: {resp.json()}"
457+
)
445458
except Exception as err:
446459
logger.error(f"apirequest:mist_post_file: Other error occurred: {err}")
447460
logger.error("apirequest:mist_post_file: Exception occurred", exc_info=True)

src/mistapi/__api_response.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,7 @@ class APIResponse:
2020
Class used to pass API Responses
2121
"""
2222

23-
def __init__(
24-
self,
25-
response: Response ,
26-
url: str,
27-
proxy_error: bool = False
28-
) -> None:
23+
def __init__(self, response: Response, url: str, proxy_error: bool = False) -> None:
2924
"""
3025
PARAMS
3126
-----------
@@ -41,7 +36,7 @@ def __init__(
4136
self.headers = None
4237
self.status_code = None
4338
self.proxy_error = proxy_error
44-
39+
4540
if response is not None:
4641
self.headers = response.headers
4742
self.status_code = response.status_code
@@ -82,17 +77,17 @@ def _check_next(self) -> None:
8277
page = int(page_str)
8378
if limit * page < total:
8479
uri = f"/api/{self.url.split('/api/')[1]}"
85-
self.next = uri.replace(f"page={page}", f"page={page+1}")
80+
self.next = uri.replace(f"page={page}", f"page={page + 1}")
8681
logger.debug(f"apiresponse:_check_next:set next to {self.next}")
87-
except:
82+
except ValueError:
8883
logger.error(
8984
f"apiresponse:_check_next:"
90-
f"unable to convert total({total})/limit({limit})/page({page}) to int"
85+
f"unable to convert total({total_str})/limit({limit_str})/page({page_str}) to int"
9186
)
9287
logger.error(
93-
"apirequest:mist_post_file:Exception occurred", exc_info=True
88+
"apiresponse:_check_next:Exception occurred", exc_info=True
9489
)
9590
console.error(
9691
f"Unable to convert total "
97-
f"({total})/limit({limit})/page({page}) to int"
92+
f"({total_str})/limit({limit_str})/page({page_str}) to int"
9893
)

0 commit comments

Comments
 (0)