Skip to content

Commit 2de7169

Browse files
committed
flake8
1 parent 0a06c98 commit 2de7169

File tree

7 files changed

+51
-19
lines changed

7 files changed

+51
-19
lines changed

.github/workflows/lint.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: flake8
2+
3+
on:
4+
pull_request:
5+
types:
6+
- 'synchronize'
7+
- 'opened'
8+
9+
jobs:
10+
lint:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
- name: Set up Python 3.11
15+
uses: actions/setup-python@v3
16+
with:
17+
python-version: 3.11
18+
- name: Install dependencies
19+
run: |
20+
python -m pip install --upgrade pip
21+
pip install flake8
22+
- name: Analyze the code with flake8
23+
run: flake8 .

tox.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[flake8]
2+
ignore = F403,F405,W504
3+
max-line-length = 120

truenas_api_client/__init__.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555

5656
from . import ejson as json
5757
from .config import CALL_TIMEOUT
58-
from .exc import ReserveFDException, ClientException, ErrnoMixin, ValidationErrors, CallTimeout
58+
from .exc import ReserveFDException, ClientException, ErrnoMixin, ValidationErrors, CallTimeout # noqa
5959
from .legacy import LegacyClient
6060
from .jsonrpc import CollectionUpdateParams, ErrorObj, JobFields, JSONRPCError, JSONRPCMessage, TruenasError
6161
from .utils import MIDDLEWARE_RUN_DIR, ProgressBar, undefined, UndefinedType, set_socket_options
@@ -76,9 +76,8 @@ def uri_check(self, uri: str | None, py_exceptions: bool):
7676
if uri and py_exceptions and not uri.startswith(UNIX_SOCKET_PREFIX):
7777
raise ClientException('py_exceptions are only allowed for connections to unix domain socket')
7878

79-
80-
def __init__(self, uri: str | None=None, reserved_ports=False, private_methods=False, py_exceptions=False,
81-
log_py_exceptions=False, call_timeout: float | UndefinedType=undefined, verify_ssl=True):
79+
def __init__(self, uri: str | None = None, reserved_ports=False, private_methods=False, py_exceptions=False,
80+
log_py_exceptions=False, call_timeout: float | UndefinedType = undefined, verify_ssl=True):
8281
"""Initialize either a `JSONRPCClient` or a `LegacyClient`.
8382
8483
Use `JSONRPCClient` unless `uri` ends with '/websocket'.
@@ -124,7 +123,7 @@ class WSClient:
124123
The object used by `JSONRPCClient` to send and receive data.
125124
126125
"""
127-
def __init__(self, url: str, *, client: 'JSONRPCClient', reserved_ports: bool=False, verify_ssl: bool=True):
126+
def __init__(self, url: str, *, client: 'JSONRPCClient', reserved_ports: bool = False, verify_ssl: bool = True):
128127
"""Initialize a `WSClient`.
129128
130129
Args:
@@ -303,7 +302,7 @@ class Job:
303302
Every `Job` is responsible for a corresponding `_JobDict` in the client's list of jobs.
304303
305304
"""
306-
def __init__(self, client: 'JSONRPCClient', job_id: str, callback: _JobCallback | None=None):
305+
def __init__(self, client: 'JSONRPCClient', job_id: str, callback: _JobCallback | None = None):
307306
"""Initialize `Job`.
308307
309308
Args:
@@ -705,9 +704,9 @@ def _jobs_subscribe(self):
705704
self._jobs_watching = True
706705
self.subscribe('core.get_jobs', self._jobs_callback, sync=True)
707706

708-
def call(self, method: str, *params, background=False, callback: _JobCallback | None=None,
709-
job: Literal['RETURN'] | bool=False, register_call: bool | None=None,
710-
timeout: float | UndefinedType=undefined) -> Any:
707+
def call(self, method: str, *params, background=False, callback: _JobCallback | None = None,
708+
job: Literal['RETURN'] | bool = False, register_call: bool | None = None,
709+
timeout: float | UndefinedType = undefined) -> Any:
711710
"""The primary way to send call requests to the API.
712711
713712
Send a JSON-RPC v2.0 Request to the server.
@@ -761,8 +760,8 @@ def call(self, method: str, *params, background=False, callback: _JobCallback |
761760
if not background:
762761
self._unregister_call(c)
763762

764-
def wait(self, c: Call, *, callback: _JobCallback | None=None, job: Literal['RETURN'] | bool=False,
765-
timeout: float | UndefinedType=undefined) -> Any:
763+
def wait(self, c: Call, *, callback: _JobCallback | None = None, job: Literal['RETURN'] | bool = False,
764+
timeout: float | UndefinedType = undefined) -> Any:
766765
"""Wait for an API call to return and return its result.
767766
768767
Args:
@@ -820,8 +819,8 @@ def event_payload() -> _Payload:
820819
'event': Event(),
821820
}
822821

823-
def subscribe(self, name: str, callback: _EventCallbackProtocol, payload: _Payload | None=None,
824-
sync: bool=False) -> str:
822+
def subscribe(self, name: str, callback: _EventCallbackProtocol, payload: _Payload | None = None,
823+
sync: bool = False) -> str:
825824
"""Subscribe to an event by calling `core.subscribe`.
826825
827826
Args:
@@ -859,7 +858,7 @@ def unsubscribe(self, id_: str):
859858
else:
860859
self._event_callbacks.pop(k)
861860

862-
def ping(self, timeout: float=10) -> Literal['pong']:
861+
def ping(self, timeout: float = 10) -> Literal['pong']:
863862
"""Call `core.ping` to verify connection to the server.
864863
865864
Args:

truenas_api_client/ejson.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ def object_hook(obj: dict):
7373
if obj_len == 1:
7474
error_key = list(obj.keys())[0]
7575
if '$date' in obj:
76-
return datetime.fromtimestamp(obj['$date'] / 1000, tz=timezone.utc) + timedelta(milliseconds=obj['$date'] % 1000)
76+
return (
77+
datetime.fromtimestamp(obj['$date'] / 1000, tz=timezone.utc) +
78+
timedelta(milliseconds=obj['$date'] % 1000)
79+
)
7780
if '$time' in obj:
7881
return time(*[int(i) for i in obj['$time'].split(':')[:4]]) # type: ignore
7982
if '$set' in obj:

truenas_api_client/exc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ def _get_errname(cls, code: int) -> str | None:
6060
class ClientException(ErrnoMixin, Exception):
6161
"""Represents any exception that might arise from a `Client`."""
6262

63-
def __init__(self, error: str, errno: int | None=None, trace: TruenasTraceback | None=None,
64-
extra: list[ErrorExtra] | None=None):
63+
def __init__(self, error: str, errno: int | None = None, trace: TruenasTraceback | None = None,
64+
extra: list[ErrorExtra] | None = None):
6565
"""Initialize `ClientException`.
6666
6767
Args:

truenas_api_client/legacy.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
logger = logging.getLogger(__name__)
2828

29+
2930
class WSClient:
3031
def __init__(self, url, *, client, reserved_ports=False, verify_ssl=True):
3132
self.url = url
@@ -178,7 +179,7 @@ def result(self):
178179

179180
class LegacyClient:
180181
def __init__(self, uri=None, reserved_ports=False, private_methods=False, py_exceptions=False,
181-
log_py_exceptions=False, call_timeout: float | UndefinedType=undefined, verify_ssl=True):
182+
log_py_exceptions=False, call_timeout: float | UndefinedType = undefined, verify_ssl=True):
182183
"""
183184
Arguments:
184185
:reserved_ports(bool): should the local socket used a reserved port

truenas_api_client/utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@
1616

1717
MIDDLEWARE_RUN_DIR = '/var/run/middleware'
1818

19+
1920
@final
2021
class UndefinedType:
2122
def __new__(cls):
2223
if not hasattr(cls, '_instance'):
2324
cls._instance = super().__new__(cls)
2425
return cls._instance
26+
27+
2528
undefined = UndefinedType()
2629

2730

@@ -107,7 +110,7 @@ def draw(self):
107110
)
108111
self.write_stream.flush()
109112

110-
def update(self, percentage: float | None=None, message: str | None=None):
113+
def update(self, percentage: float | None = None, message: str | None = None):
111114
"""Update the progress bar with a new percentage and/or message, redrawing it.
112115
113116
Args:

0 commit comments

Comments
 (0)