-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile_deps
More file actions
247 lines (210 loc) · 9.85 KB
/
Makefile_deps
File metadata and controls
247 lines (210 loc) · 9.85 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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
SHELL := /bin/bash
# ANSI color codes
GREEN=\033[0;32m
YELLOW=\033[0;33m
RED=\033[0;31m
BLUE=\033[0;34m
RESET=\033[0m
PROJECT_ROOT=.
PYTHON=PYTHONPATH=$(PROJECT_ROOT):$(PYTHONPATH) rye run python
########################################################
# Check dependencies
########################################################
check_rye: ## Ensure rye is installed
@echo -e "$(YELLOW)🔍Checking rye version...$(RESET)"
@if ! command -v rye > /dev/null 2>&1; then \
echo "$(RED)🚩rye is not installed. Please install rye before proceeding.$(RESET)"; \
exit 1; \
else \
rye --version; \
fi
check_jq: ## Ensure jq is installed
@echo -e "$(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
check_typst: ## Ensure typst is installed
@if ! command -v typst > /dev/null 2>&1; then \
echo "$(RED)typst is not installed. Installing typst...$(RESET)"; \
make install_typst; \
if ! command -v typst > /dev/null 2>&1; then \
echo "$(RED)🚩 typst installation failed. Please install typst manually.$(RESET)"; \
exit 1; \
fi; \
else \
echo -e "$(GREEN)✅typst installed.$(RESET)"; \
fi
check_forge: ## Ensure forge is installed
@if ! command -v forge > /dev/null 2>&1; then \
if [ -f "$$HOME/.foundry/bin/forge" ]; then \
echo "$(YELLOW)Foundry installed but not in PATH, copying to /usr/local/bin...$(RESET)"; \
sudo cp -a "$$HOME/.foundry/bin/forge" /usr/local/bin/forge; \
sudo chmod +x /usr/local/bin/forge; \
echo -e "$(GREEN)✅forge installed to /usr/local/bin/forge$(RESET)"; \
else \
echo "$(RED)forge is not installed. Installing forge...$(RESET)"; \
make install_forge; \
fi; \
else \
echo -e "$(GREEN)✅forge installed.$(RESET)"; \
fi
########################################################
# Setup githooks for formatting
########################################################
setup_githooks: ## Set up githooks for formatting
@echo -e "$(YELLOW)🔨Setting up githooks on post-commit...$(RESET)"
chmod +x .githooks/pre-commit
git config core.hooksPath .githooks
@echo -e "$(GREEN)✅Githooks setup completed.$(RESET)"
########################################################
# Python-used dependencies
########################################################
update_python_dep: check_rye check_typst check_forge ## Update python dependencies using rye
@echo -e "$(YELLOW)🔄Updating python dependencies...$(RESET)"
@rye sync
view_python_venv_size: ## View total size of python virtual environment
@echo -e "$(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 -e "$(GREEN)Python venv size check completed.$(RESET)"
view_python_venv_size_by_libraries: ## View size breakdown of python virtual environment by libraries
@echo -e "$(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 -e "$(GREEN)Python venv size by libraries check completed.$(RESET)"
########################################################
# Auxiliary tooling check/installs
########################################################
install_typst: ## Install typst
@echo -e "$(YELLOW)🔍Installing typst...$(RESET)"
@if [ "$$(uname)" = "Linux" ]; then \
mkdir -p ~/.local/bin; \
wget https://github.com/typst/typst/releases/download/v0.13.1/typst-x86_64-unknown-linux-musl.tar.xz -O /tmp/typst.tar.xz; \
mkdir -p /tmp/typst-temp; \
tar -xf /tmp/typst.tar.xz -C /tmp/typst-temp; \
mv /tmp/typst-temp/typst-x86_64-unknown-linux-musl/typst ~/.local/bin/typst; \
chmod +x ~/.local/bin/typst; \
rm -rf /tmp/typst-temp /tmp/typst.tar.xz; \
echo -e "$(GREEN)✅typst installed to ~/.local/bin/typst$(RESET)"; \
echo -e "$(YELLOW)Make sure ~/.local/bin is in your PATH$(RESET)"; \
sudo apt-get install -y fonts-noto-color-emoji fonts-jetbrains-mono; \
elif [ "$$(uname)" = "Darwin" ]; then \
brew install typst; \
brew install --cask font-noto-color-emoji; \
brew install --cask font-jetbrains-mono; \
else \
echo "$(RED)Unsupported platform: $$(uname)$(RESET)" && exit 1; \
fi
@echo -e "$(GREEN)✅typst installed.$(RESET)"
install_forge: ## Install forge
@echo -e "$(YELLOW)🔍Installing forge...$(RESET)"
@curl -L https://foundry.paradigm.xyz | bash
# Calculate foundry bin dir:
@BASE_DIR="$${XDG_CONFIG_HOME:-$$HOME}" && \
FOUNDRY_DIR="$${FOUNDRY_DIR:-$$BASE_DIR/.foundry}" && \
FOUNDRY_BIN_DIR="$$FOUNDRY_DIR/bin" && \
$$FOUNDRY_BIN_DIR/foundryup && \
cp -a $$FOUNDRY_BIN_DIR/forge /usr/local/bin/forge
@echo -e "$(GREEN)✅forge installed.$(RESET)"
install_gcloud_cli: ## Install gcloud cli
@echo -e "$(YELLOW)🔍Installing gcloud cli...$(RESET)"
@curl https://sdk.cloud.google.com | bash
@echo -e "$(GREEN)✅gcloud cli installed.$(RESET)"
install_docker_compose: ## Install docker compose
@echo -e "$(YELLOW)🔍Installing docker compose...$(RESET)"
@if [ "$$(uname)" = "Linux" ]; then \
sudo apt-get update && sudo apt-get install docker-compose-plugin; \
elif [ "$$(uname)" = "Darwin" ]; then \
brew install docker-compose; \
fi
@echo -e "$(GREEN)✅docker compose installed.$(RESET)"
check_solc: check_rye ## Check and use latest solc version
@echo -e "$(YELLOW)🔍Checking and using latest solc version...$(RESET)"
@if ! rye run solc-select use latest --always-install > /dev/null 2>&1; then \
echo "$(RED)🚩solc somehow failed to install. Please install solc manually.$(RESET)"; \
exit 1; \
fi
@echo -e "$(YELLOW)Solc version:$(RESET)"
@rye run solc --version | tail -n 1
@echo -e "$(GREEN)✅Solc is installed$(RESET)"
########################################################
# Linting
########################################################
IGNORE_LINT_DIRS = deps foundryeval .venv venv hackbot/tests/utils/test_foundry_repo/lib
LINE_LENGTH = 100
LINT_DIR = $(PROJECT_ROOT)/hackbot
# Convert IGNORE_LINT_DIRS to a regex pattern
IGNORE_LINT_REGEX = $(shell echo $(IGNORE_LINT_DIRS) | sed 's/ /|/g')
format: check_rye ## Format code with black
@echo -e "$(YELLOW)✨Formatting project with Black...$(RESET)"
@rye run black --exclude '($(IGNORE_LINT_REGEX))/.*' $(LINT_DIR) --line-length $(LINE_LENGTH)
@printf "%bFormatting completed.%b\n" "$(GREEN)" "$(RESET)"
lint: check_rye check_jq ## Lint code with ruff
@echo -e "$(YELLOW)✨Linting project with Ruff...$(RESET)"
@rye run ruff check $(LINT_DIR) --extend-exclude '/($(IGNORE_LINT_DIRS))/'
@echo -e "$(GREEN)✅Ruff linting completed.$(RESET)"
lint-fix: check_rye check_jq ## Lint code with ruff and fix
@echo -e "$(YELLOW)✨Linting project with Ruff...$(RESET)"
@rye run ruff check $(LINT_DIR) --extend-exclude '/($(IGNORE_LINT_DIRS))/' --fix
@echo -e "$(GREEN)✅Ruff linting completed.$(RESET)"
code-check: format lint update_python_dep ## Format and lint code
@echo -e "$(GREEN)✅Code check completed.$(RESET)"
########################################################
# Heavier checks
########################################################
vulture: ## Run vulture dead-code checking
@echo -e "$(YELLOW)🔍Running vulture dead-code checking...$(RESET)"
@rye run vulture
@echo -e "$(GREEN)✅Vulture dead-code checking completed.$(RESET)"
ruff: ## Run ruff type checking
@echo -e "$(YELLOW)🔍Running ruff checking...$(RESET)"
@rye run ruff check hackbot api common
@echo -e "$(GREEN)✅Ruff checking completed.$(RESET)"
typecheck: code-check ruff vulture ## Type check code with pyright
@echo -e "$(YELLOW)🔍Type checking project with pyright...$(RESET)"
@rye run python -m basedpyright
@echo -e "$(GREEN)✅Pyright type checking completed.$(RESET)"
only-typecheck: ## Type check code with pyright
@echo -e "$(YELLOW)🔍Type checking project with pyright...$(RESET)"
@rye run python -m basedpyright
@echo -e "$(GREEN)✅Pyright type checking completed.$(RESET)"
only-vulture: ## Run vulture dead-code checking
@echo -e "$(YELLOW)🔍Running vulture dead-code checking...$(RESET)"
@rye run vulture
@echo -e "$(GREEN)✅Vulture dead-code checking completed.$(RESET)"
########################################################
# Local tests like in main CI
########################################################
# Conveniently groups the main CI runs typecheck, hackbot_deterministic_test, hackbot_api_test
ci_local: typecheck hackbot_deterministic_test hackbot_api_test ## Run most of the CI tests locally
@echo -e "$(GREEN)✅Local CI tests completed.$(RESET)"
########################################################
# General repo prep/dep install
########################################################
install_package_manager_deps: ## Install system dependencies
@echo -e "$(YELLOW)Installing system dependencies...$(RESET)"
@if [ "$$(uname)" = "Linux" ]; then \
sudo apt-get update && \
sudo apt-get install -y libomp-dev default-jdk clang npm; \
elif [ "$$(uname)" = "Darwin" ]; then \
brew install libomp openjdk npm; \
else \
echo "$(RED)Unsupported platform: $$(uname)$(RESET)" && exit 1; \
fi
@echo -e "$(YELLOW)Installing/upgrading node...$(RESET)"
@sudo npm install -g n
@sudo n stable
@echo -e "$(YELLOW)Installing rye...$(RESET)"
@if ! command -v rye > /dev/null 2>&1; then \
curl -sSf https://rye.astral.sh/get | bash; \
source "$${HOME}/.rye/env"; \
fi
@echo -e "$(GREEN)✅System dependencies installed.$(RESET)"
install_deps: check_rye check_jq update_python_dep setup_githooks check_solc install_package_manager_deps ## Install all dependencies
@echo -e "$(GREEN)✅All dependencies installed.$(RESET)"
install_nonsystem_deps: check_jq check_solc update_python_dep ## Install non-system dependencies
@echo -e "$(GREEN)✅Non-system dependencies installed.$(RESET)"