Skip to content

Commit d3a43d1

Browse files
committed
chore(ruff): run ruff check --fix
Autofixed the following violations: - examples/get_tenant_token.py: 1 × I001 (unsorted-imports) - examples/upload_firmware.py: 1 × I001 (unsorted-imports) - onekey_client/__init__.py: 1 × I001 (unsorted-imports) - onekey_client/cli/ci.py: 2 × RET502 (implicit-return-value) 2 × RUF010 (explicit-f-string-type-conversion) 1 × F401 (unused-import) 1 × D202 (blank-line-after-function) 1 × I001 (unsorted-imports) 1 × UP032 (f-string) 1 × UP045 (non-pep604-annotation-optional) - onekey_client/cli/cli.py: 1 × I001 (unsorted-imports) - onekey_client/cli/firmware_upload.py: 2 × UP045 (non-pep604-annotation-optional) 1 × D202 (blank-line-after-function) 1 × I001 (unsorted-imports) 1 × F401 (unused-import) - onekey_client/cli/misc.py: 2 × D202 (blank-line-after-function) - onekey_client/client.py: 7 × UP045 (non-pep604-annotation-optional) 4 × UP006 (non-pep585-annotation) 3 × F401 (unused-import) 2 × RET505 (superfluous-else-return) 1 × I001 (unsorted-imports) - onekey_client/errors.py: 1 × F401 (unused-import) 1 × UP045 (non-pep604-annotation-optional) - onekey_client/models.py: 4 × UP045 (non-pep604-annotation-optional) 1 × I001 (unsorted-imports) 1 × F401 (unused-import) - onekey_client/queries/utils.py: 1 × I001 (unsorted-imports) 1 × UP011 (lru-cache-without-parameters)
1 parent 776aa19 commit d3a43d1

11 files changed

Lines changed: 42 additions & 56 deletions

File tree

examples/get_tenant_token.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22
import sys
33
from getpass import getpass
4+
45
from onekey_client import Client
56

67
API_URL = "https://app.eu.onekey.com/api"

examples/upload_firmware.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import sys
2-
32
from getpass import getpass
43
from pathlib import Path
54

onekey_client/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
from .client import Client as Client
2-
from .models import Tenant as Tenant, FirmwareMetadata as FirmwareMetadata
2+
from .models import FirmwareMetadata as FirmwareMetadata
3+
from .models import Tenant as Tenant

onekey_client/cli/ci.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import sys
22
import time
33
from pathlib import Path
4-
from typing import Optional
54
from uuid import UUID
65

76
import click
87
import httpx
9-
10-
from junit_xml import TestSuite, TestCase
8+
from junit_xml import TestCase, TestSuite
119

1210
from onekey_client import Client
1311
from onekey_client.queries import load_query
@@ -42,9 +40,7 @@ def get_result(self):
4240
except httpx.HTTPError as e:
4341
if error_count <= self.retry_count:
4442
click.echo(
45-
"Error communicating with ONEKEY platform, retrying; error='{}'".format(
46-
str(e)
47-
)
43+
f"Error communicating with ONEKEY platform, retrying; error='{e!s}'"
4844
)
4945
time.sleep(self.retry_wait * error_count)
5046
error_count += 1
@@ -138,7 +134,7 @@ def wait_for_analysis_finish(self):
138134
)
139135
break
140136
except Exception as e:
141-
click.echo(f"Error fetching results {str(e)}")
137+
click.echo(f"Error fetching results {e!s}")
142138
sys.exit(10)
143139

144140
def get_recent_firmware_id(self):
@@ -156,11 +152,11 @@ def get_recent_firmware_id(self):
156152
click.echo(
157153
f"Latest firmware upload is not the current firmware, skipping comparison with previous, latest={latest_id}"
158154
)
159-
return
155+
return None
160156

161157
if not firmware_ids:
162158
click.echo("No previous firmware")
163-
return
159+
return None
164160

165161
return firmware_ids[0]
166162

@@ -303,10 +299,9 @@ def ci_result(
303299
retry_count: int,
304300
retry_wait: int,
305301
check_interval: int,
306-
junit_path: Optional[Path],
302+
junit_path: Path | None,
307303
):
308304
"""Fetch analysis results for CI"""
309-
310305
handler = ResultHandler(
311306
client,
312307
firmware_id,

onekey_client/cli/cli.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
import httpx
55

66
from onekey_client import Client
7-
from .firmware_upload import upload_firmware
8-
from .misc import list_tenants, get_tenant_token
7+
98
from .ci import ci_result
9+
from .firmware_upload import upload_firmware
10+
from .misc import get_tenant_token, list_tenants
1011

1112

1213
@click.group()

onekey_client/cli/firmware_upload.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import sys
22
from pathlib import Path
3-
from typing import Optional
43

54
import click
65

7-
from onekey_client import FirmwareMetadata, Client
6+
from onekey_client import Client, FirmwareMetadata
87
from onekey_client.errors import QueryError
98

109

@@ -41,12 +40,11 @@ def upload_firmware(
4140
vendor_name: str,
4241
product_group_name: str,
4342
analysis_configuration_name: str,
44-
version: Optional[str],
45-
name: Optional[str],
43+
version: str | None,
44+
name: str | None,
4645
filename: Path,
4746
):
4847
"""Uploads a firmware to the ONEKEY platform"""
49-
5048
product_group_id = _get_product_group_id_by_name(client, product_group_name)
5149
analysis_configuration_id = _get_analysis_configuration_id_by_name(
5250
client, analysis_configuration_name

onekey_client/cli/misc.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
@click.pass_obj
1010
def list_tenants(client: Client):
1111
"""List available tenants"""
12-
1312
tenants = client.get_all_tenants()
1413
for tenant in tenants:
1514
click.echo(f"{tenant.name} ({tenant.id}")
@@ -19,5 +18,4 @@ def list_tenants(client: Client):
1918
@click.pass_obj
2019
def get_tenant_token(client: Client):
2120
"""Get tenant specific Bearer token"""
22-
2321
click.echo(json.dumps(client.get_auth_headers()))

onekey_client/client.py

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,21 @@
22
import gc
33
import secrets
44
from pathlib import Path
5-
from typing import Optional, List, Dict
6-
7-
from httpx import URL
85

96
try:
107
from importlib import resources
118
except ImportError:
129
import importlib_resources as resources
1310

1411
import httpx
15-
from pydantic import parse_obj_as
16-
from authlib.oidc.core import IDToken
1712
from authlib.jose import jwt
18-
from .queries import load_query
19-
from . import errors
20-
from . import models as m
21-
from . import keys
13+
from authlib.oidc.core import IDToken
14+
from httpx import URL
15+
from pydantic import parse_obj_as
2216

17+
from . import errors, keys
18+
from . import models as m
19+
from .queries import load_query
2320

2421
CLIENT_ID = "ONEKEY Python SDK"
2522
TOKEN_NAMESPACE = "https://www.onekey.com/"
@@ -51,8 +48,8 @@ class Client:
5148
def __init__(
5249
self,
5350
api_url: str,
54-
ca_bundle: Optional[Path] = None,
55-
disable_tls_verify: Optional[bool] = False,
51+
ca_bundle: Path | None = None,
52+
disable_tls_verify: bool | None = False,
5653
):
5754
self._api_url = URL(api_url)
5855
self._client = self._setup_httpx_client(api_url, ca_bundle, disable_tls_verify)
@@ -66,8 +63,8 @@ def __init__(
6663
def _setup_httpx_client(
6764
self,
6865
api_url: str,
69-
ca_bundle: Optional[Path] = None,
70-
disable_tls_verify: Optional[bool] = False,
66+
ca_bundle: Path | None = None,
67+
disable_tls_verify: bool | None = False,
7168
):
7269
if disable_tls_verify:
7370
return httpx.Client(base_url=api_url, verify=False)
@@ -78,17 +75,15 @@ def _setup_httpx_client(
7875
raise errors.InvalidCABundle
7976

8077
return httpx.Client(base_url=api_url, verify=str(ca))
81-
else:
82-
with resources.path(keys, "ca.pem") as ca:
83-
return httpx.Client(base_url=api_url, verify=str(ca))
78+
with resources.path(keys, "ca.pem") as ca:
79+
return httpx.Client(base_url=api_url, verify=str(ca))
8480

85-
def _load_key(self, key_name: str, path: Optional[Path] = None):
81+
def _load_key(self, key_name: str, path: Path | None = None):
8682
if path is not None:
8783
return path.read_bytes()
88-
else:
89-
response = self._client.get(f"/{key_name}.pem")
90-
response.raise_for_status()
91-
return response.read()
84+
response = self._client.get(f"/{key_name}.pem")
85+
response.raise_for_status()
86+
return response.read()
9287

9388
@property
9489
def api_url(self) -> URL:
@@ -111,7 +106,7 @@ def login(self, email: str, password: str):
111106
claims_cls=IDToken,
112107
)
113108
tenants = id_token[TOKEN_NAMESPACE + "tenants"]
114-
tenants = parse_obj_as(List[m.Tenant], tenants)
109+
tenants = parse_obj_as(list[m.Tenant], tenants)
115110
self._state.tenants = {e.name: e for e in tenants}
116111
self._state.email = email
117112
self._state.raw_id_token = json_res["id_token"]
@@ -131,7 +126,7 @@ def use_token(self, token: str):
131126
self._state.tenants = {tenant.name: tenant}
132127
self._state.tenant = tenant
133128

134-
def _post(self, path: str, headers: Optional[Dict] = None, **kwargs):
129+
def _post(self, path: str, headers: dict | None = None, **kwargs):
135130
response = self._client.post(path, headers=headers, **kwargs)
136131
response.raise_for_status()
137132
return response.json()
@@ -152,7 +147,7 @@ def get_tenant(self, name: str):
152147
return self._state.tenants[name]
153148

154149
@_login_required
155-
def get_all_tenants(self) -> List[m.Tenant]:
150+
def get_all_tenants(self) -> list[m.Tenant]:
156151
"""Get the list of Tenants you have access to."""
157152
return list(self._state.tenants.values())
158153

@@ -182,7 +177,7 @@ def refresh_tenant_token(self):
182177
self.use_tenant(self._state.tenant)
183178

184179
@_tenant_required
185-
def query(self, query: str, variables: Optional[Dict] = None, timeout=60):
180+
def query(self, query: str, variables: dict | None = None, timeout=60):
186181
"""Issues a GraphQL query and returns the results"""
187182
res = self._post_with_token(
188183
"/graphql", json={"query": query, "variables": variables}, timeout=timeout

onekey_client/errors.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import json
2-
from typing import Optional
32

43

54
class ClientError(Exception):
65
"""Base class for all Client errors."""
76

8-
def __init__(self, message: Optional[str] = None):
7+
def __init__(self, message: str | None = None):
98
super().__init__(message or self.MESSAGE)
109

1110

onekey_client/models.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import datetime as dt
2-
from typing import Optional
32
from uuid import UUID
3+
44
from pydantic import BaseModel
55

66

@@ -11,11 +11,11 @@ class Tenant(BaseModel):
1111

1212
class FirmwareMetadata(BaseModel):
1313
name: str
14-
version: Optional[str] = None
15-
release_date: Optional[dt.datetime] = None
16-
notes: Optional[str] = None
14+
version: str | None = None
15+
release_date: dt.datetime | None = None
16+
notes: str | None = None
1717
vendor_name: str
1818
product_name: str
19-
product_category: Optional[str] = None
19+
product_category: str | None = None
2020
product_group_id: UUID
2121
analysis_configuration_id: UUID

0 commit comments

Comments
 (0)