Reorganize python modules slightly
This commit is contained in:
parent
c9a0d9a225
commit
ed38373d1e
@ -1,26 +1,8 @@
|
|||||||
import argparse
|
import argparse
|
||||||
from dataclasses import dataclass
|
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import sys
|
import sys
|
||||||
|
from .configs import OllamaConfig, ReviewConfig, create_config_from_vars
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
|
||||||
class OllamaConfig:
|
|
||||||
"""Configuration for Ollama client."""
|
|
||||||
|
|
||||||
model: str
|
|
||||||
server_url: str
|
|
||||||
timeout: int
|
|
||||||
max_retries: int
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
|
||||||
class ReviewConfig:
|
|
||||||
"""Complete configuration for ReviewLlama."""
|
|
||||||
|
|
||||||
paths: List[Path]
|
|
||||||
ollama: OllamaConfig
|
|
||||||
|
|
||||||
|
|
||||||
def normalize_server_url(url: str) -> str:
|
def normalize_server_url(url: str) -> str:
|
||||||
@ -30,25 +12,6 @@ def normalize_server_url(url: str) -> str:
|
|||||||
return url.rstrip("/")
|
return url.rstrip("/")
|
||||||
|
|
||||||
|
|
||||||
def create_ollama_config(
|
|
||||||
model: str, server_url: str, timeout: int, max_retries: int
|
|
||||||
) -> OllamaConfig:
|
|
||||||
"""Create OllamaConfig with validated parameters."""
|
|
||||||
return OllamaConfig(
|
|
||||||
model=model,
|
|
||||||
server_url=normalize_server_url(server_url),
|
|
||||||
timeout=timeout,
|
|
||||||
max_retries=max_retries,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def create_review_config(
|
|
||||||
paths: List[Path], ollama_config: OllamaConfig
|
|
||||||
) -> ReviewConfig:
|
|
||||||
"""Create complete ReviewConfig from validated components."""
|
|
||||||
return ReviewConfig(paths=paths, ollama=ollama_config)
|
|
||||||
|
|
||||||
|
|
||||||
def create_argument_parser() -> argparse.ArgumentParser:
|
def create_argument_parser() -> argparse.ArgumentParser:
|
||||||
"""Create and configure the argument parser."""
|
"""Create and configure the argument parser."""
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
@ -110,15 +73,14 @@ def transform_namespace_to_config(namespace: argparse.Namespace) -> ReviewConfig
|
|||||||
"""Transform argparse namespace into ReviewConfig."""
|
"""Transform argparse namespace into ReviewConfig."""
|
||||||
paths = [Path(path_str) for path_str in namespace.paths]
|
paths = [Path(path_str) for path_str in namespace.paths]
|
||||||
|
|
||||||
ollama_config = create_ollama_config(
|
return create_config_from_vars(
|
||||||
|
paths=paths,
|
||||||
model=namespace.model,
|
model=namespace.model,
|
||||||
server_url=namespace.server_url,
|
server_url=normalize_server_url(namespace.server_url),
|
||||||
timeout=namespace.timeout,
|
timeout=namespace.timeout,
|
||||||
max_retries=namespace.max_retries,
|
max_retries=namespace.max_retries,
|
||||||
)
|
)
|
||||||
|
|
||||||
return create_review_config(paths=paths, ollama_config=ollama_config)
|
|
||||||
|
|
||||||
|
|
||||||
def parse_arguments(args: Optional[List[str]] = None) -> ReviewConfig:
|
def parse_arguments(args: Optional[List[str]] = None) -> ReviewConfig:
|
||||||
"""Parse command line arguments and return validated configuration."""
|
"""Parse command line arguments and return validated configuration."""
|
||||||
@ -140,7 +102,3 @@ def cli() -> None:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error: {e}", file=sys.stderr)
|
print(f"Error: {e}", file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
|
53
src/reviewllama/configs.py
Normal file
53
src/reviewllama/configs.py
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
from dataclasses import dataclass
|
||||||
|
from typing import List
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True)
|
||||||
|
class OllamaConfig:
|
||||||
|
"""Configuration for Ollama client."""
|
||||||
|
|
||||||
|
model: str
|
||||||
|
server_url: str
|
||||||
|
timeout: int
|
||||||
|
max_retries: int
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True)
|
||||||
|
class ReviewConfig:
|
||||||
|
"""Complete configuration for ReviewLlama."""
|
||||||
|
|
||||||
|
paths: List[Path]
|
||||||
|
ollama: OllamaConfig
|
||||||
|
|
||||||
|
|
||||||
|
def create_ollama_config(
|
||||||
|
model: str, server_url: str, timeout: int, max_retries: int
|
||||||
|
) -> OllamaConfig:
|
||||||
|
"""Create OllamaConfig with validated parameters."""
|
||||||
|
return OllamaConfig(
|
||||||
|
model=model,
|
||||||
|
server_url=normalize_server_url(server_url),
|
||||||
|
timeout=timeout,
|
||||||
|
max_retries=max_retries,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def create_review_config(
|
||||||
|
paths: List[Path], ollama_config: OllamaConfig
|
||||||
|
) -> ReviewConfig:
|
||||||
|
"""Create complete ReviewConfig from validated components."""
|
||||||
|
return ReviewConfig(paths=paths, ollama=ollama_config)
|
||||||
|
|
||||||
|
|
||||||
|
def create_config_from_vars(
|
||||||
|
paths: List[Path], model: str, server_url: str, timeout: int, max_retries: int
|
||||||
|
):
|
||||||
|
ollama_config = OllamaConfig(
|
||||||
|
model=model,
|
||||||
|
server_url=server_url,
|
||||||
|
timeout=timeout,
|
||||||
|
max_retries=max_retries,
|
||||||
|
)
|
||||||
|
|
||||||
|
return create_review_config(paths, ollama_config)
|
Loading…
x
Reference in New Issue
Block a user