-
-
Notifications
You must be signed in to change notification settings - Fork 98
Expand file tree
/
Copy pathMakefile
More file actions
198 lines (168 loc) · 6.95 KB
/
Copy pathMakefile
File metadata and controls
198 lines (168 loc) · 6.95 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
.PHONY: help venv install test test-cov lint format format-fix format-check manifest server-manifest \
run run-lazy run-eager run-meta version build build-check build-test docker docker-run \
clean console console-debug pre-commit pre-release \
deps-check deps-update info
UV_RUN = cd ../.. && uv run --package unifi-protect-mcp
UV = cd ../.. && uv
help:
@echo "UniFi Protect MCP — Development Commands"
@echo ""
@echo "Setup & Installation:"
@echo " make venv Create virtual environment (requires uv)"
@echo " make install Install dependencies with uv"
@echo ""
@echo "Development:"
@echo " make run Run MCP server locally (lazy mode)"
@echo " make run-lazy Run with lazy loading (default)"
@echo " make run-eager Run with eager loading (all tools)"
@echo " make run-meta Run with meta-only mode"
@echo " make manifest Regenerate tool manifest"
@echo " make console Start interactive dev console"
@echo " make console-debug Start dev console with debug logging"
@echo ""
@echo "Testing & Quality:"
@echo " make test Run tests"
@echo " make test-cov Run tests with coverage"
@echo " make lint Run linters"
@echo " make format Format code"
@echo " make format-fix Auto-fix lint issues"
@echo " make pre-commit Format + manifests + lint + test"
@echo ""
@echo "Build & Release:"
@echo " make version Show current version (from git tags)"
@echo " make build Build package (wheel + sdist)"
@echo " make server-manifest Regenerate server.json for MCP Registry"
@echo " make build-check Build and verify version in package"
@echo " make docker Build Docker image"
@echo " make docker-run Run Docker container"
@echo " make pre-release Full release preparation"
@echo " make clean Clean build artifacts"
@echo ""
@echo "Dependencies:"
@echo " make deps-check Check for outdated dependencies"
@echo " make deps-update Update all dependencies"
# Setup
venv:
@command -v uv >/dev/null 2>&1 || { echo "Error: uv is not installed. Visit https://docs.astral.sh/uv/getting-started/installation/"; exit 1; }
@if [ ! -d "../../.venv" ]; then \
echo "Creating virtual environment..."; \
$(UV) sync; \
else \
echo "Virtual environment already exists."; \
fi
install:
$(UV) sync
# Development
run:
$(UV_RUN) unifi-protect-mcp
run-lazy:
cd ../.. && UNIFI_TOOL_REGISTRATION_MODE=lazy uv run --package unifi-protect-mcp unifi-protect-mcp
run-eager:
cd ../.. && UNIFI_TOOL_REGISTRATION_MODE=eager uv run --package unifi-protect-mcp unifi-protect-mcp
run-meta:
cd ../.. && UNIFI_TOOL_REGISTRATION_MODE=meta_only uv run --package unifi-protect-mcp unifi-protect-mcp
manifest:
$(UV_RUN) python apps/protect/scripts/generate_tool_manifest.py
server-manifest:
$(UV_RUN) python scripts/generate_server_manifest.py --app protect
console:
cd ../.. && UNIFI_TOOL_REGISTRATION_MODE=eager uv run --package unifi-protect-mcp python apps/protect/devtools/dev_console.py
console-debug:
cd ../.. && UNIFI_MCP_LOG_LEVEL=DEBUG UNIFI_TOOL_REGISTRATION_MODE=eager uv run --package unifi-protect-mcp python apps/protect/devtools/dev_console.py
# Testing
test:
$(UV_RUN) pytest apps/protect/tests -v
test-cov:
$(UV_RUN) pytest apps/protect/tests -v --cov=unifi_protect_mcp --cov-report=html --cov-report=term-missing
# Code Quality
lint:
cd ../.. && uv run ruff check apps/protect/src apps/protect/tests
format:
cd ../.. && uv run ruff format apps/protect/src apps/protect/tests
format-fix:
cd ../.. && uv run ruff check apps/protect/src apps/protect/tests --fix
format-check:
cd ../.. && uv run ruff format --check apps/protect/src apps/protect/tests
# Version
version:
@echo "Version Information"
@echo ""
@echo "Git tag: $$(git -C ../.. describe --tags --always 2>/dev/null || echo 'no tags')"
@echo "Package version: $$(cd ../.. && uv run python -c "from importlib.metadata import version; print(version('unifi-protect-mcp'))" 2>/dev/null || echo 'not installed')"
@echo ""
@echo "Version is derived from git tags (e.g., protect/v0.1.0 -> 0.1.0)"
# Build
build: manifest server-manifest
cd ../.. && uv build --package unifi-protect-mcp
build-check: clean manifest server-manifest
@echo "Building and verifying version..."
cd ../.. && uv build --package unifi-protect-mcp
@WHEEL=$$(ls ../../dist/unifi_protect_mcp-*.whl | head -1); \
WHEEL_VERSION=$$(basename $$WHEEL | sed -n 's/unifi_protect_mcp-\([^-]*\)-.*/\1/p'); \
echo "Wheel version: $$WHEEL_VERSION"
build-test: manifest
cd ../.. && uv build --package unifi-protect-mcp --out-dir /tmp/unifi-protect-build-test
# Docker
docker:
@if git -C ../.. describe --tags --match 'protect/v*' HEAD >/dev/null 2>&1; then \
RAW=$$(git -C ../.. describe --tags --match 'protect/v*' HEAD); \
BASE=$$(echo "$$RAW" | sed 's|^protect/v||; s/-.*//'); \
elif git -C ../.. describe --tags --match 'v*' HEAD >/dev/null 2>&1; then \
RAW=$$(git -C ../.. describe --tags --match 'v*' HEAD); \
BASE=$$(echo "$$RAW" | sed 's/^v//; s/-.*//'); \
else \
RAW=""; BASE="0.0.0"; \
fi; \
if [ -n "$$RAW" ] && ! echo "$$RAW" | grep -q '-'; then \
VERSION="$$BASE"; \
else \
COMMITS=$$(git -C ../.. rev-list --count HEAD); \
SHA=$$(git -C ../.. rev-parse --short HEAD); \
VERSION="$${BASE}.dev$${COMMITS}+g$${SHA}"; \
fi; \
echo "Building Docker image with version: $$VERSION"; \
docker build --build-arg VERSION=$$VERSION -t unifi-protect-mcp:latest -f Dockerfile ../..
docker-run:
docker run --rm --env-file ../../.env unifi-protect-mcp:latest
# Cleanup
clean:
rm -rf build/ dist/ *.egg-info
rm -rf ../../dist/
rm -rf .pytest_cache .coverage htmlcov/
rm -f src/unifi_protect_mcp/_version.py
find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
find . -type f -name "*.pyc" -delete
# Pre-commit / Pre-release
pre-commit: format manifest server-manifest lint test
pre-release: clean manifest server-manifest format lint test build-check
@echo ""
@echo "Release preparation complete!"
@echo ""
@echo "Current version: $$(git -C ../.. describe --tags --always 2>/dev/null)"
@echo ""
@echo "Next steps:"
@echo " 1. Review changes: git status"
@echo " 2. Commit any changes"
@echo " 3. Push to main"
@echo " 4. Tag: git tag protect/v0.X.0"
@echo " 5. Push tag: git push --tags"
# Dependency management
deps-check:
@echo "Checking for outdated dependencies..."
@$(UV) pip list --outdated 2>/dev/null || echo "Run 'uv sync' first"
deps-update:
$(UV) lock --upgrade
$(UV) sync
@echo "Dependencies updated. Run 'make test' to verify."
# Info
info:
@echo "Project Information"
@echo ""
@echo "Python: $$(python --version)"
@echo "UV: $$(uv --version)"
@echo ""
@if [ -f src/unifi_protect_mcp/tools_manifest.json ]; then \
echo "Manifest: exists ($$(python -c "import json; print(json.load(open('src/unifi_protect_mcp/tools_manifest.json'))['count'])" 2>/dev/null || echo '?') tools)"; \
else \
echo "Manifest: MISSING - run 'make manifest'"; \
fi