Skip to content

Commit bfbee93

Browse files
authored
Refactor Makefile (#2457)
* handle artifact downloads; patch libs on install for kafka < 1 * export env vars * no progressbar for wget * Add lint: target; call pytest directly in test: recipe * Use make targets in gh workflow; use java 21; drop java helper script * add zstandard to requirements-dev
1 parent 661f814 commit bfbee93

File tree

4 files changed

+73
-33
lines changed

4 files changed

+73
-33
lines changed

.github/workflows/python-package.yml

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,10 @@ jobs:
7070
uses: actions/setup-java@v4
7171
with:
7272
distribution: temurin
73-
java-version: 11
74-
- name: Check Java installation
75-
run: source travis_java_install.sh
76-
- name: Pull Kafka releases
77-
run: ./build_integration.sh
73+
java-version: 21
74+
- name: Pull Kafka release
75+
run: make servers/${{ matrix.kafka }}/kafka-bin
76+
- name: Pytest
77+
run: make test
7878
env:
79-
PLATFORM: ${{ matrix.platform }}
80-
KAFKA_VERSION: ${{ matrix.kafka }}
81-
- name: Test with tox
82-
run: tox
83-
env:
84-
PLATFORM: ${{ matrix.platform }}
8579
KAFKA_VERSION: ${{ matrix.kafka }}

Makefile

Lines changed: 66 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,33 @@
1-
# Some simple testing tasks (sorry, UNIX only).
1+
# Some simple testing tasks
22

3-
FLAGS=
4-
KAFKA_VERSION=0.11.0.2
5-
SCALA_VERSION=2.12
3+
SHELL = bash
4+
5+
export KAFKA_VERSION ?= 2.4.0
6+
DIST_BASE_URL ?= https://archive.apache.org/dist/kafka/
7+
8+
# Required to support testing old kafka versions on newer java releases
9+
# The performance opts defaults are set in each kafka brokers bin/kafka_run_class.sh file
10+
# The values here are taken from the 2.4.0 release.
11+
export KAFKA_JVM_PERFORMANCE_OPTS=-server -XX:+UseG1GC -XX:MaxGCPauseMillis=20 -XX:InitiatingHeapOccupancyPercent=35 -XX:+ExplicitGCInvokesConcurrent -Djava.awt.headless=true
612

713
setup:
814
pip install -r requirements-dev.txt
915
pip install -Ue .
1016

11-
servers/$(KAFKA_VERSION)/kafka-bin:
12-
KAFKA_VERSION=$(KAFKA_VERSION) SCALA_VERSION=$(SCALA_VERSION) ./build_integration.sh
13-
14-
build-integration: servers/$(KAFKA_VERSION)/kafka-bin
15-
16-
# Test and produce coverage using tox. This is the same as is run on Travis
17-
test37: build-integration
18-
KAFKA_VERSION=$(KAFKA_VERSION) SCALA_VERSION=$(SCALA_VERSION) tox -e py37 -- $(FLAGS)
17+
lint:
18+
pylint --recursive=y --errors-only kafka test
1919

20-
test27: build-integration
21-
KAFKA_VERSION=$(KAFKA_VERSION) SCALA_VERSION=$(SCALA_VERSION) tox -e py27 -- $(FLAGS)
20+
test: build-integration
21+
pytest --durations=10 kafka test
2222

2323
# Test using pytest directly if you want to use local python. Useful for other
2424
# platforms that require manual installation for C libraries, ie. Windows.
2525
test-local: build-integration
26-
KAFKA_VERSION=$(KAFKA_VERSION) SCALA_VERSION=$(SCALA_VERSION) pytest \
27-
--pylint --pylint-rcfile=pylint.rc --pylint-error-types=EF $(FLAGS) kafka test
26+
pytest --pylint --pylint-rcfile=pylint.rc --pylint-error-types=EF $(TEST_FLAGS) kafka test
2827

2928
cov-local: build-integration
30-
KAFKA_VERSION=$(KAFKA_VERSION) SCALA_VERSION=$(SCALA_VERSION) pytest \
31-
--pylint --pylint-rcfile=pylint.rc --pylint-error-types=EF --cov=kafka \
32-
--cov-config=.covrc --cov-report html $(FLAGS) kafka test
29+
pytest --pylint --pylint-rcfile=pylint.rc --pylint-error-types=EF --cov=kafka \
30+
--cov-config=.covrc --cov-report html $(TEST_FLAGS) kafka test
3331
@echo "open file://`pwd`/htmlcov/index.html"
3432

3533
# Check the readme for syntax errors, which can lead to invalid formatting on
@@ -56,4 +54,52 @@ doc:
5654
make -C docs html
5755
@echo "open file://`pwd`/docs/_build/html/index.html"
5856

59-
.PHONY: all test37 test27 test-local cov-local clean doc
57+
.PHONY: all test test-local cov-local clean doc dist publish
58+
59+
kafka_artifact_version=$(lastword $(subst -, ,$(1)))
60+
61+
# Mappings for artifacts -> scala version; any unlisted will use default 2.12
62+
kafka_scala_0_8_0=2.8.0
63+
kafka_scala_0_8_1=2.10
64+
kafka_scala_0_8_1_1=2.10
65+
kafka_scala_0_8_2_0=2.11
66+
kafka_scala_0_8_2_1=2.11
67+
kafka_scala_0_8_2_2=2.11
68+
kafka_scala_0_9_0_0=2.11
69+
kafka_scala_0_9_0_1=2.11
70+
kafka_scala_0_10_0_0=2.11
71+
kafka_scala_0_10_0_1=2.11
72+
kafka_scala_0_10_1_0=2.11
73+
scala_version=$(if $(SCALA_VERSION),$(SCALA_VERSION),$(if $(kafka_scala_$(subst .,_,$(1))),$(kafka_scala_$(subst .,_,$(1))),2.12))
74+
75+
kafka_artifact_name=kafka_$(call scala_version,$(1))-$(1).$(if $(filter 0.8.0,$(1)),tar.gz,tgz)
76+
77+
build-integration: servers/$(KAFKA_VERSION)/kafka-bin
78+
79+
servers/dist:
80+
mkdir -p servers/dist
81+
82+
servers/dist/kafka_%.tgz servers/dist/kafka_%.tar.gz:
83+
@echo "Downloading $(@F)"
84+
wget -nv -P servers/dist/ -N $(DIST_BASE_URL)$(call kafka_artifact_version,$*)/$(@F)
85+
86+
servers/dist/jakarta.xml.bind-api-2.3.3.jar:
87+
wget -nv -P servers/dist/ -N https://repo1.maven.org/maven2/jakarta/xml/bind/jakarta.xml.bind-api/2.3.3/jakarta.xml.bind-api-2.3.3.jar
88+
89+
# to allow us to derive the prerequisite artifact name from the target name
90+
.SECONDEXPANSION:
91+
92+
servers/%/kafka-bin: servers/dist/$$(call kafka_artifact_name,$$*) | servers/dist
93+
@echo "Extracting kafka $* binaries from $<"
94+
if [ -d "$@" ]; then rm -rf $@.bak; mv $@ $@.bak; fi
95+
mkdir $@
96+
tar xzvf $< -C $@ --strip-components 1
97+
if [[ "$*" < "1" ]]; then make servers/patch-libs/$*; fi
98+
99+
servers/patch-libs/%: servers/dist/jakarta.xml.bind-api-2.3.3.jar | servers/$$*/kafka-bin
100+
cp $< servers/$*/kafka-bin/libs/
101+
102+
servers/download/%: servers/dist/$$(call kafka_artifact_name,$$*) | servers/dist ;
103+
104+
# Avoid removing any pattern match targets as intermediates (without this, .tgz artifacts are removed by make after extraction)
105+
.SECONDARY:

requirements-dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ Sphinx
1515
sphinx-rtd-theme
1616
tox
1717
xxhash
18+
zstandard

tox.ini

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ commands =
3333
setenv =
3434
CRC32C_SW_MODE = auto
3535
PROJECT_ROOT = {toxinidir}
36-
passenv = KAFKA_VERSION
37-
36+
passenv = KAFKA_*
3837

3938
[testenv:pypy]
4039
# pylint is super slow on pypy...

0 commit comments

Comments
 (0)