Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
148 lines (121 loc) · 5.12 KB
/
Copy pathMakefile
File metadata and controls
148 lines (121 loc) · 5.12 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
# ANSI color codes
GREEN=\033[0;32m
YELLOW=\033[0;33m
RED=\033[0;31m
BLUE=\033[0;34m
RESET=\033[0m
PYTHON=uv run python
TEST=uv run pytest
MIN_UV_VERSION=0.13.5
PROJECT_ROOT=.
########################################################
# Initialization: Delete later
########################################################
banner: check_uv
@echo "$(YELLOW)🔍Generating banner...$(RESET)"
@uv run python -m init.generate_banner
@echo "$(GREEN)✅Banner generated.$(RESET)"
########################################################
# Check dependencies
########################################################
check_uv:
@echo "$(YELLOW)🔍Checking uv version...$(RESET)"
@if ! command -v uv > /dev/null 2>&1; then \
echo "$(RED)uv is not installed. Please install uv before proceeding.$(RESET)"; \
exit 1; \
fi
@uv --version
@UV_VERSION=$$(uv --version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -n1); \
if [ -z "$$UV_VERSION" ]; then \
echo "$(RED)Could not determine uv version from 'uv --version'.$(RESET)"; \
exit 1; \
fi; \
if ! awk -v actual="$$UV_VERSION" -v minimum="$(MIN_UV_VERSION)" 'BEGIN { split(actual, a, /[.]/); split(minimum, m, /[.]/); for (i = 1; i <= 3; i++) { if ((a[i] + 0) < (m[i] + 0)) exit 1; if ((a[i] + 0) > (m[i] + 0)) exit 0 } exit 0 }'; then \
echo "$(RED)uv $$UV_VERSION is too old - this repo needs uv >= $(MIN_UV_VERSION) (eMudhra CA root-store fix, GHSA-hq85-5cpj-mr62).$(RESET)"; \
echo "$(RED)Fix: 'uv self update' or 'uv tool install --force \"uv>=$(MIN_UV_VERSION)\"'.$(RESET)"; \
exit 1; \
fi
check_jq:
@echo "$(YELLOW)🔍Checking jq version...$(RESET)"
@if ! command -v jq > /dev/null 2>&1; then \
echo "$(RED)jq is not installed. Please install jq before proceeding.$(RESET)"; \
echo "$(RED)brew install jq$(RESET)"; \
exit 1; \
else \
jq --version; \
fi
########################################################
# Setup githooks for linting
########################################################
setup_githooks:
@echo "$(YELLOW)🔨Setting up githooks on post-commit...$(RESET)"
chmod +x .githooks/post-commit
git config core.hooksPath .githooks
########################################################
# Python dependency-related
########################################################
update_python_dep: check_uv
@echo "$(YELLOW)🔄Updating python dependencies...$(RESET)"
@uv sync
view_python_venv_size:
@echo "$(YELLOW)🔍Checking python venv size...$(RESET)"
@PYTHON_VERSION=$$(cat .python-version | cut -d. -f1,2) && \
cd .venv/lib/python$$PYTHON_VERSION/site-packages && du -sh . && cd ../../../
@echo "$(GREEN)Python venv size check completed.$(RESET)"
view_python_venv_size_by_libraries:
@echo "$(YELLOW)🔍Checking python venv size by libraries...$(RESET)"
@PYTHON_VERSION=$$(cat .python-version | cut -d. -f1,2) && \
cd .venv/lib/python$$PYTHON_VERSION/site-packages && du -sh * | sort -h && cd ../../../
@echo "$(GREEN)Python venv size by libraries check completed.$(RESET)"
########################################################
# Run Main Application
########################################################
all: update_python_dep setup_githooks
@echo "$(GREEN)🏁Running main application...$(RESET)"
@$(PYTHON) main.py
@echo "$(GREEN)✅ Main application run completed.$(RESET)"
########################################################
# Run Tests
########################################################
TEST_TARGETS = tests/
# Tests
test: check_uv
@echo "$(GREEN)🧪Running Target Tests...$(RESET)"
$(TEST) $(TEST_TARGETS)
@echo "$(GREEN)✅Target Tests Passed.$(RESET)"
########################################################
# Cleaning
########################################################
# Linter will ignore these directories
IGNORE_LINT_DIRS = .venv|venv
LINE_LENGTH = 88
fmt: check_uv check_jq
@echo "$(YELLOW)✨Formatting project with Black...$(RESET)"
@uv run black --exclude '/($(IGNORE_LINT_DIRS))/' . --line-length $(LINE_LENGTH)
@echo "$(YELLOW)✨Formatting JSONs with jq...$(RESET)"
@count=0; \
find . \( $(IGNORE_LINT_DIRS:%=-path './%' -prune -o) \) -type f -name '*.json' -print0 | \
while IFS= read -r -d '' file; do \
if jq . "$$file" > "$$file.tmp" 2>/dev/null && mv "$$file.tmp" "$$file"; then \
count=$$((count + 1)); \
else \
rm -f "$$file.tmp"; \
fi; \
done; \
echo "$(BLUE)$$count JSON file(s)$(RESET) formatted."; \
echo "$(GREEN)✅Formatting completed.$(RESET)"
vulture: check_uv
@echo "$(YELLOW)🔍Running Vulture...$(RESET)"
@uv run vulture .
@echo "$(GREEN)✅Vulture completed.$(RESET)"
lint_immutable_refs: ## Fail if a Dockerfile or GitHub Actions file uses a mutable image tag or action ref
@echo "$(YELLOW)🔍Checking for mutable image/action references...$(RESET)"
@python3 scripts/check_immutable_refs.py
@echo "$(GREEN)✅All non-exempt references are pinned.$(RESET)"
########################################################
# Dependencies
########################################################
requirements:
@echo "$(YELLOW)🔍Checking requirements...$(RESET)"
@uv export --quiet --format requirements-txt --no-hashes --no-emit-project -o requirements.txt
@echo "$(GREEN)✅Requirements checked.$(RESET)"