This is an automated email from the ASF dual-hosted git repository. hgruszecki pushed a commit to branch 1889-test-examples in repository https://gitbox.apache.org/repos/asf/iggy.git
commit f915d8c5f4c736dd62747d5d0f69adeea1b2ff9c Author: Huan-Cheng Chang <[email protected]> AuthorDate: Sun Sep 28 17:11:25 2025 +0100 fix --- examples/python/README.md | 2 +- examples/python/basic/consumer.py | 6 +++--- examples/python/basic/producer.py | 8 ++++---- examples/python/getting-started/consumer.py | 6 +++--- examples/python/getting-started/producer.py | 8 ++++---- scripts/run-python-examples-from-readme.sh | 23 ++++++++++++++++++++--- 6 files changed, 35 insertions(+), 18 deletions(-) diff --git a/examples/python/README.md b/examples/python/README.md index 70aa4fa95..1bcee58eb 100644 --- a/examples/python/README.md +++ b/examples/python/README.md @@ -30,7 +30,7 @@ IGGY_HTTP_ENABLED=true IGGY_TCP_ADDRESS=0.0.0.0:8090 cargo run --bin iggy-server and then install Python dependencies: ```bash -pip -r requirements.txt +pip install -r requirements.txt ``` ## Basic Examples diff --git a/examples/python/basic/consumer.py b/examples/python/basic/consumer.py index 8a4829feb..2097f98de 100644 --- a/examples/python/basic/consumer.py +++ b/examples/python/basic/consumer.py @@ -24,9 +24,9 @@ from loguru import logger STREAM_NAME = "sample-stream" TOPIC_NAME = "sample-topic" -STREAM_ID = 1 -TOPIC_ID = 1 -PARTITION_ID = 1 +STREAM_ID = 0 +TOPIC_ID = 0 +PARTITION_ID = 0 BATCHES_LIMIT = 5 ArgNamespace = namedtuple("ArgNamespace", ["connection_string"]) diff --git a/examples/python/basic/producer.py b/examples/python/basic/producer.py index 624074467..e2c6d524b 100644 --- a/examples/python/basic/producer.py +++ b/examples/python/basic/producer.py @@ -25,9 +25,9 @@ from loguru import logger STREAM_NAME = "sample-stream" TOPIC_NAME = "sample-topic" -STREAM_ID = 1 -TOPIC_ID = 1 -PARTITION_ID = 1 +STREAM_ID = 0 +TOPIC_ID = 0 +PARTITION_ID = 0 BATCHES_LIMIT = 5 ArgNamespace = namedtuple("ArgNamespace", ["connection_string"]) @@ -62,7 +62,7 @@ async def init_system(client: IggyClient): logger.info(f"Creating stream with name {STREAM_NAME}...") stream: StreamDetails = await client.get_stream(STREAM_NAME) if stream is None: - await client.create_stream(name=STREAM_NAME, stream_id=STREAM_ID) + await client.create_stream(name=STREAM_NAME) logger.info("Stream was created successfully.") else: logger.warning(f"Stream {stream.name} already exists with ID {stream.id}") diff --git a/examples/python/getting-started/consumer.py b/examples/python/getting-started/consumer.py index 37cb51e69..30a78d5ba 100644 --- a/examples/python/getting-started/consumer.py +++ b/examples/python/getting-started/consumer.py @@ -27,9 +27,9 @@ from loguru import logger STREAM_NAME = "sample-stream" TOPIC_NAME = "sample-topic" -STREAM_ID = 1 -TOPIC_ID = 1 -PARTITION_ID = 1 +STREAM_ID = 0 +TOPIC_ID = 0 +PARTITION_ID = 0 BATCHES_LIMIT = 5 ArgNamespace = namedtuple("ArgNamespace", ["tcp_server_address"]) diff --git a/examples/python/getting-started/producer.py b/examples/python/getting-started/producer.py index 71ccb2232..36445bfac 100644 --- a/examples/python/getting-started/producer.py +++ b/examples/python/getting-started/producer.py @@ -28,9 +28,9 @@ from loguru import logger STREAM_NAME = "sample-stream" TOPIC_NAME = "sample-topic" -STREAM_ID = 1 -TOPIC_ID = 1 -PARTITION_ID = 1 +STREAM_ID = 0 +TOPIC_ID = 0 +PARTITION_ID = 0 BATCHES_LIMIT = 5 ArgNamespace = namedtuple("ArgNamespace", ["tcp_server_address"]) @@ -78,7 +78,7 @@ async def init_system(client: IggyClient): logger.info(f"Creating stream with name {STREAM_NAME}...") stream: StreamDetails = await client.get_stream(STREAM_NAME) if stream is None: - await client.create_stream(name=STREAM_NAME, stream_id=STREAM_ID) + await client.create_stream(name=STREAM_NAME) logger.info("Stream was created successfully.") else: logger.warning(f"Stream {stream.name} already exists with ID {stream.id}") diff --git a/scripts/run-python-examples-from-readme.sh b/scripts/run-python-examples-from-readme.sh index 7d6fc6997..43abb0648 100755 --- a/scripts/run-python-examples-from-readme.sh +++ b/scripts/run-python-examples-from-readme.sh @@ -76,12 +76,12 @@ echo "Using server binary at ${SERVER_BIN}" # Run iggy server using the prebuilt binary echo "Starting server from ${SERVER_BIN}..." -IGGY_ROOT_USERNAME=iggy IGGY_ROOT_PASSWORD=iggy ${SERVER_BIN} &>${LOG_FILE} & +IGGY_ROOT_USERNAME=iggy IGGY_ROOT_PASSWORD=iggy ${SERVER_BIN} --fresh &>${LOG_FILE} & echo $! >${PID_FILE} # Wait until "Iggy server has started" string is present inside iggy-server.log SERVER_START_TIME=0 -while ! grep -q "Iggy server has started" ${LOG_FILE}; do +while ! grep -q "has started" ${LOG_FILE}; do if [ ${SERVER_START_TIME} -gt ${TIMEOUT} ]; then echo "Server did not start within ${TIMEOUT} seconds." ps fx @@ -95,7 +95,20 @@ done cd examples/python || exit 1 -exit_code=0 +# Set up Python virtual environment and install dependencies +echo "Setting up Python virtual environment..." +python3 -m venv .venv +# shellcheck disable=SC1091 +source .venv/bin/activate + +# Build and install Python SDK from repository +echo "Building Python SDK from repository..." +pip install -q maturin patchelf +(cd ../../foreign/python && maturin develop -q) + +# Install other example dependencies (excluding apache-iggy which we built locally) +echo "Installing example dependencies..." +pip install -q loguru argparse # Execute all example commands from examples/python/README.md and check if they pass or fail exit_code=0 @@ -131,6 +144,10 @@ if [ -f "README.md" ]; then done < <(grep -E "^python " "README.md") fi +# Deactivate and clean up virtual environment +deactivate 2>/dev/null || true +rm -rf .venv + cd ../.. # Terminate server
