Skip to content

Commit 2dcfc2d

Browse files
committed
chore: add ruff and mypy configuration with auto-fixes
1 parent 5196680 commit 2dcfc2d

14 files changed

Lines changed: 69 additions & 42 deletions

backend/app/ai_client.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import os
21
import logging
2+
import os
3+
34
import requests
4-
from typing import Dict
55

66
logger = logging.getLogger("stackx.ai_client")
77
logger.setLevel(logging.INFO)
@@ -10,7 +10,7 @@
1010
OLLAMA_TIMEOUT = int(os.getenv("OLLAMA_TIMEOUT", "10"))
1111

1212
try:
13-
from .skills_registry import get_skill, all_skills, load_all_skills
13+
from .skills_registry import all_skills, get_skill, load_all_skills
1414
try:
1515
load_all_skills()
1616
except Exception:
@@ -24,7 +24,7 @@ def all_skills():
2424
return []
2525

2626

27-
def _build_prompt(user_input: Dict, top_stack: Dict) -> str:
27+
def _build_prompt(user_input: dict, top_stack: dict) -> str:
2828
proyecto = user_input.get("proyecto", "un proyecto")
2929
prioridades = user_input.get("weights", {})
3030
prompt = (
@@ -37,7 +37,7 @@ def _build_prompt(user_input: Dict, top_stack: Dict) -> str:
3737
return prompt
3838

3939

40-
def _run_skill_if_available(user_input: Dict, top_stack: Dict, skill_name: str = None) -> str:
40+
def _run_skill_if_available(user_input: dict, top_stack: dict, skill_name: str = None) -> str:
4141
"""Intenta ejecutar una skill registrada para generar la justificación.
4242
4343
Prioridad de selección de skill:
@@ -82,7 +82,7 @@ def _run_skill_if_available(user_input: Dict, top_stack: Dict, skill_name: str =
8282
return None
8383

8484

85-
def generate_justification(user_input: Dict, top_stack: Dict, skill_name: str = None) -> str:
85+
def generate_justification(user_input: dict, top_stack: dict, skill_name: str = None) -> str:
8686
# 1) Intentar skill registrado (puede pasar un nombre de skill explícito)
8787
text = _run_skill_if_available(user_input, top_stack, skill_name=skill_name)
8888
if text:

backend/app/ai_skills/content_generator.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# backend/app/ai_skills/content_generator.py
2-
import os
32

43
SKILL_NAME = "content_generator"
54
DESCRIPTION = "Super-Skill para generar contenido variable (justificaciones, resúmenes, trade-offs) basado en parámetros."
@@ -8,7 +7,7 @@ def run_skill(input: dict) -> dict:
87
mode = input.get("mode", "full_justification")
98
tech = input.get("tech", {})
109
tech_name = tech.get("name", "tecnología seleccionada")
11-
10+
1211
if mode == "full_justification":
1312
text = f"Justificación completa: {tech_name} es ideal por su escalabilidad y soporte de comunidad."
1413
elif mode == "concise_summary":
@@ -17,9 +16,9 @@ def run_skill(input: dict) -> dict:
1716
text = f"Comparativa: {tech_name} frente a alternativas destaca por su baja latencia."
1817
else:
1918
text = f"Contenido generado para {tech_name} en modo {mode}."
20-
19+
2120
return {
22-
"status": "ok",
21+
"status": "ok",
2322
"result": {
2423
"text": text,
2524
"mode_applied": mode

backend/app/ai_skills/data_analysis.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
# backend/app/ai_skills/data_analysis.py
2-
from .. import recommender # Reutilizamos lógica existente si es posible
32

43
SKILL_NAME = "data_analysis"
54
DESCRIPTION = "Super-Skill para análisis de datos, scoring y validación de compatibilidad."
65

76
def run_skill(input: dict) -> dict:
87
operation = input.get("operation", "calculate_stack_score")
9-
8+
109
if operation == "calculate_stack_score":
1110
# Podríamos llamar a recommender.calculate_score_for_tech aquí
1211
result = {"score": 0.85, "details": "Cálculo basado en pesos del usuario."}
1312
elif operation == "validate_compatibility":
1413
result = {"compatible": True, "conflict_level": "low"}
1514
else:
1615
result = {"error": f"Operación {operation} no soportada."}
17-
16+
1817
return {
1918
"status": "ok",
2019
"result": result

backend/app/database.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
23
from sqlalchemy import create_engine
34
from sqlalchemy.orm import sessionmaker
45

backend/app/main.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import os
2+
13
from fastapi import FastAPI
4+
5+
from . import sanity_sync
26
from .database import engine
37
from .models import Base
4-
from .routes import recommend, admin
5-
from . import sanity_sync
6-
from .sanity_sync import start_scheduler, shutdown_scheduler
7-
import os
8+
from .routes import admin, recommend
9+
from .sanity_sync import start_scheduler
810

911
app = FastAPI(title='Stack Recommender')
1012

backend/app/models.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
from sqlalchemy import Column, Integer, String, Float, ForeignKey, Text, DateTime
2-
from sqlalchemy.orm import relationship, declarative_base
3-
from datetime import datetime
1+
from sqlalchemy import Column, Float, ForeignKey, Integer, String, Text
2+
from sqlalchemy.orm import declarative_base, relationship
43

54
Base = declarative_base()
65

backend/app/recommender.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
12
from sqlalchemy.orm import Session
3+
24
from .models import Technology
3-
from typing import List, Dict
45

5-
def calculate_score_for_tech(tech: Technology, user_weights: Dict[str, float]) -> float:
6+
7+
def calculate_score_for_tech(tech: Technology, user_weights: dict[str, float]) -> float:
68
total_score = 0.0
79
total_weights = sum(user_weights.values()) if user_weights else 0.0
810

@@ -15,7 +17,7 @@ def calculate_score_for_tech(tech: Technology, user_weights: Dict[str, float]) -
1517
return 0.0
1618
return total_score / total_weights
1719

18-
def get_recommendations(db: Session, user_weights: Dict[str, float], top_n: int = 3) -> List[Dict]:
20+
def get_recommendations(db: Session, user_weights: dict[str, float], top_n: int = 3) -> list[dict]:
1921
technologies = db.query(Technology).all()
2022
results = []
2123

backend/app/routes/admin.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
from fastapi import APIRouter, BackgroundTasks, Request, HTTPException
21
import os
2+
3+
from fastapi import APIRouter, BackgroundTasks, HTTPException, Request
4+
35
from .. import sanity_sync
46

57
router = APIRouter()

backend/app/routes/recommend.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
from fastapi import APIRouter, Depends, HTTPException, Header
1+
from fastapi import APIRouter, Depends, Header
22
from sqlalchemy.orm import Session
3+
4+
from .. import ai_client, recommender
35
from ..database import get_db
4-
from .. import recommender, ai_client
5-
from ..schemas import UserWeights, RecommendationResponse, RecommendationItem
6+
from ..schemas import RecommendationItem, RecommendationResponse, UserWeights
67

78
router = APIRouter()
89

backend/app/sanity_sync.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import os
2+
from collections.abc import Callable
3+
24
import requests
3-
from typing import Callable, Optional
45
from sqlalchemy.orm import Session
6+
57
from .database import SessionLocal
68
from .models import Category, Technology
79

@@ -67,7 +69,7 @@ def sync():
6769
except ImportError:
6870
_APScheduler = None
6971

70-
_scheduler: Optional[object] = None
72+
_scheduler: object | None = None
7173

7274

7375
def start_scheduler(job_func: Callable):

0 commit comments

Comments
 (0)