File size: 4,928 Bytes
09da05c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#################################################################################
# GLOBALS                                                                       #
#################################################################################

PROJECT_NAME = 2025-P3-AI-Personas
PYTHON_VERSION := 3.10
PYTHON_INTERPRETER := python3
VENV_DIR := .venv

# detect operating system, assign variables
ifeq ($(OS),Windows_NT)
    ACTIVATE := $(VENV_DIR)\Scripts\activate.bat
    PYTHON := $(VENV_DIR)\Scripts\python.exe
else
    ACTIVATE := source $(VENV_DIR)/bin/activate
    PYTHON := $(VENV_DIR)/bin/python
endif

# Check if venv exists (if it exists it will output echo) and use it, otherwise fallback to system Python
ifeq ($(shell test -d $(VENV_DIR) && echo 1),1)
    # If the venv exists, use its Python interpreter
    PYTHON := $(VENV_DIR)/bin/python
else
    # If no venv, fall back to system Python
    PYTHON := python3
endif

#################################################################################
# COMMANDS                                                                      #
#################################################################################

## Lint using ruff (use `make format` to do formatting)
.PHONY: lint
lint:
	@echo ""
	@echo "🔍 ----------------------------------------------------------"
	@echo "🔍 Running Ruff Linter (checking code formatting and issues)..."
	@echo "🔍 ----------------------------------------------------------"
	@echo ""
	ruff format --check
	ruff check

	@echo ""
	@echo "✅ Linting complete. No issues detected (if any)."
	@echo ""

## Format source code with ruff
.PHONY: format
format:
	@echo ""
	@echo "⚙️ ----------------------------------------------------------"
	@echo "⚙️ Running Ruff Formatter (auto-fixing issues)..."
	@echo "⚙️ ----------------------------------------------------------"
	@echo ""
	ruff check --fix
	ruff format

	@echo ""
	@echo "✅ Formatting complete. Code is now formatted."
	@echo ""

## Set up new venv and install requirements
.PHONY: install
install:
	@echo ""
	@echo "🔧 ----------------------------------------------------------"
	@echo "🔧 Creating virtual environment (if it doesn't exist)..."
	@echo "🔧 ----------------------------------------------------------"
	@echo ""
	@test -d $(VENV_DIR) || $(PYTHON_INTERPRETER) -m venv $(VENV_DIR)

	@echo ""
	@echo "📦 Installing Python dependencies..."
	@echo "📦 ----------------------------------------------------------"
	@echo ""
	$(PYTHON) -m pip install --upgrade pip
	$(PYTHON) -m pip install -r requirements.txt

	@echo ""
	@echo "✅ Environment setup complete in '$(VENV_DIR)'"
	@echo ""

## Install only requirements (assumes venv or conda already exists)
.PHONY: requirements
requirements:
	@echo ""
	@echo "📦 Installing dependencies from requirements.txt..."
	@echo ""
	$(PYTHON) -m pip install -r requirements.txt
	@echo ""
	@echo "✅ Dependencies installed."
	@echo ""

## Delete all compiled Python files and venv
.PHONY: clean
clean:
	@echo ""
	@echo "🧹 Cleaning up __pycache__ and .pyc files..."
	@echo ""
	find . -type f -name "*.py[co]" -delete
	find . -type d -name "__pycache__" -delete

	@echo ""
	@echo "🧨 Removing virtual environment directory..."
	@echo ""
	rm -rf $(VENV_DIR)

	@echo ""
	@echo "✅ Cleanup complete."
	@echo ""

## Download the dataset
.PHONY: data
data: requirements
	@echo ""
	@echo "⬇️  Downloading dataset with fl_g13.dataset..."
	@echo ""
	$(PYTHON) -m fl_g13.dataset
	@echo ""
	@echo "✅ Dataset downloaded successfully."
	@echo ""

## Export all notebooks in the notebooks/ directory
.PHONY: export
export: requirements
	@echo ""
	@echo "📤 Exporting all notebooks in 'notebooks/' using nbautoexport..."
	@echo ""
	$(PYTHON) -m nbautoexport export notebooks/
	@echo ""
	@echo "✅ Notebooks exported successfully."
	@echo ""

## Run the local chat CLI (end-to-end demo)
.PHONY: chat
chat: requirements
	@echo ""
	@echo "💬 Starting local chat CLI..."
	@echo ""
	$(PYTHON) scripts/run_chat.py chat

## Run the REST API server (FastAPI + Swagger)
.PHONY: api
api: requirements
	@echo ""
	@echo "🛰️  Starting REST API server..."
	@echo "🧭 Swagger UI: http://localhost:8000/docs"
	@echo ""
	$(PYTHON) scripts/run_api.py

#################################################################################
# Self Documenting Commands                                                     #
#################################################################################

.DEFAULT_GOAL := help

define PRINT_HELP_PYSCRIPT
import re, sys; \
lines = '\n'.join([line for line in sys.stdin]); \
matches = re.findall(r'\n## (.*)\n[\s\S]+?\n([a-zA-Z_-]+):', lines); \
print('Available rules:\n'); \
print('\n'.join(['{:25}{}'.format(*reversed(match)) for match in matches]))
endef
export PRINT_HELP_PYSCRIPT

help:
	@$(PYTHON) -c "${PRINT_HELP_PYSCRIPT}" < $(MAKEFILE_LIST)