Adding python bindings #48
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_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 | |
- name: Install package from wheel (macos-latest) | |
run: | | |
python -m pip install --upgrade pip | |
python -m pip install pytest | |
# List directory contents to debug | |
echo "Contents of dist directory:" | |
find dist -type f -name "*.whl" | sort | |
python --version | |
pip install dist/hdf5_nuclear_data_reader-0.1.0-cp313-cp313-macosx_11_0_arm64.whl | |
- name: Verify import | |
run: | | |
python -c "import hdf5_nuclear_data_reader; print('Import successful')" | |
- name: Run tests | |
run: | | |
pytest -v | |
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 | |
- name: Install package from wheel (windows-latest) | |
run: | | |
python -m pip install --upgrade pip | |
python -m pip install pytest | |
# List directory contents to debug | |
echo "Contents of dist directory:" | |
dir dist -Filter *.whl | Sort-Object Name | |
python --version | |
pip install dist/hdf5_nuclear_data_reader-0.1.0-cp39-cp39-win_amd64.whl | |
- name: Verify import | |
run: | | |
python -c "import hdf5_nuclear_data_reader; print('Import successful')" | |
- name: Run tests | |
run: | | |
pytest -v | |
build_wheels_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 | |
- name: Install package from wheel (ubuntu-latest) | |
run: | | |
python -m pip install --upgrade pip | |
python -m pip install pytest | |
# List directory contents to debug | |
echo "Contents of dist directory:" | |
find dist -type f -name "*.whl" | sort | |
python --version | |
pip install dist/hdf5_nuclear_data_reader-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | |
- name: Verify import | |
run: | | |
python -c "import hdf5_nuclear_data_reader; print('Import successful')" | |
- name: Run tests | |
run: | | |
pytest -v | |
publish: | |
name: Publish package | |
needs: [build_wheels_manylinux, build_wheels_windows, build_wheels_macos] | |
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 |