-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
159 lines (136 loc) · 6.47 KB
/
Makefile
File metadata and controls
159 lines (136 loc) · 6.47 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
157
158
159
.PHONY: help verify test test-cov lint lint-fix format type-check quality clean install setup audit-docs
# Default target
.DEFAULT_GOAL := help
# Color output
BLUE := \033[0;34m
GREEN := \033[0;32m
YELLOW := \033[0;33m
RED := \033[0;31m
NC := \033[0m # No Color
help: ## Show this help message
@echo "$(BLUE)Home Assistant Integration Template - Available Commands$(NC)"
@echo ""
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " $(GREEN)%-20s$(NC) %s\n", $$1, $$2}'
@echo ""
@echo "$(YELLOW)Examples:$(NC)"
@echo " make setup # Initial project setup"
@echo " make quality # Run all quality checks"
@echo " make test-cov # Run tests with coverage report"
verify: ## Verify development environment
@echo "$(BLUE)Verifying development environment...$(NC)"
@python scripts/verify_environment.py
test: ## Run all tests
@echo "$(BLUE)Running tests...$(NC)"
@pytest tests/ -v
test-cov: ## Run tests with coverage report
@echo "$(BLUE)Running tests with coverage...$(NC)"
@pytest tests/ \
--cov=custom_components \
--cov-report=html \
--cov-report=term-missing \
-v
@echo "$(GREEN)Coverage report generated: htmlcov/index.html$(NC)"
test-specific: ## Run specific test file (usage: make test-specific FILE=tests/test_config_flow.py)
@echo "$(BLUE)Running specific test: $(FILE)...$(NC)"
@pytest $(FILE) -v
lint: ## Run Ruff linter
@echo "$(BLUE)Running Ruff linter...$(NC)"
@ruff check custom_components/ tests/ scripts/
lint-fix: ## Run Ruff linter with auto-fix
@echo "$(BLUE)Running Ruff linter with auto-fix...$(NC)"
@ruff check custom_components/ tests/ scripts/ --fix
format: ## Format code with Ruff
@echo "$(BLUE)Formatting code with Ruff...$(NC)"
@ruff format custom_components/ tests/ scripts/
type-check: ## Run mypy type checker
@echo "$(BLUE)Running mypy type checker...$(NC)"
@mypy custom_components/
pre-commit: ## Run pre-commit hooks on all files
@echo "$(BLUE)Running pre-commit hooks...$(NC)"
@pre-commit run --all-files
quality: lint-fix format type-check test ## Run all quality checks (lint, format, type-check, test)
@echo "$(GREEN)All quality checks completed!$(NC)"
clean: ## Remove build artifacts and cache files
@echo "$(BLUE)Cleaning build artifacts...$(NC)"
@rm -rf .pytest_cache/
@rm -rf .mypy_cache/
@rm -rf .ruff_cache/
@rm -rf htmlcov/
@rm -rf .coverage
@rm -rf coverage.xml
@find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
@find . -type f -name "*.pyc" -delete
@echo "$(GREEN)Cleanup complete!$(NC)"
install: ## Install dependencies in virtual environment
@echo "$(BLUE)Installing dependencies...$(NC)"
@pip install -U pip
@pip install homeassistant aiohttp voluptuous
@pip install pytest pytest-asyncio pytest-homeassistant-custom-component pytest-cov
@pip install ruff mypy pre-commit
@echo "$(GREEN)Dependencies installed!$(NC)"
setup: install ## Initial project setup (install + pre-commit hooks)
@echo "$(BLUE)Setting up pre-commit hooks...$(NC)"
@pre-commit install
@echo "$(GREEN)Project setup complete!$(NC)"
@echo "$(YELLOW)Run 'make verify' to check your environment$(NC)"
new-integration: ## Create a new integration from template (usage: make new-integration NAME=my_integration)
@if [ -z "$(NAME)" ]; then \
echo "$(RED)Error: NAME is required$(NC)"; \
echo "Usage: make new-integration NAME=my_integration"; \
exit 1; \
fi
@echo "$(BLUE)Creating new integration: $(NAME)...$(NC)"
@cp -r custom_components/example_integration custom_components/$(NAME)
@echo "$(GREEN)Integration created: custom_components/$(NAME)$(NC)"
@echo "$(YELLOW)Next steps:$(NC)"
@echo " 1. Update custom_components/$(NAME)/manifest.json"
@echo " 2. Update custom_components/$(NAME)/const.py (DOMAIN)"
@echo " 3. Implement your integration logic"
@echo " 4. Run 'make quality' to check your code"
list-integrations: ## List all integrations in custom_components/
@echo "$(BLUE)Integrations in custom_components/:$(NC)"
@ls -1 custom_components/ | grep -v __pycache__ || echo "No integrations found"
coverage-report: ## Open HTML coverage report in browser
@if [ ! -f htmlcov/index.html ]; then \
echo "$(RED)Coverage report not found. Run 'make test-cov' first.$(NC)"; \
exit 1; \
fi
@echo "$(BLUE)Opening coverage report...$(NC)"
@xdg-open htmlcov/index.html 2>/dev/null || open htmlcov/index.html 2>/dev/null || echo "$(YELLOW)Please open htmlcov/index.html manually$(NC)"
ci: ## Simulate CI checks locally
@echo "$(BLUE)Running CI checks locally...$(NC)"
@echo ""
@echo "$(BLUE)[1/4] Linting...$(NC)"
@ruff check custom_components/ tests/ scripts/ || (echo "$(RED)Linting failed$(NC)" && exit 1)
@echo "$(GREEN)✓ Linting passed$(NC)"
@echo ""
@echo "$(BLUE)[2/4] Format check...$(NC)"
@ruff format --check custom_components/ tests/ scripts/ || (echo "$(RED)Format check failed$(NC)" && exit 1)
@echo "$(GREEN)✓ Format check passed$(NC)"
@echo ""
@echo "$(BLUE)[3/4] Type checking...$(NC)"
@mypy custom_components/ || (echo "$(RED)Type check failed$(NC)" && exit 1)
@echo "$(GREEN)✓ Type check passed$(NC)"
@echo ""
@echo "$(BLUE)[4/4] Tests...$(NC)"
@pytest tests/ -v || (echo "$(RED)Tests failed$(NC)" && exit 1)
@echo "$(GREEN)✓ All tests passed$(NC)"
@echo ""
@echo "$(GREEN)All CI checks passed! ✓$(NC)"
watch-test: ## Watch for file changes and run tests automatically (requires entr)
@command -v entr >/dev/null 2>&1 || (echo "$(RED)Error: entr not installed. Install with: sudo apt install entr$(NC)" && exit 1)
@echo "$(BLUE)Watching for file changes... (Ctrl+C to stop)$(NC)"
@find custom_components tests -name "*.py" | entr -c pytest tests/ -v
info: ## Show project information
@echo "$(BLUE)Project Information$(NC)"
@echo " Python version: $$(python --version 2>&1)"
@echo " Home Assistant: $$(pip show homeassistant 2>/dev/null | grep Version | cut -d' ' -f2 || echo 'Not installed')"
@echo " Ruff: $$(ruff --version 2>/dev/null || echo 'Not installed')"
@echo " mypy: $$(mypy --version 2>/dev/null || echo 'Not installed')"
@echo " pytest: $$(pytest --version 2>/dev/null | head -1 || echo 'Not installed')"
@echo " Virtual environment: $$([ -n "$$VIRTUAL_ENV" ] && echo "$$VIRTUAL_ENV" || echo 'Not activated')"
audit-docs: ## Run documentation audit to check doc-code alignment
@echo "$(BLUE)Running documentation audit...$(NC)"
@python scripts/audit_documentation.py --verbose
@echo ""
@echo "$(YELLOW)Tip: Review the audit report and fix any errors or warnings$(NC)"