Skip to content

Commit

Permalink
Refactor Makefile (#2457)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
dpkp authored Feb 6, 2025
1 parent 661f814 commit bfbee93
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 33 deletions.
16 changes: 5 additions & 11 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,10 @@ jobs:
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 11
- name: Check Java installation
run: source travis_java_install.sh
- name: Pull Kafka releases
run: ./build_integration.sh
java-version: 21
- name: Pull Kafka release
run: make servers/${{ matrix.kafka }}/kafka-bin
- name: Pytest
run: make test
env:
PLATFORM: ${{ matrix.platform }}
KAFKA_VERSION: ${{ matrix.kafka }}
- name: Test with tox
run: tox
env:
PLATFORM: ${{ matrix.platform }}
KAFKA_VERSION: ${{ matrix.kafka }}
86 changes: 66 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
# Some simple testing tasks (sorry, UNIX only).
# Some simple testing tasks

FLAGS=
KAFKA_VERSION=0.11.0.2
SCALA_VERSION=2.12
SHELL = bash

export KAFKA_VERSION ?= 2.4.0
DIST_BASE_URL ?= https://archive.apache.org/dist/kafka/

# Required to support testing old kafka versions on newer java releases
# The performance opts defaults are set in each kafka brokers bin/kafka_run_class.sh file
# The values here are taken from the 2.4.0 release.
export KAFKA_JVM_PERFORMANCE_OPTS=-server -XX:+UseG1GC -XX:MaxGCPauseMillis=20 -XX:InitiatingHeapOccupancyPercent=35 -XX:+ExplicitGCInvokesConcurrent -Djava.awt.headless=true

setup:
pip install -r requirements-dev.txt
pip install -Ue .

servers/$(KAFKA_VERSION)/kafka-bin:
KAFKA_VERSION=$(KAFKA_VERSION) SCALA_VERSION=$(SCALA_VERSION) ./build_integration.sh

build-integration: servers/$(KAFKA_VERSION)/kafka-bin

# Test and produce coverage using tox. This is the same as is run on Travis
test37: build-integration
KAFKA_VERSION=$(KAFKA_VERSION) SCALA_VERSION=$(SCALA_VERSION) tox -e py37 -- $(FLAGS)
lint:
pylint --recursive=y --errors-only kafka test

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

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

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

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

.PHONY: all test37 test27 test-local cov-local clean doc
.PHONY: all test test-local cov-local clean doc dist publish

kafka_artifact_version=$(lastword $(subst -, ,$(1)))

# Mappings for artifacts -> scala version; any unlisted will use default 2.12
kafka_scala_0_8_0=2.8.0
kafka_scala_0_8_1=2.10
kafka_scala_0_8_1_1=2.10
kafka_scala_0_8_2_0=2.11
kafka_scala_0_8_2_1=2.11
kafka_scala_0_8_2_2=2.11
kafka_scala_0_9_0_0=2.11
kafka_scala_0_9_0_1=2.11
kafka_scala_0_10_0_0=2.11
kafka_scala_0_10_0_1=2.11
kafka_scala_0_10_1_0=2.11
scala_version=$(if $(SCALA_VERSION),$(SCALA_VERSION),$(if $(kafka_scala_$(subst .,_,$(1))),$(kafka_scala_$(subst .,_,$(1))),2.12))

kafka_artifact_name=kafka_$(call scala_version,$(1))-$(1).$(if $(filter 0.8.0,$(1)),tar.gz,tgz)

build-integration: servers/$(KAFKA_VERSION)/kafka-bin

servers/dist:
mkdir -p servers/dist

servers/dist/kafka_%.tgz servers/dist/kafka_%.tar.gz:
@echo "Downloading $(@F)"
wget -nv -P servers/dist/ -N $(DIST_BASE_URL)$(call kafka_artifact_version,$*)/$(@F)

servers/dist/jakarta.xml.bind-api-2.3.3.jar:
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

# to allow us to derive the prerequisite artifact name from the target name
.SECONDEXPANSION:

servers/%/kafka-bin: servers/dist/$$(call kafka_artifact_name,$$*) | servers/dist
@echo "Extracting kafka $* binaries from $<"
if [ -d "$@" ]; then rm -rf $@.bak; mv $@ $@.bak; fi
mkdir $@
tar xzvf $< -C $@ --strip-components 1
if [[ "$*" < "1" ]]; then make servers/patch-libs/$*; fi

servers/patch-libs/%: servers/dist/jakarta.xml.bind-api-2.3.3.jar | servers/$$*/kafka-bin
cp $< servers/$*/kafka-bin/libs/

servers/download/%: servers/dist/$$(call kafka_artifact_name,$$*) | servers/dist ;

# Avoid removing any pattern match targets as intermediates (without this, .tgz artifacts are removed by make after extraction)
.SECONDARY:
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ Sphinx
sphinx-rtd-theme
tox
xxhash
zstandard
3 changes: 1 addition & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ commands =
setenv =
CRC32C_SW_MODE = auto
PROJECT_ROOT = {toxinidir}
passenv = KAFKA_VERSION

passenv = KAFKA_*

[testenv:pypy]
# pylint is super slow on pypy...
Expand Down

0 comments on commit bfbee93

Please sign in to comment.