-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
133 lines (111 loc) Β· 3.57 KB
/
Copy pathMakefile
File metadata and controls
133 lines (111 loc) Β· 3.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# Commute.ai Backend Makefile
.PHONY: help install dev start test clean lint format check docker-build docker-db-up docker-up docker-down setup
# Default target
help:
@echo "Available commands:"
@echo " setup - Initial project setup (create venv, install deps)"
@echo " install - Install dependencies"
@echo " dev - Run development server with auto-reload"
@echo " start - Run production server"
@echo " test - Run tests"
@echo " lint - Run linting"
@echo " format - Format code with black"
@echo " check - Run all checks (lint + test)"
@echo " clean - Clean up generated files"
@echo " docker-build - Build Docker image"
@echo " docker-db-up - Start only the db with Docker Compose"
@echo " docker-up - Start with Docker Compose"
@echo " docker-down - Stop Docker Compose"
# Variables
PYTHON := python3
VENV := venv
PIP := $(VENV)/bin/pip
PYTHON_VENV := $(VENV)/bin/python
PORT := 8000
HOST := 0.0.0.0
# Initial setup
setup:
@echo "π Setting up Commute.ai backend..."
$(PYTHON) -m venv $(VENV)
$(PIP) install --upgrade pip
$(PIP) install -r requirements-dev.txt
@echo "β
Setup complete! Run 'make dev' to start development server"
# Install dependencies
install:
$(PIP) install --upgrade pip
$(PIP) install -r requirements.txt
# Development server with auto-reload
dev:
@echo "π Starting development server on http://$(HOST):$(PORT)"
$(PYTHON_VENV) -m uvicorn app.main:app --reload --host $(HOST) --port $(PORT)
# Production server
start:
@echo "π Starting production server on http://$(HOST):$(PORT)"
$(PYTHON_VENV) -m uvicorn app.main:app --host $(HOST) --port $(PORT)
# Run tests
test:
@echo "π§ͺ Running tests..."
$(PYTHON_VENV) -m pytest tests/ -v
# Run tests with coverage
test-cov:
@echo "π§ͺ Running tests with coverage..."
$(PYTHON_VENV) -m pytest tests/ --cov=app --cov-report=html --cov-report=term
# Lint code
lint:
@echo "π Linting code..."
$(PYTHON_VENV) -m flake8 app/ tests/
$(PYTHON_VENV) -m mypy app/
$(PYTHON_VENV) -m black --check app/ tests/
$(PYTHON_VENV) -m isort --check-only app/ tests/
# Format code
format:
@echo "β¨ Formatting code..."
$(PYTHON_VENV) -m black app/ tests/
$(PYTHON_VENV) -m isort app/ tests/
# Run all checks
check: lint test
@echo "β
All checks passed!"
# Clean up
clean:
@echo "π§Ή Cleaning up..."
find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
find . -type f -name "*.pyc" -delete
find . -type f -name "*.pyo" -delete
find . -type f -name "*~" -delete
find . -type d -name "*.egg-info" -exec rm -rf {} + 2>/dev/null || true
rm -rf build/
rm -rf dist/
rm -rf .pytest_cache/
rm -rf .coverage
rm -rf htmlcov/
rm -rf .mypy_cache/
# Database commands
db-upgrade:
@echo "β¬οΈ Upgrading database..."
$(PYTHON_VENV) -m alembic upgrade head
db-downgrade:
@echo "β¬οΈ Downgrading database..."
$(PYTHON_VENV) -m alembic downgrade -1
db-migration:
@echo "π Creating new migration..."
$(PYTHON_VENV) -m alembic revision --autogenerate -m "$(message)"
db-reset:
@echo "π Resetting database..."
rm -f commute_ai.db
$(PYTHON_VENV) -m alembic upgrade head
# Docker commands
docker-db-up:
@echo "π³ Starting database with Docker Compose..."
docker compose up -d postgres
docker-build:
@echo "π³ Building Docker image..."
docker build -t commute-ai-backend .
docker-up:
@echo "π³ Starting with Docker Compose..."
docker compose up -d
docker-down:
@echo "π³ Stopping Docker Compose..."
docker compose down
docker-logs:
@echo "π Showing Docker logs..."
docker compose logs -f