Skip to content

Commit

Permalink
Added CI for pre-built wheels
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Stiborek committed Sep 10, 2024
1 parent fafdac3 commit 7457cfb
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 44 deletions.
109 changes: 69 additions & 40 deletions .github/workflows/build_python.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Python
name: Python wheels

on:
push:
Expand All @@ -14,54 +14,83 @@ on:
- "**CMakeLists.txt"
- "**py"
pull_request:
branches:
- master
paths:
- ".github/workflows/build_python.yml"
- "**.cpp"
- "**.h"
- "**.c"
- "**.cu"
- "**.cmake"
- "**CMakeLists.txt"
- "**py"

branches:
- master
paths:
- ".github/workflows/build_python.yml"
- "**.cpp"
- "**.h"
- "**.c"
- "**.cu"
- "**.cmake"
- "**CMakeLists.txt"
- "**py"
defaults:
run:
shell: bash

jobs:
Windows:
runs-on: 'windows-latest'
build_wheels_matrix:
runs-on: ubuntu-latest
outputs:
include: ${{ steps.set-matrix.outputs.include }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- name: Install python deps
run: |
pip install pytest numpy
# don't use CMake 3.25.0 https://gitlab.kitware.com/cmake/cmake/-/issues/23975
pip3 install cmake==3.24.0
- name: Build
run: |
pip3 install cmake==3.24.0
python setup.py build
python setup.py install --user
- name: Test
run: python -m pytest --ignore docs --ignore dlib
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: 3.x
- run: pip install cibuildwheel==2.17.0 # sync version with pypa/cibuildwheel below
- id: set-matrix
env:
CIBW_PROJECT_REQUIRES_PYTHON: '>=3.7' # it is missing in setup.py and needed to determine which wheels to build
run: |
MATRIX_INCLUDE=$(
{
cibuildwheel --print-build-identifiers --platform linux --arch x86_64,aarch64 | grep cp | jq -nRc '{"only": inputs, "os": "ubuntu-latest"}' \
&& cibuildwheel --print-build-identifiers --platform macos --arch x86_64 | grep cp | jq -nRc '{"only": inputs, "os": "macos-13"}' \
&& cibuildwheel --print-build-identifiers --platform macos --arch arm64 | grep cp | jq -nRc '{"only": inputs, "os": "macos-14"}' \
&& cibuildwheel --print-build-identifiers --platform windows --arch AMD64 | grep cp | jq -nRc '{"only": inputs, "os": "windows-latest"}'
} | jq -sc
)
echo "include=$MATRIX_INCLUDE" >> $GITHUB_OUTPUT
build_wheels:
needs: build_wheels_matrix
runs-on: ${{ matrix.os }}
name: Build ${{ matrix.only }}

strategy:
fail-fast: false
matrix:
include: ${{ fromJson(needs.build_wheels_matrix.outputs.include) }}

Ubuntu:
runs-on: 'ubuntu-latest'
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- name: Install python deps
run: pip install pytest numpy
- name: Build
- uses: actions/checkout@v4

- name: Disable gui support
run: |
python setup.py build
python setup.py install --user
- name: Test
run: python -m pytest --ignore docs --ignore dlib
sed -i'' -e "s/_cmake_extra_options = \[\]/_cmake_extra_options = \['-DDLIB_NO_GUI_SUPPORT=ON'\]/" setup.py
- name: Set up QEMU
if: runner.os == 'Linux'
uses: docker/setup-qemu-action@v3

- name: Build wheel
uses: pypa/cibuildwheel@v2.17.0 # sync version with pip install cibuildwheel above
with:
only: ${{ matrix.only }}
env:
CIBW_BUILD_VERBOSITY: 1
CIBW_TEST_REQUIRES: pytest numpy
CIBW_TEST_COMMAND: python -m pytest {project}/tools/python/test --ignore docs --ignore dlib

- name: Artifacts
uses: actions/upload-artifact@v4
with:
name: dist-${{ matrix.only }}
path: wheelhouse/*.whl


# Disabled for now since something is going sideways with python packages on github actions
# MacOS:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[build-system]
requires = ["setuptools", "wheel"]
requires = ["setuptools", "wheel", "cmake==3.24.0"]
build-backend = "setuptools.build_meta"
6 changes: 3 additions & 3 deletions tools/python/test/test_numpy_returns.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import sys
import pickle
import pathlib

import dlib
import pytest

import utils

# Paths are relative to dlib root
image_path = "examples/faces/Tom_Cruise_avp_2014_4.jpg"
shape_path = "tools/python/test/shape.pkl"
image_path = (pathlib.Path(__file__).parents[3] / "examples" / "faces" / "Tom_Cruise_avp_2014_4.jpg").absolute().as_posix()
shape_path = (pathlib.Path(__file__).parents[3] / "tools" / "python" / "test" / "shape.pkl").absolute().as_posix()


def get_test_image_and_shape():
Expand Down

0 comments on commit 7457cfb

Please sign in to comment.