-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathMakefile.dev
More file actions
160 lines (139 loc) · 5.72 KB
/
Copy pathMakefile.dev
File metadata and controls
160 lines (139 loc) · 5.72 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
160
# Development-focused Makefile for Python tools
# This extends the main Makefile with development-specific commands
# Include main Makefile
include Makefile
# Development-specific variables
PYTHON = python3.12
PIP = pip
VENV_ACTIVATE = source venv/bin/activate
TEST_DIR = tests
COVERAGE_DIR = htmlcov
# Colors
BLUE = \033[0;34m
PURPLE = \033[0;35m
CYAN = \033[0;36m
.PHONY: dev-help dev-setup dev-install dev-format dev-lint dev-type-check dev-test dev-test-coverage dev-pre-commit dev-clean-dev
# Development help
dev-help:
@echo "$(BLUE)Development Commands for Home Assistant Config Tools$(NC)"
@echo ""
@echo "$(CYAN)Setup & Installation:$(NC)"
@echo " $(YELLOW)dev-setup$(NC) - Complete development environment setup"
@echo " $(YELLOW)dev-install$(NC) - Install development dependencies"
@echo ""
@echo "$(CYAN)Code Quality:$(NC)"
@echo " $(YELLOW)dev-format$(NC) - Format code with black and isort"
@echo " $(YELLOW)dev-lint$(NC) - Run all linters (flake8, pylint)"
@echo " $(YELLOW)dev-type-check$(NC) - Run mypy type checking"
@echo " $(YELLOW)dev-check-all$(NC) - Run all code quality checks"
@echo ""
@echo "$(CYAN)Testing:$(NC)"
@echo " $(YELLOW)dev-test$(NC) - Run pytest tests"
@echo " $(YELLOW)dev-test-coverage$(NC) - Run tests with coverage report"
@echo " $(YELLOW)dev-test-verbose$(NC) - Run tests with verbose output"
@echo ""
@echo "$(CYAN)Pre-commit:$(NC)"
@echo " $(YELLOW)dev-pre-commit$(NC) - Install and run pre-commit hooks"
@echo " $(YELLOW)dev-pre-commit-all$(NC) - Run pre-commit on all files"
@echo ""
@echo "$(CYAN)Maintenance:$(NC)"
@echo " $(YELLOW)dev-clean-dev$(NC) - Clean development artifacts"
@echo " $(YELLOW)dev-update-deps$(NC) - Update development dependencies"
# Complete development setup
dev-setup: dev-install dev-pre-commit
@echo "$(GREEN)Development environment setup complete!$(NC)"
@echo "$(CYAN)You can now run:$(NC)"
@echo " make -f Makefile.dev dev-format # Format code"
@echo " make -f Makefile.dev dev-lint # Check code quality"
@echo " make -f Makefile.dev dev-test # Run tests"
# Install development dependencies
dev-install:
@echo "$(GREEN)Installing development dependencies...$(NC)"
@if [ ! -L "venv" ]; then echo "$(RED)Error: venv symlink not found$(NC)"; exit 1; fi
@$(VENV_ACTIVATE) && $(PIP) install --upgrade pip
@$(VENV_ACTIVATE) && $(PIP) install -r requirements-dev.txt
@echo "$(GREEN)Development dependencies installed!$(NC)"
# Format code
dev-format:
@echo "$(GREEN)Formatting code with black and isort...$(NC)"
@$(VENV_ACTIVATE) && black . --extend-exclude 'venv/|\.venv/|config/|temp/' --line-length 88
@$(VENV_ACTIVATE) && isort . --extend-skip-glob 'venv/*,config/*,temp/*' --profile black
@echo "$(GREEN)Code formatting complete!$(NC)"
# Run linters
dev-lint:
@echo "$(GREEN)Running linters...$(NC)"
@echo "$(CYAN)Running flake8...$(NC)"
@$(VENV_ACTIVATE) && flake8 tools/
@echo "$(CYAN)Running pylint...$(NC)"
@$(VENV_ACTIVATE) && pylint tools/
@echo "$(GREEN)Linting complete!$(NC)"
# Type checking
dev-type-check:
@echo "$(GREEN)Running mypy type checking...$(NC)"
@$(VENV_ACTIVATE) && mypy tools/
@echo "$(GREEN)Type checking complete!$(NC)"
# Run all code quality checks
dev-check-all: dev-format dev-lint dev-type-check
@echo "$(GREEN)All code quality checks passed!$(NC)"
# Run tests
dev-test:
@echo "$(GREEN)Running pytest tests...$(NC)"
@$(VENV_ACTIVATE) && pytest $(TEST_DIR) -v
@echo "$(GREEN)Tests complete!$(NC)"
# Run tests with coverage
dev-test-coverage:
@echo "$(GREEN)Running tests with coverage...$(NC)"
@$(VENV_ACTIVATE) && pytest $(TEST_DIR) --cov=tools --cov-report=html --cov-report=term-missing
@echo "$(GREEN)Coverage report generated in $(COVERAGE_DIR)/$(NC)"
# Run tests with verbose output
dev-test-verbose:
@echo "$(GREEN)Running verbose tests...$(NC)"
@$(VENV_ACTIVATE) && pytest $(TEST_DIR) -v -s
@echo "$(GREEN)Verbose tests complete!$(NC)"
# Install and run pre-commit
dev-pre-commit:
@echo "$(GREEN)Setting up pre-commit hooks...$(NC)"
@$(VENV_ACTIVATE) && pre-commit install
@echo "$(GREEN)Pre-commit hooks installed!$(NC)"
# Run pre-commit on all files
dev-pre-commit-all:
@echo "$(GREEN)Running pre-commit on all files...$(NC)"
@$(VENV_ACTIVATE) && pre-commit run --all-files
@echo "$(GREEN)Pre-commit checks complete!$(NC)"
# Clean development artifacts
dev-clean-dev: clean
@echo "$(GREEN)Cleaning development artifacts...$(NC)"
@rm -rf $(COVERAGE_DIR)
@rm -rf .pytest_cache
@rm -rf .mypy_cache
@rm -rf .coverage
@rm -rf dist/
@rm -rf build/
@rm -rf *.egg-info/
@echo "$(GREEN)Development cleanup complete!$(NC)"
# Update development dependencies
dev-update-deps:
@echo "$(GREEN)Updating development dependencies...$(NC)"
@$(VENV_ACTIVATE) && $(PIP) install --upgrade pip
@$(VENV_ACTIVATE) && $(PIP) install --upgrade -r requirements-dev.txt
@echo "$(GREEN)Dependencies updated!$(NC)"
# Create test directory structure if it doesn't exist
dev-init-tests:
@if [ ! -d "$(TEST_DIR)" ]; then \
echo "$(GREEN)Creating test directory structure...$(NC)"; \
mkdir -p $(TEST_DIR); \
touch $(TEST_DIR)/__init__.py; \
touch $(TEST_DIR)/test_yaml_validator.py; \
touch $(TEST_DIR)/test_reference_validator.py; \
touch $(TEST_DIR)/test_entity_explorer.py; \
echo "$(GREEN)Test directory structure created!$(NC)"; \
fi
# Development workflow shortcut
dev-workflow: dev-format dev-lint dev-type-check dev-test
@echo "$(GREEN)Development workflow complete!$(NC)"
@echo "$(CYAN)Code is formatted, linted, type-checked, and tested.$(NC)"
# Watch mode for development (requires entr)
dev-watch:
@echo "$(GREEN)Starting development watch mode...$(NC)"
@echo "$(CYAN)Install 'entr' first: brew install entr$(NC)"
@find tools/ -name "*.py" | entr -c make dev-workflow