[PATCH patatt 2/7] Add Ruff import checks

Tamir Duberstein <[email protected]>
Newsgroups org.kernel.linux.tools
Message-ID <[email protected]>
Run Ruff's default lint rules together with import sorting and the
existing blanket-noqa check.

Sort imports and remove unused test imports so the expanded lint
configuration is green under the local CI script.

Signed-off-by: Tamir Duberstein <[email protected]>
---
 docs/conf.py                        |  5 +++--
 pyproject.toml                      |  3 ++-
 src/patatt/__init__.py              | 29 +++++++++++++----------------
 tests/conftest.py                   |  7 +++----
 tests/test_validation.py            |  7 ++++---
 tests/unit/test_byhash.py           |  2 +-
 tests/unit/test_devsig_header.py    |  6 +++---
 tests/unit/test_get_algo_keydata.py | 11 +++++------
 tests/unit/test_patatt_message.py   |  7 +++----
 9 files changed, 37 insertions(+), 40 deletions(-)

diff --git a/docs/conf.py b/docs/conf.py
index 042c753..cb0ca38 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -9,13 +9,14 @@ import sys
 # Add the source directory to the path for autodoc
 sys.path.insert(0, os.path.abspath('../src'))
 
+# The version info
+from patatt import __VERSION__
+
 # -- Project information -----------------------------------------------------
 project = 'patatt'
 copyright = '2021-2026, Konstantin Ryabitsev'
 author = 'Konstantin Ryabitsev'
 
-# The version info
-from patatt import __VERSION__
 version = __VERSION__
 release = __VERSION__
 
diff --git a/pyproject.toml b/pyproject.toml
index a541b01..7583cd4 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -52,7 +52,8 @@ version = {attr = "patatt.__VERSION__"}
 "share/man/man5" = ["man/patatt.5"]
 
 [tool.ruff.lint]
-select = [
+extend-select = [
+    "I",
     "PGH004", # https://docs.astral.sh/ruff/rules/blanket-noqa/
 ]
 flake8-quotes.inline-quotes = "single"
diff --git a/src/patatt/__init__.py b/src/patatt/__init__.py
index 499d820..935da55 100644
--- a/src/patatt/__init__.py
+++ b/src/patatt/__init__.py
@@ -5,27 +5,24 @@
 #
 __author__ = 'Konstantin Ryabitsev <[email protected]>'
 
-import sys
-import os
-import re
-
 import argparse
-import hashlib
 import base64
-import subprocess
+import datetime
+import email.header
+import email.utils
+import hashlib
 import logging
+import os
+import re
+import subprocess
+import sys
 import tempfile
 import time
-import datetime
-import warnings
-
 import urllib.parse
-import email.utils
-import email.header
-
-from pathlib import Path
-from typing import Optional, List, Tuple, Dict, Union, Any
+import warnings
 from io import BytesIO
+from pathlib import Path
+from typing import Any, Dict, List, Optional, Tuple, Union
 
 GitConfigType = Dict[str, Union[str, List[str]]]
 
@@ -437,8 +434,8 @@ class DevsigHeader:
     def _sign_ed25519(payload: bytes, privkey: bytes) -> Tuple[bytes, bytes]:
         global KEYCACHE
         try:
-            from nacl.signing import SigningKey
             from nacl.encoding import Base64Encoder
+            from nacl.signing import SigningKey
         except ModuleNotFoundError:
             raise RuntimeError('This operation requires PyNaCl libraries')
 
@@ -456,9 +453,9 @@ class DevsigHeader:
     @staticmethod
     def _validate_ed25519(sigdata: bytes, pubkey: bytes) -> bytes:
         try:
-            from nacl.signing import VerifyKey
             from nacl.encoding import Base64Encoder
             from nacl.exceptions import BadSignatureError
+            from nacl.signing import VerifyKey
         except ModuleNotFoundError:
             raise RuntimeError('This operation requires PyNaCl libraries')
 
diff --git a/tests/conftest.py b/tests/conftest.py
index a9c9157..8bb6064 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -1,13 +1,12 @@
+import base64
+import tempfile
 from pathlib import Path
+from typing import Dict, Generator
 
-import os
-import tempfile
 import pytest
-import base64
 
 from patatt import DevsigHeader, PatattMessage
 
-from typing import Generator, Dict
 
 @pytest.fixture
 def sample_email_bytes() -> bytes:
diff --git a/tests/test_validation.py b/tests/test_validation.py
index 61c4ab6..d51be81 100644
--- a/tests/test_validation.py
+++ b/tests/test_validation.py
@@ -1,9 +1,10 @@
-import pytest
 import os
-import tempfile
 from pathlib import Path
 
-from patatt import PatattMessage, sign_message, validate_message, RES_VALID
+import pytest
+
+from patatt import RES_VALID, validate_message
+
 
 @pytest.mark.parametrize("sample_file", [
     "ed25519-signed.txt",
diff --git a/tests/unit/test_byhash.py b/tests/unit/test_byhash.py
index a24d338..c3fe4d2 100644
--- a/tests/unit/test_byhash.py
+++ b/tests/unit/test_byhash.py
@@ -4,7 +4,7 @@ from pathlib import Path
 
 import pytest
 
-from patatt import make_byhash_path, make_pkey_path, get_public_key
+from patatt import get_public_key, make_byhash_path, make_pkey_path
 
 
 class TestMakeByhashPath:
diff --git a/tests/unit/test_devsig_header.py b/tests/unit/test_devsig_header.py
index 5c5bb06..547593d 100644
--- a/tests/unit/test_devsig_header.py
+++ b/tests/unit/test_devsig_header.py
@@ -1,11 +1,11 @@
-import pytest
 import base64
 import hashlib
 from io import BytesIO
 
-from typing import Dict
+import pytest
+
+from patatt import DevsigHeader
 
-from patatt import DevsigHeader, ValidationError, SigningError
 
 class TestDevsigHeader:
 
diff --git a/tests/unit/test_get_algo_keydata.py b/tests/unit/test_get_algo_keydata.py
index 6f268eb..545f051 100644
--- a/tests/unit/test_get_algo_keydata.py
+++ b/tests/unit/test_get_algo_keydata.py
@@ -1,14 +1,13 @@
-import pytest
+from typing import Callable
+from unittest.mock import MagicMock, patch
 
-from typing import Any, Callable
-from unittest.mock import patch, MagicMock
+import pytest
 
 from patatt import (
-    get_algo_keydata,
-    NoKeyError,
-    ConfigurationError,
     KEYCACHE,
     GitConfigType,
+    NoKeyError,
+    get_algo_keydata,
 )
 
 
diff --git a/tests/unit/test_patatt_message.py b/tests/unit/test_patatt_message.py
index 1422ee7..58338f4 100644
--- a/tests/unit/test_patatt_message.py
+++ b/tests/unit/test_patatt_message.py
@@ -1,10 +1,9 @@
+from typing import Tuple
+
 import pytest
-import re
-from io import BytesIO
 
-from patatt import PatattMessage, ValidationError
+from patatt import PatattMessage
 
-from typing import Tuple
 
 class TestPatattMessage:
 

-- 
2.53.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.