-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
165 lines (133 loc) · 6.27 KB
/
Makefile
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
SHELL := /bin/bash
# =============================================================================
# Variables
# =============================================================================
.DEFAULT_GOAL:=help
.ONESHELL:
USING_UV = $(shell grep "tool.uv" pyproject.toml && echo "yes")
VENV_EXISTS = $(shell python3 -c "if __import__('pathlib').Path('.venv/bin/activate').exists(): print('yes')")
UV_OPTS ?=
UV ?= uv $(UV_OPTS)
.EXPORT_ALL_VARIABLES:
.PHONY: help upgrade install-pre-commit install
.PHONY: fmt-fix test coverage check-all lint fmt-check
.PHONY: docs-install docs-clean docs-serve docs-build
.PHONY: clean run-dev-frontend run-dev-server production develop destroy
help: ## Display this help text for Makefile
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z0-9_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
upgrade: ## Upgrade all dependencies to the latest stable versions
@if [ "$(USING_UV)" ]; then $(UV) lock --upgrade
@echo "Dependencies Updated"
# =============================================================================
# Developer Utils
# =============================================================================
install-uv: ## Install latest version of UV
@echo "=> Installing uv"
@curl -LsSf https://astral.sh/uv/install.sh | sh
@echo "=> uv installed"
install-pre-commit: ## Install pre-commit and install hooks
@echo "Installing pre-commit hooks"
@(UV_RUN_BIN) run pre-commit install --install-hooks --all
@(UV_RUN_BIN) run pre-commit install --hook-type commit-msg
@echo "pre-commit installed"
.PHONY: install-frontend
install-frontend: ## Install the frontend dependencies
@echo "=> Installing frontend dependencies"
@nodeenv --python-virtualenv
@npm install
@echo "=> Frontend dependencies installed"
.PHONY: install-backend
install-backend: ## Install the backend dependencies
@echo "=> Installing backend dependencies"
@$(UV) venv && $(UV) pip install --quiet -U wheel setuptools cython mypy pip
@$(UV) sync --all-extras --force-reinstall --dev
@echo "=> Backend dependencies installed"
.PHONY: install
install: clean destroy ## Install the project, dependencies, and pre-commit for local development
@if ! $(UV) --version > /dev/null; then $(MAKE) install-uv; fi
@$(MAKE) install-backend
@$(MAKE) install-frontend
@echo "=> Install complete! Note: If you want to re-install re-run 'make install'"
# =============================================================================
# Tests, Linting, Coverage
# =============================================================================
lint: ## Runs pre-commit hooks; includes ruff linting, codespell, black
@$(UV) run --no-sync pre-commit run --all-files
fmt-check: ## Runs Ruff format in check mode (no changes)
@$(UV) run --no-sync ruff format --check .
fmt: ## Runs Ruff format, makes changes where necessary
@$(UV) run --no-sync ruff format .
ruff: ## Runs Ruff
@$(UV) run --no-sync ruff check . --unsafe-fixes --fix
test: ## Run the tests
@$(UV) run --no-sync pytest tests
coverage: ## Run the tests and generate coverage report
@$(UV) run --no-sync pytest tests --cov=byte_bot
@$(UV) run --no-sync coverage html
@$(UV) run --no-sync coverage xml
check-all: lint test fmt-check coverage ## Run all linting, tests, and coverage checks
# =============================================================================
# Docs
# =============================================================================
docs-clean: ## Dump the existing built docs
@echo "=> Cleaning documentation build assets"
@rm -rf docs/_build
@echo "=> Removed existing documentation build assets"
docs-serve: docs-clean ## Serve the docs locally
@echo "=> Serving documentation"
$(UV) run sphinx-autobuild docs docs/_build/ -j auto --watch byte_bot --watch docs --watch tests --watch CONTRIBUTING.rst --port 8002
docs: docs-clean ## Dump the existing built docs and rebuild them
@echo "=> Building documentation"
@$(UV) run sphinx-build -M html docs docs/_build/ -E -a -j auto --keep-going
# =============================================================================
# Database
# =============================================================================
migrations: ## Generate database migrations
@echo "ATTENTION: This operation will create a new database migration for any defined models changes."
@while [ -z "$$MIGRATION_MESSAGE" ]; do read -r -p "Migration message: " MIGRATION_MESSAGE; done ;
@$(UV) run app database make-migrations --autogenerate -m "$${MIGRATION_MESSAGE}"
.PHONY: migrate
migrate: ## Apply database migrations
@echo "ATTENTION: Will apply all database migrations."
@$(UV) run app database upgrade --no-prompt
.PHONY: db
db: ## Run the database
@docker compose -f "docker-compose.infra.yml" up -d --build
# =============================================================================
# Main
# =============================================================================
clean: ## Autogenerated File Cleanup
@echo "=> Cleaning up autogenerated files"
@rm -rf .scannerwork/
@rm -rf .pytest_cache
@rm -rf .ruff_cache
@rm -rf .hypothesis
@rm -rf build/
@rm -rf dist/
@rm -rf .eggs/
@find . -name '*.egg-info' -exec rm -rf {} +
@find . -name '*.egg' -exec rm -rf {} +
@find . -name '*.pyc' -exec rm -rf {} +
@find . -name '*.pyo' -exec rm -rf {} +
@find . -name '*~' -exec rm -rf {} +
@find . -name '__pycache__' -exec rm -rf {} +
@find . -name '.ipynb_checkpoints' -exec rm -rf {} +
@rm -rf .coverage
@rm -rf coverage.xml
@rm -rf coverage.json
@rm -rf htmlcov/
@rm -rf .pytest_cache
@rm -rf tests/.pytest_cache
@rm -rf tests/**/.pytest_cache
@rm -rf .mypy_cache
$(MAKE) docs-clean
destroy: ## Destroy the virtual environment
@rm -rf .venv
run-dev-bot: ## Run the bot in dev mode
@$(UV) run app run-bot
run-dev-server: ## Run the app in dev mode
@$(UV) run app run-web --http-workers 1 --reload
run-dev-frontend: ## Run the app frontend in dev mode
@$(UV) run tailwindcss -i byte_bot/server/domain/web/resources/input.css -o byte_bot/server/domain/web/resources/style.css --watch
run-dev: ## Run the bot, web, and front end in dev mode
@$(UV) run app run-all --http-workers 1 -d -v --reload