forked from HemeraProtocol/hemera-indexer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
88 lines (75 loc) · 2.79 KB
/
Makefile
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
ARCH=amd64
VERSION := $(shell grep '^version = ' pyproject.toml | sed 's/^version = //;s/"//g')
BUILD := `git rev-parse --short=7 HEAD`
TAG := $(VERSION)-$(BUILD)-$(ARCH)
PRE_COMMIT_INSTALLED := $(shell command -v pre-commit > /dev/null 2>&1 && echo yes || echo no)
VENV_DIR := .venv
POETRY_INSTALLED := $(shell command -v poetry > /dev/null 2>&1 && echo yes || echo no)
IMAGE_FLAGS := $(IMAGE_FLAGS) --platform linux/$(ARCH)
RED=\033[31m
GREEN=\033[32m
YELLOW=\033[33m
RESET=\033[0m
.PHONY: format init_db development image test
image:
@echo "Build tag: $(TAG)"
@echo "Build flags: $(IMAGE_FLAGS)"
docker buildx build $(IMAGE_FLAGS) --network host -t hemera-protocol:$(TAG) . --no-cache
@echo "Built image hemera-protocol:$(TAG)"
test:
@if [ "$(filter-out $@,$(MAKECMDGOALS))" = "" ]; then \
poetry run pytest -vv; \
else \
poetry run pytest -vv -m $(filter-out $@,$(MAKECMDGOALS)); \
fi
format:
ifeq ($(PRE_COMMIT_INSTALLED),yes)
@echo "$(YELLOW)Formatting code...$(RESET)"
@pre-commit run --all-files
else
@echo "Please install pre-commit in your local machine(pip install pre-commit or brew install pre-commit)"
endif
init_db:
@echo "Initializing database..."
poetry run python -m hemera.py init_db
development:
@echo "Setting up development environment..."
@bash -c 'set -euo pipefail; \
PYTHON_CMD=$$(command -v python3 || command -v python); \
if [ -z "$$PYTHON_CMD" ] || ! "$$PYTHON_CMD" --version 2>&1 | grep -q "Python 3"; then \
echo "Python 3 is not found. Please install Python 3 and try again."; \
exit 1; \
fi; \
python_version=$$($$PYTHON_CMD -c "import sys; print(\"{}.{}\".format(sys.version_info.major, sys.version_info.minor))"); \
if ! echo "$$python_version" | grep -qE "^3\.(8|9|10|11)"; then \
echo "Python version $$python_version is not supported. Please use Python 3.8, 3.9, 3.10, or 3.11."; \
exit 1; \
fi; \
echo "Using Python: $$($$PYTHON_CMD --version)"; \
if [ ! -d ".venv" ]; then \
echo "Creating virtual environment..."; \
$$PYTHON_CMD -m venv .venv || { \
echo "Failed to create virtual environment. Installing venv..."; \
sudo apt-get update && sudo apt-get install -y python3-venv && $$PYTHON_CMD -m venv .venv; \
}; \
fi; \
echo "Activating virtual environment..."; \
. .venv/bin/activate; \
if ! pip --version &> /dev/null; then \
echo "Installing pip..."; \
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py; \
$$PYTHON_CMD get-pip.py; \
rm get-pip.py; \
fi; \
if ! poetry --version &> /dev/null; then \
echo "Installing Poetry..."; \
pip install poetry; \
else \
echo "Poetry is already installed."; \
fi; \
echo "Installing project dependencies..."; \
poetry install -v; \
echo "Development environment setup complete."; \
echo ""; \
echo "To activate the virtual environment, run:"; \
echo "source .venv/bin/activate"'