forked from StakeEngine/math-sdk
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
156 lines (135 loc) · 5.07 KB
/
Makefile
File metadata and controls
156 lines (135 loc) · 5.07 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
PYTHON := python3.12
VENV_DIR := env
VENV_PY := $(VENV_DIR)/bin/python
ifeq ($(OS),Windows_NT)
VENV_PY := $(VENV_DIR)\Scripts\python.exe
ACTIVATE := $(VENV_DIR)\Scripts\activate.bat
else
ACTIVATE := source $(VENV_DIR)/bin/activate
endif
help:
@echo "Available commands:"
@echo ""
@echo "Setup & Environment:"
@echo " make setup - Set up virtual environment and install dependencies"
@echo " make clean - Clean up build artifacts"
@echo ""
@echo "Running Games:"
@echo " make run GAME=<game> - Run game simulation with default run_config.toml"
@echo " make run GAME=<game> CONFIG=<path> - Run game with custom config file"
@echo " make validate GAME=<game> - Validate game configuration"
@echo " make list-games - List all available games"
@echo ""
@echo "Testing:"
@echo " make test - Run main project tests"
@echo " make unit-test GAME=<game> - Run game-specific unit tests"
@echo " make coverage - Run tests with coverage report"
@echo ""
@echo "Development:"
@echo " make profile GAME=<game> - Profile game performance"
@echo " make benchmark GAME=<game> - Run compression benchmark"
@echo " make format - Format code with black and isort"
@echo " make lint - Run linting checks"
@echo ""
@echo "Examples:"
@echo " make run GAME=tower_treasures"
@echo " make validate GAME=tower_treasures"
@echo " make unit-test GAME=tower_treasures"
makeVirtual:
$(PYTHON) -m venv $(VENV_DIR)
pipInstall: makeVirtual
$(VENV_PY) -m pip install --upgrade pip
pipPackages: pipInstall
$(VENV_PY) -m pip install -r requirements.txt
packInstall: pipPackages
$(VENV_PY) -m pip install -e .
setup: packInstall
@echo "Virtual environment ready."
@echo "To activate it, run:"
@echo "$(ACTIVATE)"
run:
ifndef GAME
$(error GAME is not set. Usage: make run GAME=<game_name>)
endif
@echo "Running $(GAME) simulation..."
ifdef CONFIG
@echo "Using custom config: $(CONFIG)"
cd games/$(GAME) && CONFIG_FILE=$(CONFIG) ../../$(VENV_PY) run.py
else
@echo "Using default config: run_config.toml"
cd games/$(GAME) && ../../$(VENV_PY) run.py
endif
@echo ""
ifdef CONFIG
@echo "Checking compression setting in $(CONFIG)..."
@if grep -q "^compression = false" games/$(GAME)/$(CONFIG); then \
echo "Compression is disabled, formatting books files..."; \
$(VENV_PY) scripts/format_books_json.py games/$(GAME) || echo "Warning: Failed to format books files"; \
elif grep -q "^compression = true" games/$(GAME)/$(CONFIG); then \
echo "Compression is enabled, skipping formatting."; \
else \
echo "Could not determine compression setting, skipping formatting."; \
fi
else
@echo "Checking compression setting in run_config.toml..."
@if grep -q "^compression = false" games/$(GAME)/run_config.toml; then \
echo "Compression is disabled, formatting books files..."; \
$(VENV_PY) scripts/format_books_json.py games/$(GAME) || echo "Warning: Failed to format books files"; \
elif grep -q "^compression = true" games/$(GAME)/run_config.toml; then \
echo "Compression is enabled, skipping formatting."; \
else \
echo "Could not determine compression setting, skipping formatting."; \
fi
endif
test:
cd $(CURDIR)
pytest tests/
# Game-specific unit tests - usage: make unit-test GAME=tower_treasures
# Runs all unit tests for the specified game
unit-test:
ifndef GAME
$(error GAME is not set. Usage: make unit-test GAME=<game_name>)
endif
cd games/$(GAME) && ../../$(VENV_PY) tests/run_tests.py
clean:
rm -rf env __pycache__ *.pyc
find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
find . -type f -name "*.pyc" -delete 2>/dev/null || true
# Validate game configuration
validate:
ifndef GAME
$(error GAME is not set. Usage: make validate GAME=<game_name>)
endif
$(VENV_PY) scripts/validate_config.py $(GAME)
# List all available games
list-games:
$(VENV_PY) scripts/validate_config.py --list
# Run tests with coverage report
coverage:
$(VENV_PY) -m pytest tests/ --cov=src --cov-report=html --cov-report=term-missing
@echo "Coverage report generated in htmlcov/"
# Profile game performance
profile:
ifndef GAME
$(error GAME is not set. Usage: make profile GAME=<game_name>)
endif
$(VENV_PY) scripts/profile_performance.py --game $(GAME) --mode cpu
# Run compression benchmark
benchmark:
ifndef GAME
$(error GAME is not set. Usage: make benchmark GAME=<game_name>)
endif
$(VENV_PY) scripts/benchmark_compression.py --game $(GAME)
# Format code with black and isort
format:
$(VENV_PY) -m black src/ games/ tests/ scripts/ --line-length 100
$(VENV_PY) -m isort src/ games/ tests/ scripts/
# Run linting checks
lint:
$(VENV_PY) -m flake8 src/ --max-line-length 100 --ignore=E501,W503
$(VENV_PY) -m mypy src/ --ignore-missing-imports
# Check code without making changes
check:
$(VENV_PY) -m black src/ games/ tests/ scripts/ --check --line-length 100
$(VENV_PY) -m isort src/ games/ tests/ scripts/ --check-only
.PHONY: help setup run test unit-test clean validate list-games coverage profile benchmark format lint check