Skip to content

Commit

Permalink
add build-and-run.sh to python relay server (#98)
Browse files Browse the repository at this point in the history
* add build-and-run.sh to python relay server

* refactor dockerfile to build wheel

* requirements

* SDK_RELAY_HOST

* hardcode to 0.0.0.0

* python fixes and run in venv

* do not hardcore url

* only works with 0.0.0.0
  • Loading branch information
leoromanovsky authored Feb 27, 2025
1 parent 1fa74e4 commit 5c2b812
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 53 deletions.
3 changes: 3 additions & 0 deletions package-testing/python-sdk-relay/.env.SAMPLE
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SDK_REF=main
SDK_RELAY_HOST=localhost
SDK_RELAY_PORT=4000
3 changes: 2 additions & 1 deletion package-testing/python-sdk-relay/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
bin
lib
venv
.venv
tmp
11 changes: 0 additions & 11 deletions package-testing/python-sdk-relay/Dockerfile

This file was deleted.

12 changes: 2 additions & 10 deletions package-testing/python-sdk-relay/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,8 @@

Post test case files to this server and check the results against what's expected.

## Running locally with Docker

Build the docker image:

```shell
docker build -t Eppo-exp/python-sdk-relay .
```

Run the docker container:
## Build and run

```shell
./docker-run.sh
./build-and-run.sh
```
54 changes: 54 additions & 0 deletions package-testing/python-sdk-relay/build-and-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env bash

# Set default values for vars

: "${SDK_REF:=main}"
: "${SDK_RELAY_HOST:=localhost}"
: "${SDK_RELAY_PORT:=4000}"
SDK="https://github.com/Eppo-exp/eppo-multiplatform.git"

# Create a persistent virtual environment.
if [ ! -d ".venv" ]; then
python3 -m venv .venv
fi
source .venv/bin/activate

# checkout the specified ref of the SDK repo, build it, and then insert it into vendors here.
rm -rf tmp
mkdir -p tmp

echo "Cloning ${SDK}@${SDK_REF}"
git clone -b ${SDK_REF} --depth 1 --single-branch ${SDK} tmp || ( echo "Cloning repo failed"; exit 1 )

# TODO: Refactor this into a `build.sh` script that resides in the SDK repo.

# install dependencies

pip install maturin
pip install -r requirements.txt

# Build the wheel file in tmp directory
maturin build --release --out tmp/dist --find-interpreter --manifest-path ./tmp/python-sdk/Cargo.toml

# Get Python version and find matching wheel
PYTHON_VERSION=$(python3 -c 'import sys; print(f"cp{sys.version_info.major}{sys.version_info.minor}")')
echo "Looking for wheel for Python version: ${PYTHON_VERSION}"

WHEEL_FILE=$(find tmp/dist -name "eppo_server_sdk-*-${PYTHON_VERSION}-*.whl" | head -n 1)
echo "Found wheel file: ${WHEEL_FILE}"

if [ -z "$WHEEL_FILE" ]; then
echo "Error: Wheel file not found for Python version ${PYTHON_VERSION}"
echo "Available wheels:"
ls tmp/dist
exit 1
fi

pip install "${WHEEL_FILE}"

# cleanup
rm -rf tmp

# start the relay server
echo "Listening on port ${SDK_RELAY_HOST}:${SDK_RELAY_PORT}"
python3 src/server.py
29 changes: 0 additions & 29 deletions package-testing/python-sdk-relay/docker-run.sh

This file was deleted.

2 changes: 1 addition & 1 deletion package-testing/python-sdk-relay/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
flask
eppo-server-sdk==4.1.0
# eppo-server-sdk installed from local wheel
3 changes: 2 additions & 1 deletion package-testing/python-sdk-relay/src/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ def initialize_client_and_wait():
initialize_client_and_wait()

port = int(environ.get('SDK_RELAY_PORT', 7001))
host = environ.get('SDK_RELAY_HOST', '0.0.0.0')
# host = environ.get('SDK_RELAY_HOST', '0.0.0.0')
host = '0.0.0.0'
print(f"Starting server on {host}:{port}")
app.run(
host=host,
Expand Down

0 comments on commit 5c2b812

Please sign in to comment.