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

feat: Build wheels using cibuildwheel prior to releasing to PyPI #70

Merged
merged 63 commits into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
b949e4e
try to use CIBW_BEFORE_BUILD hook instead of CIBW_BEFORE_ALL to insta…
Liam-Deacon Jan 17, 2024
a42b8cf
build: Add helpful makefile targets for building package
Liam-Deacon Jan 17, 2024
0806e4e
ci: Add pyproject.toml and use cibuildwheels for PyPI publish
Liam-Deacon Jan 17, 2024
87942a9
fix: Add fake extension for Python 3.12 to force platform specific wh…
Liam-Deacon Jan 17, 2024
b7a427c
fixup!
Liam-Deacon Jan 17, 2024
ee8e098
fixup!
Liam-Deacon Jan 17, 2024
954b836
strip whitespace
Liam-Deacon Jan 18, 2024
876319a
fix: Make _native_build.c have module definition for Windows py3.12
Liam-Deacon Jan 18, 2024
f74c19d
tweak pyrpoject.toml
Liam-Deacon Jan 18, 2024
7efbddf
rework _native_build.c
Liam-Deacon Jan 18, 2024
a455cb6
refactor: Merge mac build wheels into win+linux matrix job
Liam-Deacon Jan 18, 2024
6a23bd6
ci: define legacy v1 cibuildwheel step for cross-compiling wheels on …
Liam-Deacon Jan 18, 2024
e5fa76a
use `from __future__ import print_function for setup.py` for python 2.7
Liam-Deacon Jan 18, 2024
edd6442
fixup! rework _native_build.c
Liam-Deacon Jan 18, 2024
ec34686
ci: Use gcc@12 for homebrew on macos
Liam-Deacon Jan 18, 2024
8066b81
skip cp37 on mac
Liam-Deacon Jan 18, 2024
3ae133b
use gcc@11 for mac os
Liam-Deacon Jan 18, 2024
579c4cd
attempt to force $FC
Liam-Deacon Jan 18, 2024
c261859
Split out wheels job into 1 per os
Liam-Deacon Jan 18, 2024
5b13873
refactor: Only build subset of legacy wheels on linux and windows
Liam-Deacon Jan 18, 2024
0c4ce2a
further restrict wheel builds
Liam-Deacon Jan 18, 2024
7dffe1b
test: Add tests to cibuildwheels
Liam-Deacon Jan 18, 2024
3492ab2
fix: Remove f-string from phsh.py
Liam-Deacon Jan 18, 2024
5c40c76
fix: Remove unknown compiler flags for other platforms
Liam-Deacon Jan 18, 2024
1ecdfa1
ci: Do sanity check test
Liam-Deacon Jan 18, 2024
62acfcd
rename sdist job
Liam-Deacon Jan 18, 2024
0547cdc
remove mac specific option as it doesn't do anything
Liam-Deacon Jan 18, 2024
dfa2b76
fix: Add linux2 to setup f2py dict
Liam-Deacon Jan 18, 2024
0782cbf
bump gfortran on mac to v12
Liam-Deacon Jan 18, 2024
15b4474
increase windows delvewheel verbosity, add --ignore-in-wheel option
Liam-Deacon Jan 18, 2024
6af4b00
remove f-string
Liam-Deacon Jan 18, 2024
7070251
tweak macos cibuildwheel config
Liam-Deacon Jan 18, 2024
01c6c8f
fix invalid character
Liam-Deacon Jan 18, 2024
09c47d3
remove f-string
Liam-Deacon Jan 18, 2024
29977a2
attempt to fix windows and macos arm64 repair wheel steps
Liam-Deacon Jan 18, 2024
cb61fa1
make atorb.py python 2.7 compatible
Liam-Deacon Jan 18, 2024
a60000b
remove use of delvewheel for windows repair wheel step
Liam-Deacon Jan 18, 2024
37b9569
fix default test command
Liam-Deacon Jan 18, 2024
4a2f905
fix
Liam-Deacon Jan 18, 2024
b8efb29
tweak windows build
Liam-Deacon Jan 18, 2024
b58b346
remove custom repair wheel command for macos
Liam-Deacon Jan 18, 2024
4b27a84
fix Mapping import from collections for py27
Liam-Deacon Jan 18, 2024
d425cf5
attempt to build libphsh.pyd prior to building wheel on windows
Liam-Deacon Jan 18, 2024
4208cbf
Merge branch 'master' into ci/improve-pypi-workflow
Liam-Deacon Jan 18, 2024
82cf4ee
do not build cpython 3.12 until #8 is resolved
Liam-Deacon Jan 18, 2024
e089708
reinstate delvewheel command for windows
Liam-Deacon Jan 18, 2024
69f2fce
try to force being libphsh using f2py on windows
Liam-Deacon Jan 18, 2024
26a18ea
use && instead of ; for joining commands on windows
Liam-Deacon Jan 18, 2024
3a902c9
do not attempt to repair wheel on windows
Liam-Deacon Jan 19, 2024
17b0fec
skip cibw tests on windows
Liam-Deacon Jan 19, 2024
4be386e
split out legacy wheel builds
Liam-Deacon Jan 19, 2024
a4a7cdd
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 19, 2024
a32adb4
split linux into aarch64 and x86_64
Liam-Deacon Jan 19, 2024
3cc7a16
reintroduce i686 to legacy linux
Liam-Deacon Jan 19, 2024
56cb1bc
skip musl linux, add dispatch options
Liam-Deacon Jan 19, 2024
8fce920
tweak windows legacy build
Liam-Deacon Jan 19, 2024
fdbb00c
feat: Add settings module for environment variables
Liam-Deacon Jan 19, 2024
509491f
refactor: ensure documentation generation does not depend on compilin…
Liam-Deacon Jan 19, 2024
b5396d5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 19, 2024
7fae903
set ruff config to use lowest possible version of python
Liam-Deacon Jan 19, 2024
505c9c8
Merge remote-tracking branch 'origin/master' into ci/improve-pypi-wor…
Liam-Deacon Jan 21, 2024
23b494f
ci: Attempt to workaround compile issue
Liam-Deacon Jan 21, 2024
72180e4
fix: Handle possibly undefined inp variable in atorb.py
Liam-Deacon Jan 21, 2024
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
7 changes: 4 additions & 3 deletions .github/workflows/publish-docs-to-github-pages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ concurrency:

jobs:
build:
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

Expand Down Expand Up @@ -54,8 +54,9 @@ jobs:
run: |
python3 -m pip install --upgrade pip
python3 -m pip install numpy setuptools wheel # NOTE: needed for non PEP-517 enabled projects
python3 -m pip install -e .[doc]

python3 -m pip install -e .[doc] || python3 -m pip install -r requirements-doc.txt
env:
PHASESHIFTS_COMPILE: "false"
- name: Build HTML Docs
run: | # NOTE: .nojekyll is important to maintain sphinx rendering
make html && touch _build/html/.nojekyll
Expand Down
248 changes: 178 additions & 70 deletions .github/workflows/publish-to-pypi.yaml
Original file line number Diff line number Diff line change
@@ -1,123 +1,222 @@
---
name: Publish Package

on:
release:
release: {}
workflow_dispatch:
inputs:
version:
description: 'Version upload to pypi'
default: master
description: Version to upload
default: ''
pypi_repo:
description: 'Repo to upload to (testpypi or pypi)'
default: 'testpypi'
description: PyPI Repo
type: choice
options:
- pypi
- testpypi
default: testpypi
required: true
build_legacy:
description: Build legacy wheels
default: true
type: boolean
build_manylinux:
description: Build manylinux wheels
default: true
type: boolean
build_musllinux:
description: Build musllinux wheels
default: false
type: boolean
build_aarch64:
description: Build aarch64 wheels
default: true
type: boolean
build_i686:
description: Build i686 wheels
default: true
type: boolean

env:
CIBW_BEFORE_BUILD: pip install numpy
CIBW_ENVIRONMENT_PASS_LINUX: PHASESHIFTS_VERSION
CIBW_TEST_COMMAND: python -c "import phaseshifts.phsh" # most simple, yet effective sanity check
CIBW_TEST_EXTRAS: ''
CIBW_TEST_REQUIRES: ''
PHASESHIFTS_VERSION: ${{ github.event.inputs.version }}

permissions:
contents: read

jobs:
build_sdist:
name: Build sdists
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ["ubuntu-latest", "windows-latest"] # .tar.gz on linux, .zip on windows
name: Build Source Dist
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.version || github.ref }}
- uses: actions/setup-python@v5
with:
python-version: '3.11'
# TODO: Figure out how to create a sdist zip for Windows
- name: Build sdist
run: |
make install-deps && \
pip install build && \
python -m build --sdist --no-isolation
shell: bash
env:
PHASESHIFTS_VERSION: ${{ github.event.inputs.version }}
- uses: actions/upload-artifact@v4
with:
name: source-${{ matrix.os }}
name: sdist
path: dist/

build_linux_wheels:
name: Linux Build
build_legacy_wheels_linux:
name: Build Legacy Linux Wheels
runs-on: ubuntu-latest
needs: build_sdist
strategy:
matrix: # TODO: Remove 2.7, 3.5 and 3.6 when we drop support for old python versions
python-version: ["2.7", "3.5", "3.6", "3.9", "3.10", "3.11"]
if: ${{ github.event.inputs.build_legacy || github.event_name != 'release' }}
steps:
- uses: actions/checkout@v4
# TODO: Remove when we drop support for older python versions
- name: Build legacy wheels
uses: pypa/cibuildwheel@v1.12.0
with:
ref: ${{ github.event.inputs.version || github.ref }}
- uses: actions/setup-python@v5
continue-on-error: true
output-dir: dist/
env:
CIBW_ARCHS_LINUX: x86_64 ${{ (github.event.inputs.build_i686 || github.event_name != 'release') && 'i686' || '' }}
CIBW_BUILD: cp27-* cp35-*
- uses: actions/upload-artifact@v4
with:
python-version: ${{ matrix.python-version }}
- if: failure()
uses: gabrielfalcao/pyenv-action@v18
name: linux-legacy
path: dist/

build_wheels_linux_x86_64:
name: Build Linux x86_64 Wheels
runs-on: ubuntu-latest
needs: build_sdist
steps:
- uses: actions/checkout@v4
- name: Set up QEMU
if: runner.os == 'Linux'
uses: docker/setup-qemu-action@v3
with:
default: "${{ matrix.python-version }}"
command: pip install -U pip # upgrade pip after installing python
- name: Build wheel
run: make wheel
shell: bash
platforms: all
- name: Build wheels
uses: pypa/cibuildwheel@v2.16.2
with:
output-dir: dist/
env:
CIBW_ARCHS_LINUX: x86_64
# Known issue with linux CPython 3.8, see #67
CIBW_SKIP: cp38-* cp*musl*
- uses: actions/upload-artifact@v4
with:
name: linux-${{ matrix.python-version }}
name: linux-x86_64
path: dist/

build_windows_binaries:
name: Windows Build
runs-on: windows-latest
needs: [build_sdist, build_linux_wheels]
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11"]
build_wheels_linux_aarch64:
name: Build Linux aarch64 Wheels
runs-on: ubuntu-latest
needs: build_sdist
if: ${{ github.event.inputs.build_aarch64 || github.event_name == 'release' }}
steps:
- uses: actions/checkout@v4
- name: Set up QEMU
if: runner.os == 'Linux'
uses: docker/setup-qemu-action@v3
with:
ref: ${{ github.event.inputs.version || github.ref }}
- uses: actions/setup-python@v5
platforms: all
- name: Build wheels
uses: pypa/cibuildwheel@v2.16.2
with:
python-version: ${{ matrix.python-version }}
- name: Build wheel
run: make wheel
shell: bash
output-dir: dist/
env:
CIBW_ARCHS_LINUX: aarch64
CIBW_SKIP: cp38-* cp*musl* cp37-musllinux_aarch64
- uses: actions/upload-artifact@v4
with:
name: windows-${{ matrix.python-version }}
name: linux-aarch64
path: dist/

build_mac_wheels:
name: Mac Build
build_wheels_macos:
name: Build Mac Wheels
runs-on: macos-latest
needs:
# restrict to running macos when everything else is successful as running as it is 10x more expensive than ubuntu
- build_sdist
- build_linux_wheels
- build_windows_binaries
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11"] # limited as macos runner minutes are 10x expensive compared to ubuntu
needs: build_sdist
steps:
- uses: actions/checkout@v4
# https://github.com/AntoineD/pdfo/blob/f6a45b3921807ad99a438f65ee2b01fa193038bb/.github/workflows/build_wheels.yml#L14C1-L23C1
- name: Provide gfortran (macOS)
if: runner.os == 'macOS'
run: |
# https://github.com/actions/virtual-environments/issues/2524
# https://github.com/cbg-ethz/dce/blob/master/.github/workflows/pkgdown.yaml
sudo ln -s /usr/local/bin/gfortran-12 /usr/local/bin/gfortran
sudo mkdir /usr/local/gfortran
sudo ln -s /usr/local/Cellar/gcc@12/*/lib/gcc/12 /usr/local/gfortran/lib
gfortran --version
- name: Build x86_64 wheels
uses: pypa/cibuildwheel@v2.16.2
with:
ref: ${{ github.event.inputs.version || github.ref }}
- uses: actions/setup-python@v5
output-dir: dist/
env:
CIBW_ARCHS_MACOS: x86_64
- name: Build arm64 wheels
uses: pypa/cibuildwheel@v2.16.2
with:
output-dir: dist/
env:
CIBW_ARCHS_MACOS: arm64
CIBW_REPAIR_WHEEL_COMMAND_MACOS: ''
- uses: actions/upload-artifact@v4
with:
python-version: ${{ matrix.python-version }}
name: macos
path: dist/

build_legacy_wheels_windows:
name: Build Legacy Windows Wheels
runs-on: windows-latest
needs: build_sdist
env:
CIBW_TEST_COMMAND: "" # FIXME: This is a workaround for an issue with DLL loading on Windows
steps:
- uses: actions/checkout@v4

- name: Tell distutils to use mingw (Windows)
if: runner.os == 'Windows'
run: |
echo "[build]`ncompiler=mingw32" | Out-File -Encoding ASCII ~/pydistutils.cfg

- name: Build legacy wheels
uses: pypa/cibuildwheel@v1.12.0
with:
output-dir: dist/
env:
CIBW_BUILD: cp27-* cp35-*
continue-on-error: true

- uses: actions/upload-artifact@v4
with:
name: windows-legacy
path: dist/

build_wheels_windows:
name: Build Windows Wheels
runs-on: windows-latest
needs: build_sdist
env:
CIBW_BEFORE_BUILD: pip install delvewheel numpy && build_libphsh.bat
CIBW_TEST_COMMAND: "" # FIXME: This is a workaround for an issue with DLL loading on Windows
steps:
- uses: actions/checkout@v4

- name: Build wheels
uses: pypa/cibuildwheel@v2.16.2
with:
output-dir: dist/
env:
CIBW_BEFORE_ALL: pip install numpy
CIBW_ARCHS_MACOS: x86_64 arm64
- uses: actions/upload-artifact@v4
with:
name: macos-${{ matrix.python-version }}
name: windows
path: dist/

publish_to_testpypi:
Expand All @@ -128,9 +227,12 @@ jobs:
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
needs:
- build_sdist
- build_linux_wheels
- build_windows_binaries
- build_mac_wheels
- build_legacy_wheels_linux
- build_legacy_wheels_windows
- build_wheels_linux_aarch64
- build_wheels_linux_x86_64
- build_wheels_macos
- build_wheels_windows
steps:
- uses: actions/download-artifact@v4
with:
Expand All @@ -149,9 +251,12 @@ jobs:
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
needs:
- build_sdist
- build_linux_wheels
- build_windows_binaries
- build_mac_wheels
- build_legacy_wheels_linux
- build_legacy_wheels_windows
- build_wheels_linux_aarch64
- build_wheels_linux_x86_64
- build_wheels_macos
- build_wheels_windows
steps:
- uses: actions/download-artifact@v4
with:
Expand All @@ -172,9 +277,12 @@ jobs:
contents: write
needs:
- build_sdist
- build_linux_wheels
- build_windows_binaries
- build_mac_wheels
- build_legacy_wheels_linux
- build_legacy_wheels_windows
- build_wheels_linux_aarch64
- build_wheels_linux_x86_64
- build_wheels_macos
- build_wheels_windows
steps:
- uses: actions/download-artifact@v4
with:
Expand Down
26 changes: 22 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
# Makefile for assisting with some common development activities

PYTHON ?= $(shell pyenv which python 2>/dev/null || echo python)
DOCKER ?= $(shell command -v docker 2>/dev/null || docker)

.PHONY: wheel install-deps libphsh check test clean
.PHONY: build-deps cbuildwheel check install install-deps libphsh sdist test wheel

#: Quickly generate binary wheel
wheel: install-deps
$(PYTHON) setup.py build bdist_wheel

#: Install dependencies
#: Meta target, will attempt to build all it can
build: sdist
if command -v docker 1>/dev/null; then $(MAKE) cibuildwheel; else $(MAKE) wheel; fi

#: Build a matrix of wheels for different OSs and CPU archs
cibuildwheel: build-deps $(DOCKER)
$(PYTHON) -m cibuildwheel --platform=auto --output-dir=dist .

#: Create source distributions
sdist: build-deps
$(PYTHON) build --sdist --no-isolation --formats=zip,tar

#: Install build dependencies
build-deps:
$(PYTHON) -m pip install build cibuildwheel

#: Install setup_requires dependencies
install-deps:
$(PYTHON) -m pip install wheel numpy setuptools 'meson; python_version >= "3.5"' ninja pytest scikit-build
$(PYTHON) -m pip install wheel numpy setuptools \
'meson; python_version >= "3.5"' ninja pytest scikit-build

#: Install library into current virtualenv
install:
Expand Down Expand Up @@ -41,4 +59,4 @@ clean:

#: Build docker image
docker:
docker build . -t "phaseshifts:$${DOCKER_TAG:-$$($(PYTHON) -c 'import phaseshifts; print(phaseshifts.__version__)')}"
$(DOCKER) build . -t "ghcr.io/Liam-Deacon/phaseshifts:$${DOCKER_TAG:-$$($(PYTHON) -c 'import phaseshifts; print(phaseshifts.__version__)')}"
Loading
Loading