fix: macos workflow #102
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
# 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: | |
push: | |
jobs: | |
build_test: | |
name: Build and Test | |
# container: gudhi/pip_for_gudhi:latest # container allows to compile for older abis, but is not easy to setup... | |
strategy: | |
matrix: | |
python-version: ["3.10", "3.11", "3.12"] | |
os: ["ubuntu-latest", "macos-latest"] #windows fails for some reasons | |
runs-on: ${{ matrix.os }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Setup miniconda | |
uses: conda-incubator/setup-miniconda@v2 | |
with: | |
python-version: ${{ matrix.python-version }} | |
activate-environment: build_test_env | |
channels: conda-forge | |
# channel-priority: true | |
- name: Install build and test dependencies | |
shell: bash -el {0} | |
run: | | |
if [[ ${{ matrix.os }} == "ubuntu-latest" ]]; then | |
conda install mamba -c conda-forge | |
mamba install python=${{matrix.python-version}} pip -c conda-forge | |
mamba install numpy gudhi cython boost boost-cpp tbb tbb-devel pytest scikit-learn matplotlib build joblib tqdm scipy -c conda-forge | |
mamba install cxx-compiler numpy gudhi cython boost boost-cpp tbb tbb-devel pytest scikit-learn matplotlib build joblib tqdm scipy -c conda-forge | |
fi | |
if [[ ${{ matrix.os }} == "macos-latest" ]]; then | |
brew update || true | |
## boost doesn't need to be linked so brew is fine | |
brew install boost || true | |
pip install numpy cython gudhi pytest scikit-learn matplotlib joblib tqdm scipy --upgrade | |
### Installs TBB in the conda env for both archs (brew doesn't propose universal/fat builds) | |
export ARCHFLAGS="-arch arm64 -arch x86_64" | |
git clone --depth 1 https://github.com/oneapi-src/oneTBB.git | |
cd oneTBB | |
mkdir build && cd build | |
cmake -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -DTBB_TEST=OFF .. | |
cmake --build . -j4 | |
cmake --install . | |
cd ../.. | |
#### | |
fi | |
pip install pykeops filtration-domination --upgrade | |
- name: Build package | |
shell: bash -el {0} | |
run: | | |
python setup.py sdist | |
if [[ ${{ matrix.os }} == "macos-latest" ]]; then | |
export CXXFLAGS="-fno-aligned-new" # Macos workaround | |
export CFLAGS="-fno-aligned-new" # Macos workaround | |
## should compile for both architecture | |
export MACOSX_DEPLOYMENT_TARGET="12.0" | |
export _PYTHON_HOST_PLATFORM="macosx-12.0-universal2" | |
python setup.py build_ext -j4 --inplace | |
pip wheel . --wheel-dir dist | |
fi | |
if [[ ${{ matrix.os }} == "ubuntu-latest" ]]; then | |
python setup.py build_ext -j2 --inplace | |
pip wheel . --wheel-dir dist | |
fi | |
- name: Install and Test | |
shell: bash -el {0} | |
run: | | |
pip install dist/*.whl | |
pytest multipers/tests | |
- name: Fix wheels on Linux and Macos | |
shell: bash -el {0} | |
run: | | |
if [[ ${{ matrix.os }} == "ubuntu-latest" ]]; then | |
cd dist | |
pip install auditwheel --upgrade | |
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 | |
mv wheelhouse/*.whl . # retrieves repaired wheels | |
cd .. | |
fi | |
if [[ ${{ matrix.os }} == "macos-latest" ]]; then | |
cd dist | |
pip install delocate --upgrade | |
for wheel_file in multipers*macosx*.whl; do | |
delocate-listdeps $wheel_file | |
delocate-wheel --require-archs universal2 -w wheelhouse -v $wheel_file | |
rm $wheel_file | |
done | |
mv wheelhouse/*.whl . # retrieves repaired wheels | |
cd .. | |
fi | |
- 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 |