Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ci:
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.14.14
rev: v0.16.6
hooks:
# Run the linter.
- id: ruff
Expand Down
24 changes: 12 additions & 12 deletions src/autocommitt/cli/main.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import os
import time
import typer
import shutil
import subprocess
from rich.text import Text
from rich.table import Table
from rich.panel import Panel
import time

import typer
from rich.console import Console
from typing import Optional
from rich.panel import Panel
from rich.table import Table
from rich.text import Text

from autocommitt.core.commit_manager import CommitManager
from autocommitt.core.ollama_manager import OllamaManager
Expand Down Expand Up @@ -51,7 +51,7 @@ def start():
time.sleep(3)
console.print("[green]Ollama server started successfully![/green]")
else:
return None
return

else:
console.print("[yellow]Warning: Ollama server is already running![/yellow]")
Expand All @@ -68,10 +68,10 @@ def start():
console.print(
"[red]Failed to pull default model. Please check your internet connection[/red]"
)
return None
return
else:
console.print(f"[green]Default model {model_name} is ready![/green]")
return None
return


@app.command()
Expand Down Expand Up @@ -174,7 +174,7 @@ def gen(
return False

except Exception as e:
console.print(f"[red]Unexpected error: {str(e)}[/red]")
console.print(f"[red]Unexpected error: {e!s}[/red]")
return False


Expand Down Expand Up @@ -300,7 +300,7 @@ def use(model_name: str = typer.Argument(..., help="Name of the model to use")):

@app.command()
def his(
limit: Optional[int] = typer.Option(
limit: int | None = typer.Option(
None, "--limit", "-n", help="Display only the latest n commit messages"
),
):
Expand Down Expand Up @@ -347,7 +347,7 @@ def his(
return False

except Exception as e:
console.print(f"[red]Unexpected error: {str(e)}[/red]")
console.print(f"[red]Unexpected error: {e!s}[/red]")
return False


Expand Down
8 changes: 4 additions & 4 deletions src/autocommitt/core/commit_manager.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import ollama
import subprocess
from typing import Tuple, Optional

import ollama


class CommitManager:
Expand All @@ -10,7 +10,7 @@ class CommitManager:
model_name: str = "llama3.2:3b"

@staticmethod
def execute_git_command(command: list[str]) -> Tuple[str, Optional[str]]:
def execute_git_command(command: list[str]) -> tuple[str, str | None]:
"""
Execute a Git command safely with cross-platform compatibility.

Expand All @@ -36,7 +36,7 @@ def execute_git_command(command: list[str]) -> Tuple[str, Optional[str]]:
return None, e.stderr

@staticmethod
def check_staged_changes() -> Optional[str]:
def check_staged_changes() -> str | None:
"""
Check for staged Git changes.

Expand Down
15 changes: 8 additions & 7 deletions src/autocommitt/core/ollama_manager.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import os
import platform
import subprocess
import time

import psutil
import platform
import requests
import subprocess
from rich.console import Console
from rich.progress import Progress, SpinnerColumn, TextColumn, TimeElapsedColumn

Expand Down Expand Up @@ -85,7 +86,7 @@ def start_ollama_service() -> bool:
return False

except Exception as e:
console.print(f"[red]An unexpected error occurred: {str(e)}[/red]")
console.print(f"[red]An unexpected error occurred: {e!s}[/red]")
return False

@staticmethod
Expand Down Expand Up @@ -152,7 +153,7 @@ def stop_ollama_service() -> bool:
return False

except Exception as e:
console.print(f"[red]An unexpected error occurred: {str(e)}[/red]")
console.print(f"[red]An unexpected error occurred: {e!s}[/red]")
return False

@staticmethod
Expand Down Expand Up @@ -210,7 +211,7 @@ def is_model_present(model_name: str) -> bool:

except Exception as e:
console.print(
f"[red]Unexpected error checking for model '{model_name}': {str(e)}[/red]"
f"[red]Unexpected error checking for model '{model_name}': {e!s}[/red]"
)
return False

Expand Down Expand Up @@ -304,7 +305,7 @@ def pull_model(model_name: str, timeout: float = 600.00) -> bool:
)
return False
except Exception as e:
console.print(f"[red]Unexpected error while pulling model: {str(e)}[/red]")
console.print(f"[red]Unexpected error while pulling model: {e!s}[/red]")
return False

@staticmethod
Expand Down Expand Up @@ -347,5 +348,5 @@ def delete_model(model_name: str) -> bool:
)
return False
except Exception as e:
console.print(f"[red]Unexpected error while deleting model: {str(e)}[/red]")
console.print(f"[red]Unexpected error while deleting model: {e!s}[/red]")
return False
4 changes: 2 additions & 2 deletions src/autocommitt/utils/check_installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import platform
import shutil
import subprocess

import requests


Expand Down Expand Up @@ -39,8 +40,7 @@ def download_and_install_ollama():
response = requests.get(download_url, stream=True)
if response.status_code == 200:
with open(filename, "wb") as file:
for chunk in response.iter_content(chunk_size=8192):
file.write(chunk)
file.writelines(response.iter_content(chunk_size=8192))
print(f"Ollama downloaded successfully as '{filename}'.")
else:
raise RuntimeError(
Expand Down
12 changes: 6 additions & 6 deletions src/autocommitt/utils/config_manager.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
from typing import Dict
from pathlib import Path
from platformdirs import user_config_dir, user_cache_dir

from platformdirs import user_cache_dir, user_config_dir


class ConfigManager:
Expand Down Expand Up @@ -62,7 +62,7 @@ def ensure_config(cls) -> None:
cls.save_models(cls.DEFAULT_MODELS)

@classmethod
def get_config(cls) -> Dict:
def get_config(cls) -> dict:
"""
Retrieves current configuration.

Expand All @@ -73,7 +73,7 @@ def get_config(cls) -> Dict:
return json.loads(cls.CONFIG_FILE.read_text())

@classmethod
def get_models(cls) -> Dict:
def get_models(cls) -> dict:
"""
Retrieves available model configurations.

Expand All @@ -84,7 +84,7 @@ def get_models(cls) -> Dict:
return json.loads(cls.MODELS_FILE.read_text())

@classmethod
def save_config(cls, config: Dict) -> None:
def save_config(cls, config: dict) -> None:
"""
Saves configuration settings to file.

Expand All @@ -94,7 +94,7 @@ def save_config(cls, config: Dict) -> None:
cls.CONFIG_FILE.write_text(json.dumps(config, indent=2))

@classmethod
def save_models(cls, models: Dict) -> None:
def save_models(cls, models: dict) -> None:
"""
Saves model configurations to file.

Expand Down