Skip to content

Commit

Permalink
Merge pull request #1 from Innoptech/build-wheels-for-multiple-os
Browse files Browse the repository at this point in the history
ci: build wheels using cibuildwheel
  • Loading branch information
jeanchristopheruel authored May 28, 2024
2 parents 0299c35 + 754a717 commit 0374133
Show file tree
Hide file tree
Showing 7 changed files with 216 additions and 116 deletions.
140 changes: 95 additions & 45 deletions .github/workflows/publish-to-test-pypi.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,93 @@
---
name: Publish OpenSTL
on: push
on:
push:
branches:
- main
tags:
- 'v*'
pull_request:
branches:
- main

jobs:
build:
name: Build distribution 📦
timeout-minutes: 30
if: startsWith(github.ref, 'refs/tags/')
runs-on:
- self-hosted
- manylinux
env:
PLAT: manylinux_2_28_x86_64
if: "github.event_name == 'pull_request'"
name: Build and Test on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-13, macos-14]

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.8'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install .
- name: Run tests
run: |
python3 -m pip install numpy pytest
pytest
bump_version_and_tag:
if: "github.event_name == 'push' && github.ref == 'refs/heads/main' && !startsWith(github.event.head_commit.message, 'bump:')"
name: Bump version and tag on main
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v3
with:
fetch-depth: 0
ssh-key: "${{ secrets.COMMIT_KEY }}"
- name: Create bump and changelog
uses: commitizen-tools/commitizen-action@master
with:
push: false
- name: Print Version
run: echo "Bumped to version ${{ steps.cz.outputs.version }}"
- name: Push using ssh
if: github.event_name == 'push'
run: |
git config --global user.name "${{ env.CI_COMMIT_AUTHOR }}"
git config --global user.email "[email protected]"
git push --tags
git push
build_wheels:
if: "startsWith(github.event.head_commit.message, 'bump:')"
name: Build wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-13, macos-14]
steps:
- uses: actions/checkout@v4
- name: Build a binary wheel and a source tarball -> manylinux_2_28_x86_64
run: bash python/build-wheels.sh
- name: Store the distribution packages
uses: actions/upload-artifact@v3
- uses: actions/setup-python@v5
- name: Print the arch and system
run: |
python -c "import platform; print(f'System: {platform.system()}'); print(f'Architecture: {platform.architecture()[0]}')"
- name: Install cibuildwheel
run: python -m pip install cibuildwheel==2.18.1
- name: Build wheels
run: python -m cibuildwheel --output-dir wheelhouse
- uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/
name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }}
path: ./wheelhouse/*.whl

publish-to-testpypi:
name: Publish Python 🐍 distribution 📦 to TestPyPI
needs:
- build
- build_wheels
runs-on: ubuntu-latest
environment:
name: testpypi
Expand All @@ -32,37 +96,20 @@ jobs:
id-token: write
steps:
- name: Download all the dists
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
pattern: cibw-*
path: dist
merge-multiple: true
- name: Publish distribution 📦 to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
tests:
name: Test openstl testpypi distrib
needs:
- publish-to-testpypi
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["pypy3.7", "pypy3.8", "pypy3.9", "pypy3.10", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Test the python package
run: |
python3 -m pip install --index-url https://test.pypi.org/simple/ openstl
python3 -m pip install numpy pytest
pytest ./tests/python

publish-to-pypi:
name: Publish Python 🐍 distribution 📦 to PyPI
needs:
- tests
- publish-to-testpypi
runs-on: ubuntu-latest
environment:
name: pypi
Expand All @@ -71,12 +118,14 @@ jobs:
id-token: write
steps:
- name: Download all the dists
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
pattern: cibw-*
path: dist
merge-multiple: true
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

github-release:
name: Sign the Python 🐍 distribution 📦 with Sigstore and upload them to GitHub
Release
Expand All @@ -88,10 +137,11 @@ jobs:
id-token: write
steps:
- name: Download all the dists
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
pattern: cibw-*
path: dist
merge-multiple: true
- name: Sign the dists with Sigstore
uses: sigstore/[email protected]
with:
Expand Down
14 changes: 10 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,16 @@ set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall -Wextra -std=c++11 -lstdc++ -pthread")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -fno-math-errno")
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lm ")
# Compiler-specific flags
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall -pthread")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -fno-math-errno")
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /EHsc")
set(CMAKE_CXX_FLAGS_RELEASE "/O2")
set(CMAKE_CXX_FLAGS_DEBUG "/Od /Zi")
endif()

# Do not allow to build in main repo
file(TO_CMAKE_PATH "${PROJECT_BINARY_DIR}/CMakeLists.txt" LOC_PATH)
Expand Down
30 changes: 25 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,40 @@
[build-system]
requires = ["setuptools>=42", "wheel" , "ninja", "cmake>=3.15.3"]
requires = ["setuptools>=42", "wheel", "ninja", "cmake>=3.15.3"]
build-backend = "setuptools.build_meta"

[tool.mypy]
files = "setup.py"
python_version = "3.7"
strict = true
show_error_codes = true
enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]
warn_unreachable = true

[[tool.mypy.overrides]]
module = ["ninja"]
ignore_missing_imports = true

[tool.pytest.ini_options]
minversion = "6.0"
addopts = "-ra -q"
testpaths = [
"tests/python",
addopts = ["-ra", "--showlocals", "--strict-markers", "--strict-config"]
xfail_strict = true
filterwarnings = [
"error",
"ignore:(ast.Str|Attribute s|ast.NameConstant|ast.Num) is deprecated:DeprecationWarning:_pytest",
]
testpaths = ["tests/python"]

[tool]
[tool.commitizen]
name = "cz_conventional_commits"
version = "1.1.1"
tag_format = "v$version"

[tool.cibuildwheel]
test-command = "pytest {project}/tests"
test-extras = ["test"]
test-skip = ["*universal2:arm64", "pp*", "cp{38,39,310,311,312}-manylinux_i686", "cp38-macosx_arm64", "*musllinux*", "*ppc64le", "*s390x"]
# Setuptools bug causes collision between pypy and cpython artifacts
before-build = "rm -rf {project}/build"

[tool.poetry.dependencies]
pybind11 = "v2.11.1"
Expand Down
35 changes: 9 additions & 26 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
message(STATUS "Adding OpenSTL python binding")

#-------------------------------------------------------------------------------
# External libraries
#-------------------------------------------------------------------------------
FIND_PACKAGE(PythonInterp 3)
FIND_PACKAGE(PythonLibs 3)
find_package(Python COMPONENTS Interpreter Development)
find_package(pybind11 CONFIG)

#-------------------------------------------------------------------------------
# Internal libraries
Expand All @@ -18,22 +11,12 @@ endif()
#-------------------------------------------------------------------------------
# Build Python Binding
#-------------------------------------------------------------------------------
if(NOT PYTHONINTERP_FOUND)
message( FATAL_ERROR "PYTHONINTERP could not be found")
endif()
if(NOT PYTHONLIBS_FOUND)
message( FATAL_ERROR "PYTHONLIBS could not be found")
endif()


IF(PYTHONINTERP_FOUND AND PYTHONLIBS_FOUND)
file(GLOB_RECURSE python_SRC core/*.cpp)
pybind11_add_module(openstl MODULE ${python_SRC})
target_include_directories(openstl PRIVATE ${PYBIND11_SUBMODULE}/include)
target_link_libraries(openstl PRIVATE openstl::core pybind11::headers)
target_compile_definitions(openstl PRIVATE VERSION_INFO=${PROJECT_VERSION})
set_target_properties(openstl PROPERTIES
INTERPROCEDURAL_OPTIMIZATION ON
CXX_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN ON)
ENDIF()
file(GLOB_RECURSE python_SRC core/*.cpp)
pybind11_add_module(openstl MODULE ${python_SRC})
target_include_directories(openstl PRIVATE ${PYBIND11_SUBMODULE}/include)
target_link_libraries(openstl PRIVATE openstl::core pybind11::headers)
target_compile_definitions(openstl PRIVATE VERSION_INFO=${PROJECT_VERSION})
set_target_properties(openstl PROPERTIES
INTERPROCEDURAL_OPTIMIZATION ON
CXX_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN ON)
22 changes: 0 additions & 22 deletions python/build-wheels.sh

This file was deleted.

2 changes: 1 addition & 1 deletion python/core/src/stl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ namespace pybind11 { namespace detail {

bool load(handle src, bool convert)
{
if ( !convert and !py::array_t<float, py::array::c_style | py::array::forcecast>::check_(src) )
if ( (!convert) && (!py::array_t<float, py::array::c_style | py::array::forcecast>::check_(src)) )
return false;

auto buf = py::array_t<float, py::array::c_style | py::array::forcecast>::ensure(src);
Expand Down
Loading

0 comments on commit 0374133

Please sign in to comment.