Skip to content

Commit 7559ad0

Browse files
committed
style: reformat all files with black 24.10.0
1 parent 1e8fe28 commit 7559ad0

File tree

9 files changed

+20
-63
lines changed

9 files changed

+20
-63
lines changed

src/nakimi/core/config.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@ def _load_config(self):
6565
self._yubikey_enabled = self._get_bool(
6666
"NAKIMI_YUBIKEY_ENABLED", config_values.get("yubikey_enabled"), False
6767
)
68-
self._yubikey_slot = self._get_str(
69-
"NAKIMI_YUBIKEY_SLOT", config_values.get("yubikey_slot"), "1"
70-
)
68+
self._yubikey_slot = self._get_str("NAKIMI_YUBIKEY_SLOT", config_values.get("yubikey_slot"), "1")
7169
self._yubikey_require_touch = self._get_bool(
7270
"NAKIMI_YUBIKEY_REQUIRE_TOUCH", config_values.get("yubikey_require_touch"), True
7371
)

src/nakimi/core/plugin.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,7 @@ def __init__(self, secrets_data: Optional[Dict[str, Any]] = None):
115115
"""
116116
self.secrets_data = secrets_data or {}
117117
self._plugins: Dict[str, Plugin] = {}
118-
self._commands: Dict[str, tuple[str, PluginCommand]] = (
119-
{}
120-
) # full_name -> (plugin_name, command)
118+
self._commands: Dict[str, tuple[str, PluginCommand]] = {} # full_name -> (plugin_name, command)
121119

122120
def register_plugin(self, plugin_class: type[Plugin], plugin_secrets: Optional[Dict] = None):
123121
"""
@@ -183,11 +181,7 @@ def discover_plugins(self):
183181
# Find the Plugin subclass
184182
for attr_name in dir(module):
185183
attr = getattr(module, attr_name)
186-
if (
187-
isinstance(attr, type)
188-
and issubclass(attr, Plugin)
189-
and attr is not Plugin
190-
):
184+
if isinstance(attr, type) and issubclass(attr, Plugin) and attr is not Plugin:
191185
self.register_plugin(attr)
192186
break
193187

src/nakimi/core/vault.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,7 @@ def _check_age_installed(self):
291291
try:
292292
subprocess.run(["age", "--version"], capture_output=True, check=True)
293293
except (subprocess.CalledProcessError, FileNotFoundError):
294-
raise VaultCryptoError(
295-
"age is not installed. Install it from https://age-encryption.org"
296-
)
294+
raise VaultCryptoError("age is not installed. Install it from https://age-encryption.org")
297295

298296
def generate_key(self) -> str:
299297
"""Generate a new age key pair"""

src/nakimi/core/yubikey.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@ def _get_yubikey_recipient(self) -> str:
107107
raise YubiKeyError("No recipient found in age-plugin-yubikey output")
108108
except FileNotFoundError:
109109
raise YubiKeyError(
110-
"age-plugin-yubikey not found. "
111-
"Install it from https://github.com/str4d/age-plugin-yubikey"
110+
"age-plugin-yubikey not found. " "Install it from https://github.com/str4d/age-plugin-yubikey"
112111
)
113112
except subprocess.CalledProcessError as e:
114113
raise YubiKeyError(f"Failed to get recipient: {e.stderr}")
@@ -131,8 +130,7 @@ def _get_yubikey_identity(self) -> str:
131130
return result.stdout.strip()
132131
except FileNotFoundError:
133132
raise YubiKeyError(
134-
"age-plugin-yubikey not found. "
135-
"Install it from https://github.com/str4d/age-plugin-yubikey"
133+
"age-plugin-yubikey not found. " "Install it from https://github.com/str4d/age-plugin-yubikey"
136134
)
137135
except subprocess.CalledProcessError as e:
138136
raise YubiKeyError(f"Failed to get identity: {e.stderr}")
@@ -341,9 +339,7 @@ def verify_pin(self, pin: str) -> bool:
341339
return False
342340

343341
try:
344-
subprocess.run(
345-
["ykman", "piv", "verify-pin", pin], capture_output=True, text=True, check=True
346-
)
342+
subprocess.run(["ykman", "piv", "verify-pin", pin], capture_output=True, text=True, check=True)
347343
return True
348344
except subprocess.CalledProcessError:
349345
return False

src/nakimi/plugins/gmail/client.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,7 @@ def search(self, query: str, max_results: int = 10) -> List[Dict[str, Any]]:
274274
self._ensure_valid_token()
275275

276276
results = self._execute_with_retry(
277-
self.service.users()
278-
.messages()
279-
.list(userId="me", q=query, maxResults=max_results)
280-
.execute
277+
self.service.users().messages().list(userId="me", q=query, maxResults=max_results).execute
281278
)
282279

283280
if not results:
@@ -320,9 +317,7 @@ def list_labels(self) -> List[Dict[str, Any]]:
320317
"""List Gmail labels"""
321318
try:
322319
self._ensure_valid_token()
323-
results = self._execute_with_retry(
324-
self.service.users().labels().list(userId="me").execute
325-
)
320+
results = self._execute_with_retry(self.service.users().labels().list(userId="me").execute)
326321
return results.get("labels", []) if results else []
327322
except GmailAuthError:
328323
return []

src/nakimi/plugins/gmail/plugin.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@ def get_commands(self) -> List[PluginCommand]:
7474
("limit", "Maximum results", False),
7575
],
7676
),
77-
PluginCommand(
78-
name="labels", description="List Gmail labels", handler=self.cmd_labels, args=[]
79-
),
77+
PluginCommand(name="labels", description="List Gmail labels", handler=self.cmd_labels, args=[]),
8078
PluginCommand(
8179
name="profile", description="Show Gmail profile", handler=self.cmd_profile, args=[]
8280
),

tests/unit/test_plugin.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,7 @@ def _validate_secrets(self):
146146
def get_commands(self):
147147
return [
148148
PluginCommand("cmd1", "Command 1", lambda: "result1", []),
149-
PluginCommand(
150-
"cmd2", "Command 2", lambda x: f"result{x}", [("x", "Argument", True)]
151-
),
149+
PluginCommand("cmd2", "Command 2", lambda x: f"result{x}", [("x", "Argument", True)]),
152150
]
153151

154152
manager = PluginManager()
@@ -330,9 +328,7 @@ def _validate_secrets(self):
330328

331329
def get_commands(self):
332330
return [
333-
PluginCommand(
334-
"echo", "Echo input", self.cmd_echo, [("text", "Text to echo", True)]
335-
),
331+
PluginCommand("echo", "Echo input", self.cmd_echo, [("text", "Text to echo", True)]),
336332
PluginCommand(
337333
"add",
338334
"Add numbers",
@@ -379,11 +375,7 @@ def _validate_secrets(self):
379375
pass
380376

381377
def get_commands(self):
382-
return [
383-
PluginCommand(
384-
"echo", "Echo input", self.cmd_echo, [("text", "Text to echo", True)]
385-
)
386-
]
378+
return [PluginCommand("echo", "Echo input", self.cmd_echo, [("text", "Text to echo", True)])]
387379

388380
def cmd_echo(self, text):
389381
return f"Echo: {text}"

tests/unit/test_vault.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,7 @@ def test_secure_delete_with_shred(self, mock_run, mock_is_ram_disk, temp_dir):
258258
mock_run.return_value = mock_result
259259

260260
secure_delete(test_file)
261-
mock_run.assert_called_once_with(
262-
["shred", "-u", str(test_file)], capture_output=True, check=True
263-
)
261+
mock_run.assert_called_once_with(["shred", "-u", str(test_file)], capture_output=True, check=True)
264262

265263
@patch("nakimi.core.vault.is_ram_disk")
266264
@patch("subprocess.run", side_effect=FileNotFoundError())

tests/unit/test_yubikey.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ def test_check_ykman_installed_found(self):
4040

4141
result = yk._check_ykman_installed()
4242
assert result is True
43-
mock_run.assert_called_once_with(
44-
["ykman", "--version"], capture_output=True, check=True
45-
)
43+
mock_run.assert_called_once_with(["ykman", "--version"], capture_output=True, check=True)
4644
# Second call should use cached value
4745
result2 = yk._check_ykman_installed()
4846
assert result2 is True
@@ -149,9 +147,7 @@ def test_encrypt_age_key(self):
149147
# Mock is_available to return True
150148
with patch.object(yk, "is_available", return_value=True):
151149
with patch.object(yk, "_check_age_plugin_installed", return_value=True):
152-
with patch.object(
153-
yk, "_get_yubikey_recipient", return_value="age1yubikey1testrecipient"
154-
):
150+
with patch.object(yk, "_get_yubikey_recipient", return_value="age1yubikey1testrecipient"):
155151
with patch("subprocess.run") as mock_run:
156152
mock_result = Mock()
157153
mock_result.stdout = b"ENCRYPTED_DATA"
@@ -176,9 +172,7 @@ def test_decrypt_age_key(self):
176172
# Mock is_available to return True
177173
with patch.object(yk, "is_available", return_value=True):
178174
with patch.object(yk, "_check_age_plugin_installed", return_value=True):
179-
with patch.object(
180-
yk, "_get_yubikey_identity", return_value="AGE-SECRET-KEY-1TESTIDENTITY"
181-
):
175+
with patch.object(yk, "_get_yubikey_identity", return_value="AGE-SECRET-KEY-1TESTIDENTITY"):
182176
with patch("tempfile.NamedTemporaryFile") as mock_temp:
183177
mock_file = MagicMock()
184178
mock_file.name = "/tmp/mock.age"
@@ -193,9 +187,7 @@ def test_decrypt_age_key(self):
193187
with patch("os.unlink") as mock_unlink:
194188
decrypted = yk.decrypt_age_key(b"ENCRYPTED_DATA")
195189
assert decrypted == "DECRYPTED_DATA"
196-
mock_file.write.assert_called_once_with(
197-
"AGE-SECRET-KEY-1TESTIDENTITY"
198-
)
190+
mock_file.write.assert_called_once_with("AGE-SECRET-KEY-1TESTIDENTITY")
199191
mock_run.assert_called_once_with(
200192
["age", "-d", "-i", "/tmp/mock.age"],
201193
input=b"ENCRYPTED_DATA",
@@ -246,9 +238,7 @@ def test_verify_pin_failure(self):
246238
with patch.object(yk, "is_available", return_value=True):
247239
with patch(
248240
"subprocess.run",
249-
side_effect=subprocess.CalledProcessError(
250-
1, "ykman piv verify-pin", stderr="Wrong PIN"
251-
),
241+
side_effect=subprocess.CalledProcessError(1, "ykman piv verify-pin", stderr="Wrong PIN"),
252242
):
253243
result = yk.verify_pin("wrong")
254244
assert result is False
@@ -294,9 +284,7 @@ def test_change_pin_failure(self):
294284
with patch.object(yk, "is_available", return_value=True):
295285
with patch(
296286
"subprocess.run",
297-
side_effect=subprocess.CalledProcessError(
298-
1, "ykman piv change-pin", stderr="Wrong old PIN"
299-
),
287+
side_effect=subprocess.CalledProcessError(1, "ykman piv change-pin", stderr="Wrong old PIN"),
300288
):
301289
result = yk.change_pin("wrong", "new")
302290
assert result is False

0 commit comments

Comments
 (0)