Skip to content

Commit

Permalink
Streamline and simplify the IB artifact building.
Browse files Browse the repository at this point in the history
  • Loading branch information
chipkent committed Apr 29, 2024
1 parent 780185e commit 65b9ea9
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 16 deletions.
20 changes: 4 additions & 16 deletions .github/workflows/build-and-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,16 @@ jobs:
name: Build IB WHL
runs-on: ubuntu-20.04
steps:
- name: Setup Python
uses: actions/setup-python@v1
with:
python-version: 3.7
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade setuptools wheel build twine
- name: Checkout
uses: actions/checkout@v1
- name: Build
run: |
IB_VERSION_DOWNLOAD=$(echo ${IB_VERSION} | sed 's/[.]//')
echo "Downloading IB API version ${IB_VERSION_DOWNLOAD}"
curl -o ./api.zip "https://interactivebrokers.github.io/downloads/twsapi_macunix.${IB_VERSION_DOWNLOAD}.zip"
unzip api.zip
cd ./IBJts/source/pythonclient
python -m build
run: cd ibwhl && docker-compose -f "docker-compose.yml" up -d --build
- name: Archive build artifacts
uses: actions/upload-artifact@v2
with:
name: ib-wheels
path: |
./IBJts/source/pythonclient/dist/*
ibwhl/dist/*
build-whl:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.idea
venv
build
dist
src/deephaven_ib.egg-info
docker/data
Expand Down
30 changes: 30 additions & 0 deletions ibwhl/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Interactive Brokers Python Wheels Builder

This directory provides a Docker Compose setup for building Python wheels for the Interactive Brokers API.

## Requirements

- Docker
- Docker Compose

## Usage

1. Set the `IB_VERSION` environment variable to the version of Interactive Brokers' API you want to use.
2. Run `docker compose up` from the directory containing the Docker Compose file. This will build the wheels.
3. After the build process is complete, the wheels will be available in the `./dist` directory.
4. To install the wheels, run `pip install ./dist/*.whl`.

> **Note:** Steps 1 and 2 can be combined as `IB_VERSION=10.19.04 docker compose up`.
## Details

The build process is defined in the `build_ibpy.sh` script.
The `./build` directory contains the scratch work for building the wheels.

By using Docker, you can build the wheels in a clean environment that is isolated from your local machine.
This setup will work on any platform that supports Docker.

## Note

Interactive Brokers does not make their Python wheels available via PyPI, and the wheels are not redistributable.
This script lets you build the wheels locally, and then install them via pip.
32 changes: 32 additions & 0 deletions ibwhl/build_ibpy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash

# This script is used to build Python wheels for the Interactive Brokers' API.


# check that IB_VERSION is set
if [ -z "$IB_VERSION" ]; then
echo "IB_VERSION must be set"
exit 1
fi

# IB has a funky versioning scheme, so we need to strip out the periods in some places before download
IB_VERSION_DOWNLOAD=$(echo ${IB_VERSION} | sed 's/[.]//')

rm -rf ./build
rm -rf ./dist

mkdir ./build
mkdir ./dist

pushd ./build

python3 -m pip install build

echo "Downloading IB API version ${IB_VERSION} (${IB_VERSION_DOWNLOAD})"
curl -o ./api.zip "https://interactivebrokers.github.io/downloads/twsapi_macunix.${IB_VERSION_DOWNLOAD}.zip"
unzip api.zip
cd ./IBJts/source/pythonclient
python3 -m build --wheel
popd
cp ./build/IBJts/source/pythonclient/dist/* ./dist/

29 changes: 29 additions & 0 deletions ibwhl/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

# This is a Docker Compose file for building Interactive Brokers python wheels.
# Ideally, the wheels would be published by IB for installation via pip, but
# (1) IB does not make them available via pypi, and
# (2) the wheels are not redistributable.
# This script lets you build the wheels locally, and then install them via pip.
#
# To build the wheels, run `docker-compose up` from the directory containing this file.
# To install the wheels, run `pip install ./dist/*.whl`.
# After running the script, the wheels will be available in the `./dist` directory.
# The `./build` directory contains the scratch work for building the wheels.
#
# The build process is defined in the `build_ibpy.sh` script.
#
# By using Docker, you can build the wheels in a clean environment that is isolated from your local machine.
# It also will work on any platform that supports Docker.

version: '3.8'

services:
build:
image: python:3.10
environment:
- IB_VERSION
volumes:
- .:/app
- ./build:/build
- ./dist:/dist
command: /bin/bash -c "/app/build_ibpy.sh"

0 comments on commit 65b9ea9

Please sign in to comment.