Skip to content

Commit

Permalink
Setup CI Python wheels (#142)
Browse files Browse the repository at this point in the history
* fix xtensor overriden option

* add cmake option to download the xtensor stack

Useful until it is available on PyPI (maybe someday?)

* add cibuildwheel setup

* add distribute (publish) python bindings gha
  • Loading branch information
benbovy committed Oct 6, 2023
1 parent 7f6805a commit 346e573
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 4 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/python-wheels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Python wheels

on:
# trigger action from GitHub GUI (testing, no publish)
workflow_dispatch:
release:
types:
- published

make_sdist:
name: Make Python SDist
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Build SDist
run: pipx run build --sdist

- name: Upload SDist
uses: actions/upload-artifact@v3
with:
path: dist/*.tar.gz

build_wheels:
name: Build wheel (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Build wheels
uses: pypa/cibuildwheel@v2.16

- name: Upload wheels
uses: actions/upload-artifact@v3
with:
path: wheelhouse/*.whl

upload_all:
needs: [build_wheels, make_sdist]
environment: pypi
permissions:
id-token: write
runs-on: ubuntu-latest
if: github.event_name == 'release' && github.event.action == 'published'
steps:
- name: Get dist files
uses: actions/download-artifact@v3
with:
name: artifact
path: dist

- name: Publish on PyPI
uses: pypa/gh-action-pypi-publish@release/v1
37 changes: 33 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ message(STATUS "Building fastscapelib v${PROJECT_VERSION}")
set(FASTSCAPELIB_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)

OPTION(FS_DOWNLOAD_XTENSOR "Download and use xtensor development version" OFF)
OPTION(FS_DOWNLOAD_XTENSOR_PYTHON "Download xtensor-python (python bindings)" OFF)
OPTION(FS_BUILD_TESTS "Build fastscapelib test suite" OFF)
OPTION(FS_DOWNLOAD_GTEST "Build gtest from downloaded sources" OFF)
OPTION(FS_GTEST_SRC_DIR "Build gtest from local sources" OFF)
Expand All @@ -24,10 +25,37 @@ set(CMAKE_MODULE_PATH
# Dependencies
# ============

# -- xtensor (optionally from source download)
if(FS_DOWNLOAD_XTENSOR)
include(FetchContent)
include(FetchContent)

# -- get the whole xtensor stack (only when building python bindings)
if(SKBUILD AND FS_DOWNLOAD_XTENSOR_PYTHON)
message(STATUS "Downloading xtl, xtensor and xtensor-python libraries")

FetchContent_Declare(xtl
GIT_REPOSITORY https://github.com/xtensor-stack/xtl
GIT_TAG 0.7.5
GIT_SHALLOW TRUE)
FetchContent_MakeAvailable(xtl)

FetchContent_Declare(xtensor
GIT_REPOSITORY https://github.com/xtensor-stack/xtensor
GIT_TAG 0.24.6
GIT_SHALLOW TRUE)
set(CPP17 ON CACHE BOOL "Enable C++17 for xtensor" FORCE)
FetchContent_MakeAvailable(xtensor)

FetchContent_Declare(xtensor-python
GIT_REPOSITORY https://github.com/xtensor-stack/xtensor-python
GIT_TAG 0.26.1
GIT_SHALLOW TRUE)
FetchContent_MakeAvailable(xtensor-python)

set_property(DIRECTORY ${xtl_SOURCE_DIR} PROPERTY EXCLUDE_FROM_ALL YES)
set_property(DIRECTORY ${xtensor_SOURCE_DIR} PROPERTY EXCLUDE_FROM_ALL YES)
set_property(DIRECTORY ${xtensor-python_SOURCE_DIR} PROPERTY EXCLUDE_FROM_ALL YES)

# -- get xtensor development version (need xtl already installed)
elseif(FS_DOWNLOAD_XTENSOR)
message(STATUS "Downloading xtensor development version (master branch)")

FetchContent_Declare(xtensor
Expand All @@ -36,10 +64,11 @@ if(FS_DOWNLOAD_XTENSOR)
GIT_SHALLOW TRUE)

set(CPP17 ON CACHE BOOL "Enable C++17 for xtensor" FORCE)
set(FS_DOWNLOAD_GBENCHMARK OFF CACHE BOOL
set(DOWNLOAD_GBENCHMARK OFF CACHE BOOL
"skip downloading google-benchmark via xtensor" FORCE)

FetchContent_MakeAvailable(xtensor)

else()
find_package(xtensor REQUIRED)
message(STATUS "Found xtensor: ${xtensor_INCLUDE_DIRS}/xtensor")
Expand Down
10 changes: 10 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ test = ["pytest>=6.0"]
[tool.scikit-build]
wheel.packages = ["python/fastscapelib"]

[tool.cibuildwheel]
environment = "SKBUILD_CMAKE_ARGS='-DFS_DOWNLOAD_XTENSOR_PYTHON=ON'"
test-extras = "test"
test-command = "pytest python/fastscapelib/tests"
build-verbosity = 1

[tool.cibuildwheel.macos]
archs = ["auto", "universal2"]
test-skip = ["*universal2:arm64"]

[tool.isort]
profile = "black"
skip_gitignore = true
Expand Down

0 comments on commit 346e573

Please sign in to comment.