Adding python bindings #24
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Publish Python Wheels | |
on: | |
push: | |
branches: [ main ] | |
pull_request: | |
branches: [ main ] | |
release: | |
types: [published] | |
workflow_dispatch: | |
jobs: | |
build_wheels_linux: | |
name: Build wheels on Linux | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Install HDF5 | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y libhdf5-dev | |
- name: Build wheels | |
uses: PyO3/maturin-action@v1 | |
with: | |
args: --release --out dist --find-interpreter | |
- name: Upload wheels | |
uses: actions/upload-artifact@v4 | |
with: | |
name: wheels-linux | |
path: dist/*.whl | |
build_wheels_macos: | |
name: Build wheels on macOS | |
runs-on: macos-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Install HDF5 | |
run: | | |
brew install hdf5 | |
- name: Build wheels | |
uses: PyO3/maturin-action@v1 | |
with: | |
args: --release --out dist --find-interpreter | |
- name: Upload wheels | |
uses: actions/upload-artifact@v4 | |
with: | |
name: wheels-macos | |
path: dist/*.whl | |
build_wheels_windows: | |
name: Build wheels on Windows | |
runs-on: windows-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Install h5py for HDF5 support | |
run: | | |
pip install h5py | |
- name: Build wheels | |
uses: PyO3/maturin-action@v1 | |
with: | |
args: --release --out dist --find-interpreter | |
- name: Upload wheels | |
uses: actions/upload-artifact@v4 | |
with: | |
name: wheels-windows | |
path: dist/*.whl | |
build_manylinux: | |
name: Build manylinux wheels | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Build manylinux wheels | |
uses: PyO3/maturin-action@v1 | |
with: | |
target: x86_64-unknown-linux-gnu | |
manylinux: 2014 | |
args: --release --out dist --find-interpreter | |
before-script-linux: | | |
# Install HDF5 development files | |
yum install -y hdf5-devel | |
# Set environment variables for HDF5 | |
export HDF5_DIR=/usr | |
# Ensure the built-in tryrun results are used (from your build.rs) | |
export HDF5_DISABLE_VERSION_CHECK=1 | |
- name: Upload manylinux wheels | |
uses: actions/upload-artifact@v4 | |
with: | |
name: wheels-manylinux | |
path: dist/*.whl | |
test_wheels: | |
name: Test wheels | |
needs: [build_wheels_linux, build_wheels_macos, build_wheels_windows, build_manylinux] | |
runs-on: ${{ matrix.os }} | |
strategy: | |
fail-fast: false | |
matrix: | |
os: [ubuntu-latest, macos-latest, windows-latest] | |
python-version: ["3.8", "3.10"] | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Install HDF5 (Linux) | |
if: runner.os == 'Linux' | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y libhdf5-dev | |
- name: Install HDF5 (macOS) | |
if: runner.os == 'macOS' | |
run: | | |
brew install hdf5 | |
- name: Install HDF5 (Windows) | |
if: runner.os == 'Windows' | |
run: | | |
pip install h5py | |
- name: Download wheels | |
uses: actions/download-artifact@v4 | |
with: | |
path: dist | |
- name: Install package from wheel (Linux) | |
if: runner.os == 'Linux' | |
run: | | |
python -m pip install --upgrade pip | |
python -m pip install pytest | |
# Find appropriate wheel for this Python version | |
WHEEL_PATH=$(find dist/wheels-linux -name "*cp$(python -c 'import sys; print(f"{sys.version_info.major}{sys.version_info.minor}")')*" -o -name "*pp*" | head -n 1) | |
echo "Installing wheel: $WHEEL_PATH" | |
pip install $WHEEL_PATH | |
- name: Install package from wheel (macOS) | |
if: runner.os == 'macOS' | |
run: | | |
python -m pip install --upgrade pip | |
python -m pip install pytest | |
# Find appropriate wheel for this Python version | |
WHEEL_PATH=$(find dist/wheels-macos -name "*cp$(python -c 'import sys; print(f"{sys.version_info.major}{sys.version_info.minor}")')*" -o -name "*pp*" | head -n 1) | |
echo "Installing wheel: $WHEEL_PATH" | |
pip install $WHEEL_PATH | |
- name: Install package from wheel (Windows) | |
if: runner.os == 'Windows' | |
run: | | |
python -m pip install --upgrade pip | |
python -m pip install pytest | |
# Find appropriate wheel for this Python version using PowerShell | |
$PythonVersion = python -c "import sys; print(f'{sys.version_info.major}{sys.version_info.minor}')" | |
$WheelPath = Get-ChildItem -Path "dist\wheels-windows" -Recurse -Filter "*cp$PythonVersion*" | Select-Object -First 1 -ExpandProperty FullName | |
if (-not $WheelPath) { | |
$WheelPath = Get-ChildItem -Path "dist\wheels-windows" -Recurse -Filter "*pp*" | Select-Object -First 1 -ExpandProperty FullName | |
} | |
echo "Installing wheel: $WheelPath" | |
pip install $WheelPath | |
- name: Verify import | |
run: | | |
python -c "import hdf5_nuclear_data_reader; print('Import successful')" | |
- name: Run tests | |
run: | | |
pytest tests/ | |
publish: | |
name: Publish package | |
needs: [test_wheels] | |
runs-on: ubuntu-latest | |
if: github.event_name == 'release' && github.event.action == 'published' | |
steps: | |
- uses: actions/download-artifact@v4 | |
with: | |
path: dist | |
- name: Prepare distribution files | |
run: | | |
mkdir -p dist_combined | |
find dist -name "*.whl" -exec cp {} dist_combined \; | |
ls -la dist_combined/ | |
- name: Publish to PyPI | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
user: __token__ | |
password: ${{ secrets.PYPI_API_TOKEN }} | |
packages-dir: dist_combined/ | |
skip-existing: true |