Skip to content

Commit 02c569f

Browse files
committed
feat(dev): add Makefile
1 parent 987e965 commit 02c569f

File tree

1 file changed

+131
-0
lines changed

1 file changed

+131
-0
lines changed

Makefile

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
.DEFAULT_GOAL := help
2+
.PHONY: help install install-dev lint lint-fix format format-md typecheck quality test test-parallel test-teardown test-verbose coverage docs-serve docs-build docs-clean build clean all dev
3+
4+
# Colors for output
5+
YELLOW := \033[33m
6+
GREEN := \033[32m
7+
BLUE := \033[34m
8+
RED := \033[31m
9+
RESET := \033[0m
10+
11+
# Project variables
12+
PYTHON := python3
13+
UV := uv
14+
PYTEST := pytest
15+
RUFF := ruff
16+
TYPECHECK := basedpyright
17+
MKDOCS := mkdocs
18+
MDFORMAT := mdformat
19+
BALATRO_SCRIPT := ./balatro.sh
20+
21+
# Test ports for parallel testing
22+
TEST_PORTS := 12346 12347 12348 12349
23+
24+
help: ## Show this help message
25+
@echo "$(BLUE)BalatroBot Development Makefile$(RESET)"
26+
@echo ""
27+
@echo "$(YELLOW)Available targets:$(RESET)"
28+
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " $(GREEN)%-18s$(RESET) %s\n", $$1, $$2}' $(MAKEFILE_LIST)
29+
30+
# Installation targets
31+
install: ## Install package dependencies
32+
@echo "$(YELLOW)Installing dependencies...$(RESET)"
33+
$(UV) sync
34+
35+
install-dev: ## Install package with development dependencies
36+
@echo "$(YELLOW)Installing development dependencies...$(RESET)"
37+
$(UV) sync --all-extras
38+
39+
# Code quality targets
40+
lint: ## Run ruff linter (check only)
41+
@echo "$(YELLOW)Running ruff linter...$(RESET)"
42+
$(RUFF) check --select I .
43+
$(RUFF) check .
44+
45+
lint-fix: ## Run ruff linter with auto-fixes
46+
@echo "$(YELLOW)Running ruff linter with fixes...$(RESET)"
47+
$(RUFF) check --select I --fix .
48+
$(RUFF) check --fix .
49+
50+
format: ## Run ruff formatter
51+
@echo "$(YELLOW)Running ruff formatter...$(RESET)"
52+
$(RUFF) check --select I --fix .
53+
$(RUFF) format .
54+
55+
format-md: ## Run markdown formatter
56+
@echo "$(YELLOW)Running markdown formatter...$(RESET)"
57+
$(MDFORMAT) .
58+
59+
typecheck: ## Run type checker
60+
@echo "$(YELLOW)Running type checker...$(RESET)"
61+
$(TYPECHECK)
62+
63+
quality: lint format typecheck ## Run all code quality checks
64+
@echo "$(GREEN) All quality checks completed$(RESET)"
65+
66+
# Testing targets
67+
test: ## Run tests with single Balatro instance (auto-starts if needed)
68+
@echo "$(YELLOW)Running tests...$(RESET)"
69+
@if ! $(BALATRO_SCRIPT) --status | grep -q "12346"; then \
70+
echo "Starting Balatro on port 12346..."; \
71+
$(BALATRO_SCRIPT) --headless --fast -p 12346; \
72+
fi
73+
$(PYTEST)
74+
75+
test-parallel: ## Run tests in parallel on 4 instances (auto-starts if needed)
76+
@echo "$(YELLOW)Running parallel tests...$(RESET)"
77+
@running_count=$$($(BALATRO_SCRIPT) --status | grep -E "($(word 1,$(TEST_PORTS))|$(word 2,$(TEST_PORTS))|$(word 3,$(TEST_PORTS))|$(word 4,$(TEST_PORTS)))" | wc -l); \
78+
if [ "$$running_count" -ne 4 ]; then \
79+
echo "Starting Balatro instances on ports: $(TEST_PORTS)"; \
80+
$(BALATRO_SCRIPT) --headless --fast -p $(word 1,$(TEST_PORTS)) -p $(word 2,$(TEST_PORTS)) -p $(word 3,$(TEST_PORTS)) -p $(word 4,$(TEST_PORTS)); \
81+
fi
82+
$(PYTEST) -n 4 --port $(word 1,$(TEST_PORTS)) --port $(word 2,$(TEST_PORTS)) --port $(word 3,$(TEST_PORTS)) --port $(word 4,$(TEST_PORTS)) tests/lua/
83+
84+
test-teardown: ## Kill all Balatro instances
85+
@echo "$(YELLOW)Killing all Balatro instances...$(RESET)"
86+
$(BALATRO_SCRIPT) --kill
87+
@echo "$(GREEN) All instances stopped$(RESET)"
88+
89+
test-verbose: ## Run tests with verbose output
90+
@echo "$(YELLOW)Running tests with verbose output...$(RESET)"
91+
$(PYTEST) -vx
92+
93+
coverage: ## Generate test coverage reports
94+
@echo "$(YELLOW)Generating coverage reports...$(RESET)"
95+
$(PYTEST) --cov=src/balatrobot --cov-report=term-missing --cov-report=html --cov-report=xml
96+
@echo "$(GREEN) Coverage reports generated$(RESET)"
97+
@echo "HTML report: htmlcov/index.html"
98+
99+
# Documentation targets
100+
docs-serve: ## Serve documentation locally
101+
@echo "$(YELLOW)Starting documentation server...$(RESET)"
102+
$(MKDOCS) serve
103+
104+
docs-build: ## Build documentation
105+
@echo "$(YELLOW)Building documentation...$(RESET)"
106+
$(MKDOCS) build
107+
108+
docs-clean: ## Clean built documentation
109+
@echo "$(YELLOW)Cleaning documentation build...$(RESET)"
110+
rm -rf site/
111+
112+
# Build targets
113+
build: ## Build package for distribution
114+
@echo "$(YELLOW)Building package...$(RESET)"
115+
$(PYTHON) -m build
116+
117+
clean: ## Clean build artifacts and caches
118+
@echo "$(YELLOW)Cleaning build artifacts...$(RESET)"
119+
rm -rf build/ dist/ *.egg-info/
120+
rm -rf .pytest_cache/ .coverage htmlcov/ coverage.xml
121+
rm -rf .ruff_cache/
122+
find . -type d -name __pycache__ -exec rm -rf {} +
123+
find . -type f -name "*.pyc" -delete
124+
@echo "$(GREEN) Cleanup completed$(RESET)"
125+
126+
# Convenience targets
127+
dev: format lint typecheck ## Quick development check (no tests)
128+
@echo "$(GREEN) Development checks completed$(RESET)"
129+
130+
all: format lint typecheck test ## Complete quality check with tests
131+
@echo "$(GREEN) All checks completed successfully$(RESET)"

0 commit comments

Comments
 (0)