Skip to content

Commit 83eaa7a

Browse files
committed
fix: resolve all ruff and mypy linting issues
- Fix nested if statements (SIM102) in plugin and update commands - Remove unused subprocess result variables (F841) - Fix mutable class attribute using Field(default_factory=list) (RUF012) - Add proper type annotations for Click context and JSON parsing - Fix nullable type handling in plugin search logic - Ensure all code passes black, ruff, and mypy checks
1 parent 2827f9a commit 83eaa7a

3 files changed

Lines changed: 34 additions & 32 deletions

File tree

packages/deepctl-cmd-plugin/src/deepctl_cmd_plugin/command.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def context_wrapper(func: Any) -> Any:
8383
"""Wrap subcommand to provide config and auth."""
8484

8585
@click.pass_context
86-
def wrapper(ctx: click.Context, **kwargs: Any) -> Any:
86+
def wrapper(ctx: click.Context, /, **kwargs: Any) -> Any:
8787
# Try to get from parent context first
8888
if ctx.parent and ctx.parent.obj:
8989
config = ctx.parent.obj.get("config")
@@ -93,7 +93,7 @@ def wrapper(ctx: click.Context, **kwargs: Any) -> Any:
9393
return func(config, auth_manager, client, **kwargs)
9494

9595
# Fallback - look for deepctl_context
96-
current_ctx = ctx
96+
current_ctx: click.Context | None = ctx
9797
while current_ctx:
9898
if hasattr(current_ctx, "deepctl_context"):
9999
config = current_ctx.deepctl_context.get("config")
@@ -187,7 +187,10 @@ def _get_plugin_state(self) -> dict[str, Any]:
187187
"""
188188
if self._plugin_state_file.exists():
189189
try:
190-
return json.loads(self._plugin_state_file.read_text())
190+
result: dict[str, Any] = json.loads(
191+
self._plugin_state_file.read_text()
192+
)
193+
return result
191194
except Exception:
192195
return {"plugins": {}}
193196
return {"plugins": {}}
@@ -399,11 +402,10 @@ def _handle_remove(
399402
package = kwargs["package"]
400403
yes = kwargs.get("yes", False)
401404

402-
if not yes:
403-
if not click.confirm(
404-
f"Are you sure you want to remove {package}?"
405-
):
406-
return
405+
if not yes and not click.confirm(
406+
f"Are you sure you want to remove {package}?"
407+
):
408+
return
407409

408410
result = self.remove_plugin(config, auth_manager, client, package)
409411

@@ -476,13 +478,15 @@ def _handle_search(
476478

477479
# Check installed status
478480
is_installed = (
479-
plugin.install_name in installed_plugins
480-
or plugin.name in installed_plugins
481-
)
481+
plugin.install_name is not None
482+
and plugin.install_name in installed_plugins
483+
) or plugin.name in installed_plugins
482484
installed_version = None
483485
if is_installed:
484-
installed_plugin = installed_plugins.get(
485-
plugin.install_name
486+
installed_plugin = (
487+
installed_plugins.get(plugin.install_name)
488+
if plugin.install_name
489+
else None
486490
) or installed_plugins.get(plugin.name)
487491
if installed_plugin:
488492
installed_version = installed_plugin.version
@@ -689,9 +693,7 @@ def install_plugin(
689693
# Execute installation
690694
try:
691695
print_info(f"Installing {options.package}...")
692-
result = subprocess.run(
693-
cmd, capture_output=True, text=True, check=True
694-
)
696+
subprocess.run(cmd, capture_output=True, text=True, check=True)
695697

696698
# Get installed version
697699
installed_version = self._get_package_version(
@@ -883,9 +885,7 @@ def remove_plugin(
883885
# Execute removal
884886
try:
885887
print_info(f"Removing {package}...")
886-
result = subprocess.run(
887-
cmd, capture_output=True, text=True, check=True
888-
)
888+
subprocess.run(cmd, capture_output=True, text=True, check=True)
889889

890890
# Update plugin state if using plugin environment
891891
if using_plugin_env:

packages/deepctl-cmd-plugin/src/deepctl_cmd_plugin/models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from enum import Enum
44

55
from deepctl_core.models import BaseModel
6+
from pydantic import Field
67

78

89
class PluginAction(str, Enum):
@@ -35,7 +36,7 @@ class PluginRegistryEntry(BaseModel):
3536
version: str
3637
author: str | None = None
3738
url: str | None = None
38-
keywords: list[str] = []
39+
keywords: list[str] = Field(default_factory=list)
3940
# Package name for installation if different from name
4041
install_name: str | None = None
4142

packages/deepctl-cmd-update/src/deepctl_cmd_update/command.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -158,19 +158,20 @@ def handle(
158158
console.print(f"\nUpdate command: [green]{update_command}[/green]")
159159

160160
# Confirm update
161-
if not yes:
162-
if not Confirm.ask("\nDo you want to proceed with the update?"):
163-
print_info("Update cancelled")
164-
return UpdateResult(
165-
success=False,
166-
message="Update cancelled by user",
167-
current_version=version_info.current_version,
168-
latest_version=version_info.latest_version,
169-
update_available=version_info.update_available,
170-
installation_method=install_info.method,
171-
).model_dump()
161+
if not yes and not Confirm.ask(
162+
"\nDo you want to proceed with the update?"
163+
):
164+
print_info("Update cancelled")
165+
return UpdateResult(
166+
success=False,
167+
message="Update cancelled by user",
168+
current_version=version_info.current_version,
169+
latest_version=version_info.latest_version,
170+
update_available=version_info.update_available,
171+
installation_method=install_info.method,
172+
).model_dump()
172173

173-
# Execute update
174+
# Execute update
174175
print_info("Updating deepctl...")
175176
try:
176177
# Run the update command synchronously

0 commit comments

Comments
 (0)