Skip to content
Merged
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
18 changes: 0 additions & 18 deletions .github/actions/setup-python/action.yml

This file was deleted.

18 changes: 18 additions & 0 deletions .github/actions/setup-uv/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: "Setup uv environment"
description: "Instala uv y sincroniza las dependencias con cache"

runs:
using: "composite"
steps:
- name: Instalar uv
uses: astral-sh/setup-uv@v2
with:
python-version: "3.11"
enable-cache: true
cache-dependency-glob: |
**/uv.lock
**/pyproject.toml

- name: Instalar dependencias
shell: bash
run: uv sync --all-extras
16 changes: 8 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Setup Python
uses: ./.github/actions/setup-python
- name: Setup uv
uses: ./.github/actions/setup-uv

- name: Black
run: black --check api/ tests/
run: uv run black --check api/ tests/

- name: Flake8
run: flake8 api/ tests/
run: uv run flake8 api/ tests/

- name: MyPy
run: mypy api/
run: uv run mypy api/

test:
name: Tests unitarios e integración
Expand All @@ -45,8 +45,8 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Setup Python
uses: ./.github/actions/setup-python
- name: Setup uv
uses: ./.github/actions/setup-uv

- name: Ejecutar tests
env:
Expand All @@ -55,7 +55,7 @@ jobs:
OPENROUTER_API_KEY: test-key
API_KEY: test-api-key
run: |
pytest --cov=api --cov-report=xml --cov-report=term-missing
uv run pytest --cov=api --cov-report=xml --cov-report=term-missing

- name: Subir cobertura
uses: codecov/codecov-action@v4.6.0
Expand Down
29 changes: 17 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,37 +1,42 @@
# Imagen base con Python 3.11 (Alpine es más ligera y segura)
FROM python:3.11-slim-bookworm AS builder

# uv reemplaza pip para instalar dependencias (misma herramienta que local y CI)
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/

# Variables de entorno para Python
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1
PYTHONDONTWRITEBYTECODE=1

# Directorio de trabajo
# Directorio de trabajo; la etapa runtime usa la misma ruta para que las
# rutas absolutas registradas dentro de .venv sigan siendo válidas
WORKDIR /app

# Actualizar paquetes del sistema para parches de seguridad
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
&& rm -rf /var/lib/apt/lists/*

# Copiar pyproject y usarlo para instalar dependencias
COPY pyproject.toml .
# Copiar pyproject + uv.lock e instalar dependencias primero (cache de capas)
# README.md es requerido por los metadatos de pyproject.toml
COPY pyproject.toml uv.lock README.md ./
RUN UV_PYTHON_DOWNLOADS=never uv sync --locked --no-install-project

# Copiar código fuente e instalar el proyecto
COPY api/ ./api/
RUN pip install --upgrade pip setuptools wheel && \
pip install --no-cache-dir .
RUN UV_PYTHON_DOWNLOADS=never uv sync --locked

# Stage 2: Runtime
FROM python:3.11-slim-bookworm

ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1
PYTHONDONTWRITEBYTECODE=1 \
PATH="/app/.venv/bin:$PATH"

WORKDIR /app

# Copiar dependencias instaladas
COPY --from=builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin
# Copiar el .venv construido en el builder (misma ruta absoluta)
COPY --from=builder /app/.venv /app/.venv

# Copiar código fuente
COPY api/ ./api/
Expand Down
28 changes: 10 additions & 18 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,42 @@ Guía rápida para contribución y desarrollo local.
## Entorno recomendado

- Python 3.11+
- Virtualenv
- [uv](https://docs.astral.sh/uv/) (gestor de entornos y dependencias)

## Pasos rápidos

```bash
# Crear entorno virtual
python -m venv .venv
# Windows
.\.venv\Scripts\activate
# Unix
source .venv/bin/activate
# Instalar dependencias
python -m pip install --upgrade pip
pip install -e '.[dev]'
# Crear .venv e instalar dependencias (uv gestiona el entorno)
uv sync --all-extras

# Levantar Redis para desarrollo
docker run -d -p 6379:6379 redis:7-alpine

# Ejecutar la app

uvicorn api.main:app --reload --host 0.0.0.0 --port 8000
uv run uvicorn api.main:app --reload --host 0.0.0.0 --port 8000
```

## Tests

```bash
# Ejecutar todos los tests
pytest -v
uv run pytest -v

# Tests específicos
pytest tests/test_router.py -v
uv run pytest tests/test_router.py -v
```

## Formato y lint

```bash
# Formatear
black .
uv run black .
# Lint
flake8 . --max-line-length=100
uv run flake8 . --max-line-length=100
# Type check
mypy . --ignore-missing-imports
uv run mypy . --ignore-missing-imports
```

## Notas

- Use `scripts/test.py` para utilidades comunes (lint, tests).
- Use `uv run scripts/test.py` para utilidades comunes (lint, tests).
Loading
Loading