-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
127 lines (109 loc) · 4.29 KB
/
Makefile
File metadata and controls
127 lines (109 loc) · 4.29 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
NAME := aredis_om
SYNC_NAME := redis_om
INSTALL_STAMP := .install.stamp
UV := $(shell command -v uv 2> /dev/null)
REDIS_OM_URL ?= redis://localhost:6380?decode_responses=True
DOCKER_COMPOSE := docker compose
CLUSTER_COMPOSE := $(DOCKER_COMPOSE) -f docker-compose.cluster.yml
.DEFAULT_GOAL := help
.PHONY: help
help:
@echo "Please use 'make <target>' where <target> is one of"
@echo ""
@echo " install install packages and prepare environment"
@echo " clean remove all temporary files"
@echo " lint run the code linters"
@echo " format reformat code"
@echo " test run all the tests against redis:8-alpine"
@echo " test_oss run all the tests against redis:latest (OSS)"
@echo " shell open a uv shell"
@echo " redis start a Redis instance with Docker"
@echo " sync generate modules redis_om, tests_sync from aredis_om, tests respectively"
@echo " dist build a redis-om package"
@echo " upload upload distributions to PyPI"
@echo " all equivalent to \"make lint format test\""
@echo ""
@echo "Check the Makefile to know exactly what each target is doing."
install: $(INSTALL_STAMP)
$(INSTALL_STAMP): pyproject.toml
@if [ -z $(UV) ]; then echo "uv could not be found. See https://docs.astral.sh/uv/"; exit 2; fi
$(UV) sync --extra dev
touch $(INSTALL_STAMP)
.PHONY: clean
clean:
find . -type d -name "__pycache__" | xargs rm -rf {};
rm -rf $(INSTALL_STAMP) .coverage .mypy_cache
rm -rf build
rm -rf dist
rm -rf redis_om
rm -rf tests_sync
rm -rf .venv
-$(DOCKER_COMPOSE) down
-$(CLUSTER_COMPOSE) down
.PHONY: dist
dist: $(INSTALL_STAMP) clean sync
$(UV) build
.PHONY: sync
sync: $(INSTALL_STAMP)
$(UV) sync --extra dev
$(UV) run python make_sync.py
.PHONY: lint
lint: $(INSTALL_STAMP) dist
$(UV) run isort --profile=black --lines-after-imports=2 ./tests/ $(NAME) $(SYNC_NAME)
$(UV) run black ./tests/ $(NAME)
$(UV) run flake8 --ignore=W503,E501,F401,E731 ./tests/ $(NAME) $(SYNC_NAME)
$(UV) run mypy ./tests/ $(NAME) $(SYNC_NAME) --ignore-missing-imports --exclude migrate.py --exclude _compat\.py$$
$(UV) run bandit -r $(NAME) $(SYNC_NAME) -s B608
.PHONY: format
format: $(INSTALL_STAMP) sync
$(UV) run isort --profile=black --lines-after-imports=2 ./tests/ $(NAME) $(SYNC_NAME)
$(UV) run black ./tests/ $(NAME) $(SYNC_NAME)
.PHONY: test
test: $(INSTALL_STAMP) sync redis
REDIS_OM_URL=$(REDIS_OM_URL) $(UV) run pytest -n auto -vv ./tests/ ./tests_sync/ --cov-report term-missing --cov $(NAME) $(SYNC_NAME)
$(DOCKER_COMPOSE) down
.PHONY: test_oss
test_oss: $(INSTALL_STAMP) sync redis
# Specifically tests against a local OSS Redis instance via
# docker-compose.yml. Do not use this for CI testing, where we should
# instead have a matrix of Docker images.
REDIS_OM_URL=redis://localhost:6381?decode_responses=True $(UV) run pytest -n auto -vv ./tests/ ./tests_sync/ --cov-report term-missing --cov $(NAME)
.PHONY: shell
shell: $(INSTALL_STAMP)
$(UV) shell
.PHONY: redis
redis:
$(DOCKER_COMPOSE) up -d
.PHONY: redis_cluster
redis_cluster:
$(CLUSTER_COMPOSE) up -d
@echo "Waiting for Redis Cluster nodes to start..."
@sleep 5
@cluster_init_container=$$($(CLUSTER_COMPOSE) ps -q redis-cluster-7001); \
if ! docker exec $$cluster_init_container redis-cli -p 7001 cluster info 2>/dev/null | grep -q "cluster_state:ok"; then \
docker exec $$cluster_init_container redis-cli --cluster create \
127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 \
127.0.0.1:7004 127.0.0.1:7005 127.0.0.1:7006 \
--cluster-replicas 1 --cluster-yes; \
fi
@echo "Waiting for Redis Cluster to become healthy..."
@cluster_init_container=$$($(CLUSTER_COMPOSE) ps -q redis-cluster-7001); \
for attempt in 1 2 3 4 5 6 7 8 9 10; do \
if docker exec $$cluster_init_container redis-cli -p 7001 cluster info 2>/dev/null | grep -q "cluster_state:ok"; then \
exit 0; \
fi; \
sleep 2; \
done; \
echo "Redis Cluster did not become healthy in time" >&2; \
exit 1
.PHONY: test_cluster
test_cluster: $(INSTALL_STAMP) sync redis redis_cluster
REDIS_OM_URL=$(REDIS_OM_URL) $(UV) run pytest -vv ./tests/test_cluster_operations.py
REDIS_OM_URL=$(REDIS_OM_URL) $(UV) run pytest -vv ./tests_sync/test_cluster_operations.py
$(CLUSTER_COMPOSE) down
$(DOCKER_COMPOSE) down
.PHONY: upload
upload: dist
$(UV) run twine upload dist/* --verbose
.PHONY: all
all: lint format test