Skip to content

Build, test, and Push to PyPI #227

Build, test, and Push to PyPI

Build, test, and Push to PyPI #227

Workflow file for this run

# This workflow will upload a Python Package using Twine when a release is created
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
name: Build, test, and Push to PyPI
on:
[workflow_dispatch]
jobs:
build_test:
name: Build and Test
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12"]
os: ["ubuntu-latest", "macos-13", "macos-14"] # windows fails, macos13 is x86_64 and macos-latest=14 is arm64
# monitor https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners/about-github-hosted-runners#standard-github-hosted-runners-for-public-repositories
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: mamba-org/setup-micromamba@v2
with:
micromamba-version: 'latest'
init-shell: >-
bash
powershell
condarc: |
channels:
- conda-forge
- name: Install build and test dependencies
shell: bash -el {0}
run: |
micromamba create -n build python=${{matrix.python-version}} pip -c conda-forge
micromamba activate build
micromamba install boost-cpp 'gudhi>=3.10' 'numpy>=2' pot 'cython>=3' pytest scikit-learn matplotlib boost joblib tqdm scipy tbb tbb-devel -c conda-forge
pip install pykeops filtration-domination --upgrade
# tbb, boost are installed in the conda env: sets some variables.
micromamba install c-compiler=1.6 cxx-compiler=1.6 -c conda-forge
- name: Build package
shell: bash -el {0}
run: |
micromamba activate build
python setup.py sdist
if [[ ${{ matrix.os }} =~ "macos-".* ]]; then
export CXXFLAGS="-fno-aligned-new" # Macos workaround
export CFLAGS="-fno-aligned-new" # Macos workaround
## should compile for both architecture
## initialize below ?
export MACOSX_DEPLOYMENT_TARGET="13.0"
# export _PYTHON_HOST_PLATFORM="macosx-13.0-universal2"
fi
if [[ ${{ matrix.os }} =~ "ubuntu-".* ]]; then
export CXXFLAGS="-march=x86-64-v3" # post haswell, for avx
export CFLAGS="-march=x86-64-v3"
fi
python setup.py build_ext -j4 --inplace bdist_wheel
- name: Fix wheels on Linux and Macos
shell: bash -el {0}
run: |
micromamba activate build
cd dist
if [[ ${{ matrix.os }} =~ "ubuntu-".* ]]; then
micromamba install auditwheel patchelf
for wheel_file in multipers*linux*.whl; do
auditwheel show $wheel_file
auditwheel repair $wheel_file --plat manylinux_2_34_x86_64
rm $wheel_file
done
fi
if [[ ${{ matrix.os }} == "macos-13" ]]; then
micromamba install delocate
for wheel_file in multipers*macosx*x86*.whl; do
delocate-listdeps $wheel_file
delocate-wheel --require-archs x86_64 -w wheelhouse -v $wheel_file
rm $wheel_file
done
fi
if [[ ${{ matrix.os }} == "macos-14" ]]; then
pip install delocate --upgrade
for wheel_file in multipers*macosx*arm64*.whl; do
delocate-listdeps $wheel_file
delocate-wheel --require-archs arm64 -w wheelhouse -v $wheel_file
rm $wheel_file
done
fi
mv wheelhouse/*.whl . # retrieves repaired wheels
cd ..
- name: Install and Test
shell: bash -el {0}
run: |
# Fresh env
micromamba create -n test python=${{matrix.python-version}} pip pytest -c conda-forge
micromamba activate test
pip install dist/*.whl --force-reinstall
pytest multipers/tests
- name: Upload sources and wheel
uses: actions/upload-artifact@v3
with:
name: sources
path: dist
send_to_pypi:
name: Send sources and wheels
runs-on: ubuntu-latest
needs: [ build_test ]
steps:
- uses: actions/download-artifact@v3
with:
name: sources
- uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Publish to PyPI
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: |
pip install --upgrade pip twine
twine upload --skip-existing *.tar.gz # sources
twine upload --skip-existing *.whl # wheels