Skip to content

Commit

Permalink
Add @MonkeyBreaker's GitHub action for wheel building (#646)
Browse files Browse the repository at this point in the history
* Merge with latest master, do not delete Azure CI, remove Py36, add Py310 and Apple Silicon

* Enable cross-compilation on macOS as done by @MonkeyBreaker in pyflagser and giotto-ph

* Linting in test_rips_complex

* Bump install-boost version to 2.3.1 (latest)

* Bumping cibuildwheel version to 2.9.0 (latest)

Co-authored-by: julian <monkeybreaker@protonmail.com>
  • Loading branch information
ulupo and MonkeyBreaker authored Aug 26, 2022
1 parent 12aa80e commit 7576eb9
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 7 deletions.
97 changes: 97 additions & 0 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: Build Wheels

# https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#onworkflow_dispatchinputs
on :
workflow_dispatch:
inputs:
nightlyRelease:
description: 'Generates wheels for the nightly release'
type: boolean
required: true
default: false

jobs:

build_wheels:
name: Build wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
include:
- os: ubuntu-latest
boost_install_dir: /home/runner/work
- os: macos-latest
boost_install_dir: /Users/runner/work
- os: windows-latest
boost_install_dir: D:\
env:
BOOST_VERSION: 1.76.0

steps:
- uses: actions/checkout@v2

- name: Change name to giotto-tda-nightly
if: ${{ github.event.inputs.nightlyRelease == true }}
run: |
set -e
sed -i "s/'giotto-tda'/'giotto-tda-nightly'/1" setup.py
sed -i 's/"giotto-tda"/"giotto-tda-nightly"/1' setup.py
sed -i "s/__version__.*/__version__ = '$(Build.BuildNumber)'/1" gtda/_version.py
shell: bash

- name: Create directories boost
run: |
cd ${{ matrix.boost_install_dir }}
mkdir -p boost/boost
cd -
- name: Cache boost ${{env.BOOST_VERSION}} in ${{ matrix.boost_install_dir }}
# FIXME For an unknown reason on windows runner, when the cache is hit
# The compilation fails because it doesn't find some headers
# I don't know if the cache is corrupted, for the moment hard to debug
if: ${{ runner.os == 'Linux' || runner.os == 'macOS' }}
uses: actions/cache@v2
id: cache-boost
with:
# Set the default path as the path to cache
path: ${{ matrix.boost_install_dir }}/boost/boost
# Use the version as the key to only cache the correct version
key: 1-boost-${{env.BOOST_VERSION}}

- name: Install boost ${{env.BOOST_VERSION}}
uses: MarkusJx/install-boost@v2.3.1
id: install-boost
if: steps.cache-boost.outputs.cache-hit != 'true'
with:
boost_version: ${{env.BOOST_VERSION}}
boost_install_dir: ${{ matrix.boost_install_dir }}

- name: Build wheels
uses: pypa/cibuildwheel@v2.9.0
env:
# Specify which Python versions to build wheels
# https://cibuildwheel.readthedocs.io/en/stable/options/#build-skip
CIBW_BUILD: "cp37-* cp38-* cp39-* cp310-*"
# Skip 32 bit architectures, musllinux, and i686, and macOS x86_64 wheels for CP3.8 -- CP3.10
CIBW_SKIP: "*-win32 *-musllinux_x86_64 *_i686 cp38-macosx_x86_64 cp39-macosx_x86_64 cp310-macosx_x86_64"
CIBW_BEFORE_BUILD_WINDOWS: python -m pip install cmake && python -m pip install --upgrade pip setuptools && sed -i $'s/\r$//' README.rst && python -m pip install delvewheel
CIBW_BEFORE_BUILD_LINUX: python -m pip install cmake && python -m pip install --upgrade pip setuptools
CIBW_BEFORE_BUILD_MACOS: python -m pip install cmake && python -m pip install --upgrade pip setuptools
CIBW_TEST_COMMAND: python -m pytest --pyargs gtda
# nbformat is needed by plotly: https://github.com/plotly/plotly.py/issues/2159
CIBW_TEST_REQUIRES: pytest hypothesis pandas nbformat
CIBW_ENVIRONMENT_WINDOWS: BOOST_ROOT='${{ matrix.boost_install_dir }}boost\boost'
CIBW_ENVIRONMENT_MACOS: BOOST_ROOT='${{ matrix.boost_install_dir }}/boost'
CIBW_ENVIRONMENT_LINUX: BOOST_ROOT=/host${{ matrix.boost_install_dir }}/boost
CIBW_ENVIRONMENT_PASS_LINUX: BOOST_ROOT
CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: "delvewheel repair -vv -w {dest_dir} {wheel}"
CIBW_MANYLINUX_X86_64_IMAGE: manylinux2014
# Should generate universal2 wheels for CP3.8 -- CP3.10
CIBW_ARCHS_MACOS: x86_64 universal2

- uses: actions/upload-artifact@v2
name: Upload wheels
with:
path: ./wheelhouse/*.whl
3 changes: 1 addition & 2 deletions doc/contributing/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ Contributing

This page contains a summary of what one needs to do to contribute.

..
toctree::
.. toctree::
:maxdepth: 2
:hidden:

Expand Down
6 changes: 4 additions & 2 deletions gtda/externals/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@

from .modules.gtda_bottleneck import bottleneck_distance
from .modules.gtda_wasserstein import wasserstein_distance
from .python import SparseRipsComplex, CechComplex, CubicalComplex, \
PeriodicCubicalComplex, SimplexTree, WitnessComplex, StrongWitnessComplex
from .python import RipsComplex, SparseRipsComplex, CechComplex, \
CubicalComplex, PeriodicCubicalComplex, SimplexTree, WitnessComplex, \
StrongWitnessComplex

__all__ = [
'bottleneck_distance',
'wasserstein_distance',
'RipsComplex',
'SparseRipsComplex',
'CechComplex',
'CubicalComplex',
Expand Down
5 changes: 2 additions & 3 deletions gtda/externals/python/tests/test_rips_complex.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
from .. import RipsComplex, SparseRipsComplex

""" Test comes from
"""Test comes from
https://github.com/GUDHI/gudhi-devel/blob/master/src/python/test/test_rips_complex.py
"""


def test_empty_rips():
rips_complex = RipsComplex()
del(rips_complex)
del rips_complex


def test_sparse_filtered_rips_from_points():
Expand Down
7 changes: 7 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ def build_extension(self, ext):
cmake_args += [f"-DCMAKE_BUILD_TYPE={cfg}"]
build_args += ["--", "-j2"]

if sys.platform.startswith("darwin"):
# Cross-compile support for macOS - respect ARCHFLAGS if set
archs = re.findall(r"-arch (\S+)", os.environ.get("ARCHFLAGS", ""))
if archs:
cmake_args += \
["-DCMAKE_OSX_ARCHITECTURES={}".format(";".join(archs))]

env = os.environ.copy()
env["CXXFLAGS"] = f"{env.get('CXXFLAGS', '')} -DVERSION_INFO="\
f"\\'{self.distribution.get_version()}\\'"
Expand Down

0 comments on commit 7576eb9

Please sign in to comment.