Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

automatically build Python wheels with cibuildwheel and test with pytest #406

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: build

on:
pull_request:
push:
branches:
- master
release:
types:
- released
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true

permissions: read-all

jobs:
cmake:
strategy:
matrix:
runs-on:
- ubuntu-latest
# macos-13 is an intel runner, macos-14 is apple silicon
- macos-13
- macos-latest
fail-fast: false
runs-on: ${{ matrix.runs-on }}
timeout-minutes: 30
steps:
- uses: zacharyburnett/setup-abseil-cpp@de39f445295c887839e30c864ffbbb1c0231bc83 # 1.0.5
with:
cmake-build-args: "-DCMAKE_CXX_STANDARD=17 -DABSL_PROPAGATE_CXX_STD=ON -DABSL_ENABLE_INSTALL=ON -DBUILD_TESTING=off -DCMAKE_POSITION_INDEPENDENT_CODE=ON"
abseil-version: "20240722.0"
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- run: mkdir build
- run: cmake -DCMAKE_CXX_STANDARD=17 -DCMAKE_PREFIX_PATH=/usr/local/ -DBUILD_TESTS=OFF ..
working-directory: build/
- run: sudo cmake --build . --parallel --target=install
working-directory: build/
cibuildwheel:
strategy:
matrix:
# macos-13 is an intel runner, macos-14 is apple silicon
os:
- ubuntu-latest
- macos-13
- macos-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: pypa/cibuildwheel@ee63bf16da6cddfb925f542f2c7b59ad50e93969 # v2.22.0
- uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
with:
name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }}
path: ./wheelhouse/*.whl
53 changes: 53 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: test

on:
pull_request:
push:
branches:
- master
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true

permissions: read-all

env:
GOOGLETEST_VERSION: "1.15.2"

jobs:
ctest:
strategy:
matrix:
runs-on:
- ubuntu-latest
# macos-13 is an intel runner, macos-14 is apple silicon
- macos-13
- macos-latest
fail-fast: false
runs-on: ${{ matrix.runs-on }}
timeout-minutes: 30
env:
CTEST_OUTPUT_ON_FAILURE: ON
steps:
- uses: zacharyburnett/setup-abseil-cpp@de39f445295c887839e30c864ffbbb1c0231bc83 # 1.0.5
with:
cmake-build-args: "-DCMAKE_CXX_STANDARD=17 -DABSL_PROPAGATE_CXX_STD=ON -DABSL_ENABLE_INSTALL=ON -DBUILD_TESTING=off -DCMAKE_POSITION_INDEPENDENT_CODE=ON"
abseil-version: "20240722.0"
- name: retrieve googletest v${{ env.GOOGLETEST_VERSION }}
run: |
wget https://github.com/google/googletest/releases/download/v${{ env.GOOGLETEST_VERSION }}/googletest-${{ env.GOOGLETEST_VERSION }}.tar.gz
tar -xzvf googletest-${{ env.GOOGLETEST_VERSION }}.tar.gz
echo GOOGLETEST_ROOT=${{ runner.temp }}/googletest-${{ env.GOOGLETEST_VERSION }} >> $GITHUB_ENV
working-directory: ${{ runner.temp }}
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- run: mkdir build
- run: cmake -DCMAKE_CXX_STANDARD=17 -DCMAKE_PREFIX_PATH=/usr/local/ -DGOOGLETEST_ROOT=${{ env.GOOGLETEST_ROOT }} -DGOOGLETEST_VERSION=${{ env.GOOGLETEST_VERSION }} ..
working-directory: build/
- run: cmake --build . ${{ runner.os == 'macOS' && '--parallel' || '' }}
# building tests with `--parallel` is disabled on Linux because GitHub seems to automatically cancel the job due to resource limits(?)
working-directory: build/
- if: always()
run: cmake --build . --parallel --target=test
working-directory: build/
89 changes: 64 additions & 25 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,23 @@
name = "s2geometry"
description = "Computational geometry and spatial indexing on the sphere"
authors = [
{ name = "Dan Larkin-York", email = "[email protected]" },
{ name = "Eric Veach", email = "[email protected]" },
{ name = "Jesse Rosenstock", email = "[email protected]" },
{ name = "Julien Basch", email = "[email protected]" },
{ name = "Mike Playle", email = "[email protected]" },
{ name = "Phil Elson", email = "[email protected]" },
{ name = "Robert Coup", email = "[email protected]" },
{ name = "Tiago Brito", email = "[email protected]" },
{ name = "Zachary Burnett", email = "[email protected]" },
{ name = "Dan Larkin-York", email = "[email protected]" },
{ name = "Eric Veach", email = "[email protected]" },
{ name = "Jesse Rosenstock", email = "[email protected]" },
{ name = "Julien Basch", email = "[email protected]" },
{ name = "Mike Playle", email = "[email protected]" },
{ name = "Phil Elson", email = "[email protected]" },
{ name = "Robert Coup", email = "[email protected]" },
{ name = "Tiago Brito", email = "[email protected]" },
{ name = "Zachary Burnett", email = "[email protected]" },
]
requires-python = ">=3.7"
classifiers = [
"Programming Language :: Python :: 3",
"Operating System :: POSIX",
"License :: OSI Approved :: Apache Software License",
]
dynamic = [
"version",
"Programming Language :: Python :: 3",
"Operating System :: POSIX",
"License :: OSI Approved :: Apache Software License",
]
dynamic = ["version"]

[project.license]
file = "LICENSE"
Expand All @@ -30,16 +28,15 @@ content-type = "text/plain"
Source = "https://github.com/google/s2geometry"

[project.optional-dependencies]
test = [
"pytest",
]
test = ["pytest"]

[build-system]
requires = [
"wheel",
"setuptools",
"setuptools_scm[toml]",
"cmake_build_extension",
"wheel",
"setuptools",
"setuptools_scm[toml]",
"cmake_build_extension",
"swig",
]
build-backend = "setuptools.build_meta"

Expand All @@ -48,11 +45,53 @@ zip-safe = false
include-package-data = false

[tool.setuptools.packages.find]
where = [
"src",
]
where = ["src"]
namespaces = false

[tool.setuptools.package-dir]
"" = "src"

[tool.cibuildwheel]
# manylinux-x86_64-image = "quay.io/pypa/manylinux2014_x86_64"
build-frontend = "build[uv]"
build = "cp3*-manylinux_x86_64 cp3*-macosx_x86_64 cp3*-macosx_arm64"
# test-requires = "pytest"
# test-command = "pytest {project}/src/python/"

[tool.cibuildwheel.environment]
MACOSX_DEPLOYMENT_TARGET = 14.0

[tool.cibuildwheel.linux]
# repair-wheel-command = ""
# the EPEL9 package `abseil-cpp` is out of date, so we have to build `abseil-cpp` from source
before-all = """
yum install -y gflags-devel glog-devel gtest-devel openssl-devel
git clone https://github.com/abseil/abseil-cpp.git && cd ./abseil-cpp
git checkout 20240116.2
mkdir ./build && cd ./build
cmake -DCMAKE_CXX_STANDARD=17 -DABSL_PROPAGATE_CXX_STD=ON -DABSL_ENABLE_INSTALL=ON -DBUILD_TESTING=off ..
cmake --build . --parallel --target=install
"""

[tool.cibuildwheel.macos]
before-all = """
git clone https://github.com/gflags/gflags.git && cd ./gflags
mkdir ./build && cd ./build
cmake .. -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTING=OFF
cmake --build . --parallel --target install
cd ../../
git clone https://github.com/google/glog.git && cd ./glog
cmake -S . -B ./build && cd ./build
cmake --build . --parallel --target install
cd ../../
git clone https://github.com/openssl/openssl.git && cd ./openssl
mkdir ./build && cd ./build
../Configure install
cmake --build . --parallel --target install
cd ../../
git clone https://github.com/abseil/abseil-cpp.git && cd ./abseil-cpp
git checkout 20240116.2
mkdir ./build && cd ./build
cmake -DCMAKE_CXX_STANDARD=17 -DABSL_PROPAGATE_CXX_STD=ON -DABSL_ENABLE_INSTALL=ON -DBUILD_TESTING=off ..
cmake --build . --parallel --target=install
"""
33 changes: 19 additions & 14 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,38 @@
import os
import sys
from pathlib import Path

import cmake_build_extension
import setuptools

# Extra options passed to the CI/CD pipeline that uses cibuildwheel
CIBW_CMAKE_OPTIONS = []
if "CIBUILDWHEEL" in os.environ and os.environ["CIBUILDWHEEL"] == "1":
# The manylinux variant runs in Debian Stretch and it uses lib64 folder
if sys.platform == "linux":
CIBW_CMAKE_OPTIONS += ["-DCMAKE_INSTALL_LIBDIR=lib"]

setuptools.setup(
ext_modules=[
cmake_build_extension.CMakeExtension(
# This could be anything you like, it is used to create build folders
name="SwigBindings",
# Name of the resulting package name (import s2geometry)
name="s2geometry",
install_prefix="s2geometry",
# Selects the folder where the main CMakeLists.txt is stored
# (it could be a subfolder)
source_dir=str(Path(__file__).parent.absolute()),
cmake_configure_options=[
# This option points CMake to the right Python interpreter, and helps
# the logic of FindPython3.cmake to find the active version
f"-DPython3_ROOT_DIR={Path(sys.prefix)}",
'-DCALL_FROM_SETUP_PY:BOOL=ON',
'-DBUILD_SHARED_LIBS:BOOL=OFF',
'-DCMAKE_POSITION_INDEPENDENT_CODE=ON',
'-DWITH_PYTHON=ON'
]
# This option points CMake to the right Python interpreter, and helps
# the logic of FindPython3.cmake to find the active version
# f"-DPython3_ROOT_DIR={Path(sys.prefix)}",
"-DCALL_FROM_SETUP_PY:BOOL=ON",
"-DBUILD_SHARED_LIBS:BOOL=OFF",
"-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON",
"-DWITH_PYTHON:BOOL=ON",
"-DBUILD_TESTS:BOOL=OFF",
]
+ CIBW_CMAKE_OPTIONS,
)
],
cmdclass=dict(
# Enable the CMakeExtension entries defined above
build_ext=cmake_build_extension.BuildExtension,
sdist=cmake_build_extension.GitSdistFolder,
),
)
Loading