Skip to content

Commit b23eb59

Browse files
committed
Update prek/pre-commit config
1 parent 0dff3e5 commit b23eb59

7 files changed

Lines changed: 91 additions & 404 deletions

File tree

.pre-commit-config.yaml

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,42 @@
1+
# See https://pre-commit.com for more information
2+
# See https://pre-commit.com/hooks.html for more hooks
13
repos:
2-
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.6.0
4+
- repo: https://github.com/astral-sh/ruff-pre-commit
5+
# Ruff version.
6+
rev: v0.14.10
7+
hooks:
8+
# Run the linter.
9+
- id: ruff-check
10+
args: [ --fix ]
11+
# Run the formatter.
12+
- id: ruff-format
13+
- repo: https://github.com/pre-commit/pre-commit-hooks
14+
rev: v6.0.0
415
hooks:
5-
- id: check-json
16+
- id: trailing-whitespace
17+
- id: end-of-file-fixer
18+
- id: check-json
619
exclude: .devcontainer
7-
- id: check-yaml
8-
- id: trailing-whitespace
9-
- id: end-of-file-fixer
10-
- repo: https://github.com/astral-sh/ruff-pre-commit
11-
rev: v0.9.5
20+
- id: check-yaml
21+
- id: check-added-large-files
22+
- id: no-commit-to-branch
23+
stages: [pre-commit]
24+
args: [--branch, main]
25+
- repo: https://github.com/rhysd/actionlint
26+
rev: v1.7.7
1227
hooks:
13-
- id: ruff
14-
name: ruff check
15-
types: [ python ]
16-
- id: ruff-format
17-
name: ruff format
18-
types: [ python ]
19-
- repo: local
28+
- id: actionlint
29+
- repo: local
2030
hooks:
2131
- id: mypy
2232
name: mypy
2333
entry: mypy
2434
language: system
2535
types: [ python ]
36+
exclude: tests
37+
- id: ty
38+
name: ty check
39+
entry: uv run ty check .
40+
language: system
41+
types: [ python ]
42+
exclude: tests

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ dev = [
3030
"prek>=0.3.8,<1.0",
3131
"ruff>=0.9.0,<1.0",
3232
"mypy>=1.19,<2.0",
33+
"ty>=0.0.29,<1.0",
3334
]
3435

3536
[build-system]

sagemcom_api/client.py

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@
33
from __future__ import annotations
44

55
import asyncio
6-
from collections.abc import Mapping
76
import hashlib
87
import json
98
import math
109
import random
10+
import urllib.parse
11+
from collections.abc import Mapping
1112
from types import TracebackType
1213
from typing import Any
13-
import urllib.parse
1414

15+
import backoff
16+
import humps
1517
from aiohttp import (
1618
ClientConnectorError,
1719
ClientOSError,
@@ -20,8 +22,6 @@
2022
ServerDisconnectedError,
2123
TCPConnector,
2224
)
23-
import backoff
24-
import humps
2525

2626
from .const import (
2727
API_ENDPOINT,
@@ -106,9 +106,7 @@ def __init__(
106106
else ClientSession(
107107
headers={"User-Agent": f"{DEFAULT_USER_AGENT}"},
108108
timeout=ClientTimeout(DEFAULT_TIMEOUT),
109-
connector=TCPConnector(
110-
verify_ssl=verify_ssl if verify_ssl is not None else True
111-
),
109+
connector=TCPConnector(verify_ssl=verify_ssl if verify_ssl is not None else True),
112110
)
113111
)
114112

@@ -143,11 +141,7 @@ def __generate_md5_nonce_hash(self):
143141
def md5(input_string):
144142
return hashlib.md5(input_string.encode()).hexdigest()
145143

146-
n = (
147-
self.__generate_nonce(UINT_MAX)
148-
if self._current_nonce is None
149-
else self._current_nonce
150-
)
144+
n = self.__generate_nonce(UINT_MAX) if self._current_nonce is None else self._current_nonce
151145
f = 0
152146
l_nonce = ""
153147
ha1 = md5(self.username + ":" + l_nonce + ":" + md5(self.password))
@@ -173,9 +167,7 @@ def __generate_hash(self, value, authentication_method=None):
173167

174168
def __get_credential_hash(self):
175169
"""Build credential hash."""
176-
return self.__generate_hash(
177-
self.username + ":" + self._server_nonce + ":" + self._password_hash
178-
)
170+
return self.__generate_hash(self.username + ":" + self._server_nonce + ":" + self._password_hash)
179171

180172
def __generate_auth_key(self):
181173
"""Build auth key."""
@@ -240,8 +232,7 @@ async def __post(self, url, data):
240232

241233
# No errors
242234
if (
243-
error["description"] == XMO_REQUEST_NO_ERR
244-
or error["description"] == "Ok" # NOQA: W503
235+
error["description"] == XMO_REQUEST_NO_ERR or error["description"] == "Ok" # NOQA: W503
245236
):
246237
return result
247238

@@ -373,9 +364,7 @@ async def get_encryption_method(self):
373364
for encryption_method in EncryptionMethod:
374365
try:
375366
self.authentication_method = encryption_method
376-
self._password_hash = self.__generate_hash(
377-
self.password, encryption_method
378-
)
367+
self._password_hash = self.__generate_hash(self.password, encryption_method)
379368

380369
await self.login()
381370

@@ -468,9 +457,7 @@ async def get_values_by_xpaths(self, xpaths, options: dict | None = None) -> dic
468457
max_tries=1,
469458
on_backoff=retry_login,
470459
)
471-
async def set_value_by_xpath(
472-
self, xpath: str, value: str, options: dict | None = None
473-
) -> dict:
460+
async def set_value_by_xpath(self, xpath: str, value: str, options: dict | None = None) -> dict:
474461
"""
475462
Retrieve raw value from router using XPath.
476463
@@ -534,9 +521,7 @@ async def get_device_info(self) -> DeviceInfo:
534521
)
535522
async def get_hosts(self, only_active: bool | None = False) -> list[Device]:
536523
"""Retrieve hosts connected to Sagemcom F@st device."""
537-
data = await self.get_value_by_xpath(
538-
"Device/Hosts/Hosts", options={"capability-flags": {"interface": True}}
539-
)
524+
data = await self.get_value_by_xpath("Device/Hosts/Hosts", options={"capability-flags": {"interface": True}})
540525
devices = [Device(**d) for d in data]
541526

542527
if only_active:

sagemcom_api/enums.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Enums for the Sagemcom F@st client."""
22

3-
from enum import unique
43
import sys
4+
from enum import unique
55

66
# Since we support Python versions lower than 3.11, we use
77
# a backport for StrEnum when needed.

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
from typing import Any, Dict, List
88
from unittest.mock import AsyncMock, MagicMock
99

10-
from aiohttp import ClientSession
1110
import pytest
11+
from aiohttp import ClientSession
1212

1313
from sagemcom_api.client import SagemcomClient
1414
from sagemcom_api.enums import EncryptionMethod

tests/unit/test_client_basic.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ async def test_login_success(mock_session_factory, login_success_response):
4040

4141

4242
@pytest.mark.asyncio
43-
async def test_login_authentication_error(
44-
mock_session_factory, login_auth_error_response
45-
):
43+
async def test_login_authentication_error(mock_session_factory, login_auth_error_response):
4644
"""
4745
Test login raises AuthenticationException on XMO_AUTHENTICATION_ERR.
4846
@@ -70,9 +68,7 @@ async def test_login_authentication_error(
7068

7169

7270
@pytest.mark.asyncio
73-
async def test_get_value_by_xpath_url_encoding(
74-
mock_session_factory, login_success_response, xpath_value_response
75-
):
71+
async def test_get_value_by_xpath_url_encoding(mock_session_factory, login_success_response, xpath_value_response):
7672
"""
7773
Test XPath values are URL-encoded with safe characters preserved.
7874

0 commit comments

Comments
 (0)