1- .PHONY : help install test lint build clean publish-test publish
1+ .PHONY : help install install-dev test test-unit test-integration test-stress lint format type-check build clean cassandra-start cassandra-stop cassandra-status cassandra-wait
2+
3+ # Environment setup
4+ CONTAINER_RUNTIME ?= $(shell command -v podman >/dev/null 2>&1 && echo podman || echo docker)
5+ CASSANDRA_CONTACT_POINTS ?= 127.0.0.1
6+ CASSANDRA_PORT ?= 9042
7+ CASSANDRA_IMAGE ?= cassandra:4.1
8+ CASSANDRA_CONTAINER_NAME ?= async-cassandra-bulk-test
29
310help :
411 @echo " Available commands:"
5- @echo " install Install dependencies"
6- @echo " test Run tests"
7- @echo " lint Run linters"
8- @echo " build Build package"
9- @echo " clean Clean build artifacts"
10- @echo " publish-test Publish to TestPyPI"
11- @echo " publish Publish to PyPI"
12+ @echo " "
13+ @echo " Installation:"
14+ @echo " install Install the package"
15+ @echo " install-dev Install with development dependencies"
16+ @echo " "
17+ @echo " Testing:"
18+ @echo " test Run all tests (unit + integration)"
19+ @echo " test-unit Run unit tests only"
20+ @echo " test-integration Run integration tests (auto-manages Cassandra)"
21+ @echo " test-stress Run stress tests"
22+ @echo " "
23+ @echo " Cassandra Management:"
24+ @echo " cassandra-start Start Cassandra container"
25+ @echo " cassandra-stop Stop Cassandra container"
26+ @echo " cassandra-status Check if Cassandra is running"
27+ @echo " cassandra-wait Wait for Cassandra to be ready"
28+ @echo " "
29+ @echo " Code Quality:"
30+ @echo " lint Run linters (ruff, black, isort, mypy)"
31+ @echo " format Format code"
32+ @echo " type-check Run type checking"
33+ @echo " "
34+ @echo " Build:"
35+ @echo " build Build distribution packages"
36+ @echo " clean Clean build artifacts"
37+ @echo " "
38+ @echo " Environment variables:"
39+ @echo " CASSANDRA_CONTACT_POINTS Cassandra contact points (default: 127.0.0.1)"
40+ @echo " CASSANDRA_PORT Cassandra port (default: 9042)"
41+ @echo " SKIP_INTEGRATION_TESTS=1 Skip integration tests"
1242
1343install :
44+ pip install -e .
45+
46+ install-dev :
1447 pip install -e " .[dev,test]"
1548
49+ # Standard test command - runs everything
1650test :
17- pytest tests/
51+ @echo " Running standard test suite..."
52+ @echo " === Running Unit Tests (No Cassandra Required) ==="
53+ pytest tests/unit/ -v
54+ @echo " === Starting Cassandra for Integration Tests ==="
55+ $(MAKE ) cassandra-wait
56+ @echo " === Running Integration Tests ==="
57+ pytest tests/integration/ -v
58+ @echo " === Cleaning up Cassandra ==="
59+ $(MAKE ) cassandra-stop
60+
61+ test-unit :
62+ @echo " Running unit tests (no Cassandra required)..."
63+ pytest tests/unit/ -v --cov=async_cassandra_bulk --cov-report=html
64+
65+ test-integration : cassandra-wait
66+ @echo " Running integration tests..."
67+ CASSANDRA_CONTACT_POINTS=$(CASSANDRA_CONTACT_POINTS ) pytest tests/integration/ -v
68+
69+ test-stress : cassandra-wait
70+ @echo " Running stress tests..."
71+ CASSANDRA_CONTACT_POINTS=$(CASSANDRA_CONTACT_POINTS ) pytest tests/integration/test_stress.py -v
1872
73+ # Code quality
1974lint :
20- ruff check src tests
21- black --check src tests
22- isort --check-only src tests
23- mypy src
75+ @echo " === Running ruff ==="
76+ ruff check src/ tests/
77+ @echo " === Running black ==="
78+ black --check src/ tests/
79+ @echo " === Running isort ==="
80+ isort --check-only src/ tests/
81+ @echo " === Running mypy ==="
82+ mypy src/
2483
84+ format :
85+ black src/ tests/
86+ isort src/ tests/
87+ ruff check --fix src/ tests/
88+
89+ type-check :
90+ mypy src/
91+
92+ # Build
2593build : clean
2694 python -m build
2795
@@ -30,8 +98,63 @@ clean:
3098 find . -type d -name __pycache__ -exec rm -rf {} +
3199 find . -type f -name " *.pyc" -delete
32100
33- publish-test : build
34- python -m twine upload --repository testpypi dist/*
101+ # Cassandra management
102+ cassandra-start :
103+ @echo " Starting Cassandra container..."
104+ @echo " Stopping any existing Cassandra container..."
105+ @$(CONTAINER_RUNTIME ) stop $(CASSANDRA_CONTAINER_NAME ) 2> /dev/null || true
106+ @$(CONTAINER_RUNTIME ) rm -f $(CASSANDRA_CONTAINER_NAME ) 2> /dev/null || true
107+ @$(CONTAINER_RUNTIME ) run -d \
108+ --name $(CASSANDRA_CONTAINER_NAME ) \
109+ -p $(CASSANDRA_PORT ) :9042 \
110+ -e CASSANDRA_CLUSTER_NAME=TestCluster \
111+ -e CASSANDRA_DC=datacenter1 \
112+ -e CASSANDRA_ENDPOINT_SNITCH=GossipingPropertyFileSnitch \
113+ $(CASSANDRA_IMAGE )
114+ @echo " Cassandra container started"
115+
116+ cassandra-stop :
117+ @echo " Stopping Cassandra container..."
118+ @$(CONTAINER_RUNTIME ) stop $(CASSANDRA_CONTAINER_NAME ) 2> /dev/null || true
119+ @$(CONTAINER_RUNTIME ) rm $(CASSANDRA_CONTAINER_NAME ) 2> /dev/null || true
120+ @echo " Cassandra container stopped"
121+
122+ cassandra-status :
123+ @if $(CONTAINER_RUNTIME ) ps --format " {{.Names}}" | grep -q " ^$( CASSANDRA_CONTAINER_NAME) $$ " ; then \
124+ echo " Cassandra container is running" ; \
125+ if $( CONTAINER_RUNTIME) exec $( CASSANDRA_CONTAINER_NAME) nodetool info 2>&1 | grep -q " Native Transport active: true" ; then \
126+ if $( CONTAINER_RUNTIME) exec $( CASSANDRA_CONTAINER_NAME) cqlsh -e " SELECT release_version FROM system.local" 2>&1 | grep -q " [0-9]" ; then \
127+ echo " Cassandra is ready and accepting CQL queries" ; \
128+ else \
129+ echo " Cassandra native transport is active but CQL not ready yet" ; \
130+ fi ; \
131+ else \
132+ echo " Cassandra is starting up..." ; \
133+ fi ; \
134+ else \
135+ echo " Cassandra container is not running" ; \
136+ exit 1; \
137+ fi
35138
36- publish : build
37- python -m twine upload dist/*
139+ cassandra-wait :
140+ @echo " Ensuring Cassandra is ready..."
141+ @if ! nc -z $(CASSANDRA_CONTACT_POINTS ) $(CASSANDRA_PORT ) 2> /dev/null; then \
142+ echo " Cassandra not running on $( CASSANDRA_CONTACT_POINTS) :$( CASSANDRA_PORT) , starting container..." ; \
143+ $(MAKE ) cassandra-start; \
144+ echo " Waiting for Cassandra to be ready..." ; \
145+ for i in $$ (seq 1 60); do \
146+ if $( CONTAINER_RUNTIME) exec $( CASSANDRA_CONTAINER_NAME) nodetool info 2>&1 | grep -q " Native Transport active: true" ; then \
147+ if $( CONTAINER_RUNTIME) exec $( CASSANDRA_CONTAINER_NAME) cqlsh -e " SELECT release_version FROM system.local" 2>&1 | grep -q " [0-9]" ; then \
148+ echo " Cassandra is ready! (verified with SELECT query)" ; \
149+ exit 0; \
150+ fi ; \
151+ fi ; \
152+ printf " ." ; \
153+ sleep 2; \
154+ done ; \
155+ echo " " ; \
156+ echo " Timeout waiting for Cassandra to be ready" ; \
157+ exit 1; \
158+ else \
159+ echo " Cassandra is already running on $( CASSANDRA_CONTACT_POINTS) :$( CASSANDRA_PORT) " ; \
160+ fi
0 commit comments