name: Python Tests
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
jobs:
python-test:
name: Python ${{ matrix.python-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
exclude:
- os: macos-latest
python-version: '3.8'
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
- name: Install system dependencies (Linux)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y fontconfig libfontconfig1-dev
- name: Install system dependencies (macOS)
if: runner.os == 'macos'
run: |
brew install fontconfig
rustup target add aarch64-apple-darwin
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
enable-cache: true
- name: Install dependencies
run: |
uv pip install --system maturin pytest numpy pandas
- name: Build Python package
run: |
cd market-data-source-python
maturin build --release --out ../dist
- name: Install package
shell: bash
run: |
# Find the wheel file (works on all platforms)
WHEEL_FILE=$(ls dist/market_data_source*.whl 2>/dev/null | head -n 1)
if [ -z "$WHEEL_FILE" ]; then
echo "No wheel file found in dist/"
ls -la dist/
exit 1
fi
echo "Installing wheel: $WHEEL_FILE"
uv pip install --system "$WHEEL_FILE" --force-reinstall
- name: Run Python tests
run: |
python -c "import market_data_source; print(f'Version: {market_data_source.__version__}')"
python -c "from market_data_source import MarketDataGenerator; gen = MarketDataGenerator(); print('Generator created successfully')"
- name: Test data generation
run: |
python -c "
from market_data_source import MarketDataGenerator
import json
# Create generator
gen = MarketDataGenerator()
# Generate OHLC data
ohlc_data = gen.generate_series(100)
print(f'Generated {len(ohlc_data)} OHLC records')
# Verify data structure
first = ohlc_data[0]
assert 'timestamp' in first
assert 'open' in first
assert 'high' in first
assert 'low' in first
assert 'close' in first
assert 'volume' in first
print('Data structure validation passed')
"
- name: Test with pytest
run: |
if [ -d "tests" ]; then
pytest tests/ -v
else
echo "No tests directory found"
fi
shell: bash
maturin-develop:
name: Test maturin develop
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: '3.11'
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Install fontconfig dependencies
if: runner.os == 'Linux'
run: |
sudo apt-get update && sudo apt-get install -y libfontconfig1-dev
- name: Install uv
uses: astral-sh/setup-uv@v3
- name: Install maturin
run: uv pip install --system maturin
- name: Test maturin develop
run: |
uv venv .venv
source .venv/bin/activate
maturin develop
python -c "import market_data_source; print(market_data_source.__version__)"
wheel-build:
name: Build wheels for ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: '3.11'
- uses: dtolnay/rust-toolchain@stable
- name: Install fontconfig dependencies
if: runner.os == 'Linux'
run: |
sudo apt-get update && sudo apt-get install -y libfontconfig1-dev
- name: Install maturin
run: pip install maturin
- name: Build wheels
run: maturin build --release --out dist
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-${{ matrix.os }}
path: dist/*.whl
if-no-files-found: error