################################################################################# # 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)