Skip to content

Commit

Permalink
Skbuild (#44)
Browse files Browse the repository at this point in the history
* skbuild

* dynamic version, remove metadata.{hh,cc}

* adapt workflow

* working on ci

* bit less verbose

* ci

* force ninja

* add dependabot

* fix

* files for setuptools_scm

* ci

* refresh publish.yml

* add flags for visual studio compiler

* try with msvc

* auto-ize

* test verbosely

* no openmp on windows

* clang-cl w/o openmp

* dobule quotes

* quotes

* quotes

* quotes

* openmp is not the problem on windows, apparently

* install eigen

* trigger

* single quotes

* cibuildwheel

* install a recent eigen on linux

* environment

* tinker

* cancel older

* no pypy

* env vars

* env

* Add fallback version

* forward slashed

* foo

* Eigen3_ROOT

* remove continue-on-error

* reorg a bit

* reorg

* reorg

* reorg

* reorg

* dammit

* NO_EXTRAS

* auto-ize

* decltype instead of auto

* Update .github/workflows/ci.yml

* fix warning

* eigen3 path on windows

* eigen3 path on windows

* eigen3 path on windows

* setup-miniconda conf

* update checkout action

* update ci.yml

* update ci.yml

* testing command

* testing command

* non-shallow clone in ci.yml

* skip test_fields

* skip test_fields

* skip all test that use cache

* fetch eigen3 for sdist

* skip C compiler checks when fetching Eigen

* blasted eigen

* blasted eigen

* Try aarch64 ppc64le

* One job per wheel

* fix action version

* skip CPython 3.12

* chore: update action versions

* chore: update action versions

* chore: update toml and publish.yml

* fix: option available only in latest scikit-build-core

* fix: step name

* fix: skip musl, do 3.12

* chore: exclude more variants

* chore: exclude aarch64 on linux

* test: wheel upload

* test: wheel upload

* fix: use tarball for eigen

* use correct action

---------

Co-authored-by: Maximilian Scheurer <[email protected]>
  • Loading branch information
robertodr and maxscheurer authored Aug 1, 2024
1 parent d1bc43f commit 1d2d0be
Show file tree
Hide file tree
Showing 37 changed files with 514 additions and 654 deletions.
1 change: 0 additions & 1 deletion .clang-format.ignore

This file was deleted.

5 changes: 5 additions & 0 deletions .git_archival.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node: $Format:%H$
node-date: $Format:%cI$
describe-name: $Format:%(describe:tags=true,match=*[0-9]*)$
ref-names: $Format:%D$

2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.git_archival.txt export-subst

12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: 2
updates:
# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
ignore:
# cibuildwheel updates often and cannot be tracked by
# a major version tag like 'v1'. Mute updates since
# this is not a critical component
- dependency-name: "pypa/cibuildwheel*"
8 changes: 0 additions & 8 deletions .github/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@ name: cppe-gha
channels:
- conda-forge
dependencies:
- cmake
- cxx-compiler
- eigen
- h5py
- ninja
- numpy
- pandas
- pip
- pybind11
- pytest
- scipy
140 changes: 59 additions & 81 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,17 @@ on:
branches:
- master

env:
BUILD_TYPE: Release

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

env:
FORCE_COLOR: 3

jobs:
build:
runs-on: ${{ matrix.os }}

continue-on-error: true

strategy:
fail-fast: false
matrix:
Expand All @@ -32,84 +30,64 @@ jobs:
- windows-latest
python-version:
- "3.8"
- "3.11"
- "3.12"

defaults:
run:
shell: bash -l {0}

steps:
- uses: actions/checkout@v3

# this will set the system compiler;
# This must be done *before* setting up miniconda, see:
# https://github.com/ilammy/msvc-dev-cmd/issues/34
- name: Set Windows env
if: matrix.os == 'windows-latest'
uses: ilammy/msvc-dev-cmd@v1
shell: bash -el {0}

- name: Cache conda
uses: actions/cache@v3
env:
# Increase this value to reset cache if .github/environment.yml has not changed
CACHE_NUMBER: 1
with:
path: ~/conda_pkgs_dir
key:
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-${{ hashFiles('.github/environment.yml') }}
env:
NINJA_STATUS: "[Built edge %f of %t in %e sec] "

- uses: conda-incubator/setup-miniconda@v2
with:
mamba-version: "*"
auto-update-conda: true
auto-activate-base: false
activate-environment: cppe-gha
environment-file: .github/environment.yml
channel-priority: strict
python-version: ${{ matrix.python-version }}

- name: Select CMake CLI options
run: |
echo "We are running on ${{ matrix.os }}"
if [ "${{ matrix.os }}" == "ubuntu-latest" ]; then
echo "CXX=g++" >> $GITHUB_ENV
elif [ "${{ matrix.os }}" == "macos-latest" ]; then
echo "CXX=clang++" >> $GITHUB_ENV
else
echo "CXX=clang-cl" >> $GITHUB_ENV
fi
- name: Configure
run: |
cmake -S. \
-Bbuild \
-GNinja \
-DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} \
-DCMAKE_CXX_COMPILER=${CXX} \
-DCMAKE_INSTALL_PREFIX=~/Software
- name: Build and install
run: |
cmake --build build --config ${{ env.BUILD_TYPE }} --target install -- -v -d stats
- name: Test
run: |
python -m pip install git+https://gitlab.com/robertodr/polarizationsolver.git@master
cd
if [ "${{ matrix.os }}" == "windows-latest" ]; then
export KMP_DUPLICATE_LIB_OK=TRUE
export PYTHONPATH=Software/Lib/site-packages
python -m pytest --capture=no --log-cli-level=INFO --color=yes --pyargs cppe
else
export PYTHONPATH=$PYTHONPATH:Software/lib/python${{ matrix.python-version }}/site-packages
python -m pytest --capture=no --log-cli-level=INFO --color=yes --pyargs cppe
fi
# TODO move to separate workflow
#- name: Build and Test Setuptools
# run: |
# rm -rf build
# python setup.py install
# py.test
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # such that setuptools_scm can do its job correctly

# this will set the system compiler;
# This must be done *before* setting up miniconda, see:
# https://github.com/ilammy/msvc-dev-cmd/issues/34
- name: Set Windows env
if: matrix.os == 'windows-latest'
uses: ilammy/msvc-dev-cmd@v1
env:
KMP_DUPLICATE_LIB_OK: "TRUE"

- name: Cache conda
uses: actions/cache@v4
env:
# Increase this value to reset cache if .github/environment.yml has not changed
CACHE_NUMBER: 2
with:
path: ~/conda_pkgs_dir
key:
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-${{ hashFiles('.github/environment.yml') }}

- uses: conda-incubator/setup-miniconda@v3
with:
python-version: ${{ matrix.python-version }}
auto-update-conda: true
auto-activate-base: false
channels: conda-forge
channel-priority: true
activate-environment: cppe-gha
environment-file: .github/environment.yml

- name: Select CMake CLI options
run: |
echo "We are running on ${{ matrix.os }}"
if [ "${{ matrix.os }}" == "ubuntu-latest" ]; then
echo "SKBUILD_CMAKE_ARGS=-DCMAKE_CXX_COMPILER=g++;-GNinja" >> $GITHUB_ENV
elif [ "${{ matrix.os }}" == "macos-latest" ]; then
echo "SKBUILD_CMAKE_ARGS=-DCMAKE_CXX_COMPILER=clang++;-GNinja" >> $GITHUB_ENV
else
echo "SKBUILD_CMAKE_ARGS=-DCMAKE_CXX_COMPILER=clang-cl;-GNinja" >> $GITHUB_ENV
fi
- name: Configure, build, install
run: |
python -m pip install -v .[test]
- name: Test
run: |
python -m pytest -vvv --ignore=tests/test_fields.py --ignore=tests/test_functionality.py --ignore=tests/test_gradients.py --ignore=tests/test_solver.py
151 changes: 130 additions & 21 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,140 @@
name: Publish package

on:
push:
branches: [master]
workflow_dispatch:
pull_request:
push:
branches:
- master
release:
types:
- published

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

env:
FORCE_COLOR: 3

jobs:
publish:
build_sdist:
name: Build source distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v1
- uses: actions/checkout@v4
with:
python-version: '3.7'
- name: Install setuptools and wheel
run: |
python -m pip install --user setuptools wheel
- name: Build a source tarball
fetch-depth: 0 # such that setuptools_scm can do its job correctly

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

- uses: actions/upload-artifact@v4
with:
name: cibw-sdist
path: dist/*.tar.gz

generate-wheels-matrix:
name: Generate wheels matrix
runs-on: ubuntu-latest
outputs:
include: ${{ steps.set-matrix.outputs.include }}
steps:
- uses: actions/checkout@v4
- name: Install cibuildwheel
run: pipx install cibuildwheel==2.19.2
- id: set-matrix
run: |
pip install pytest numpy h5py scipy pandas scikit-build pybind11
pip install git+https://gitlab.com/reinholdt/polarizationsolver.git@master
python setup.py install
pytest --pyargs cppe
python setup.py sdist
- name: Publish distribution 📦 to Test PyPI
if: startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ secrets.pypi_password }}
MATRIX=$(
{
cibuildwheel --print-build-identifiers --platform linux \
| jq -nRc '{"only": inputs, "os": "ubuntu-latest"}' \
&& cibuildwheel --print-build-identifiers --platform macos \
| jq -nRc '{"only": inputs, "os": "macos-latest"}' \
&& cibuildwheel --print-build-identifiers --platform windows \
| jq -nRc '{"only": inputs, "os": "windows-latest"}'
} | jq -sc
)
echo "Full build matrix"
echo "$MATRIX"
echo "include=$MATRIX" >> $GITHUB_OUTPUT
env:
CIBW_ARCHS_LINUX: x86_64 # aarch64 # skipping as h5py stopped providing pre-build wheels for aarch64 on PyPI
CIBW_ARCHS_MACOS: x86_64 arm64
CIBW_ARCHS_WINDOWS: AMD64
# skip musl builds
CIBW_SKIP: "*-musllinux_*"
# disable free-threaded support
CIBW_FREE_THREADED_SUPPORT: False
# exclude latest Python beta
CIBW_PRERELEASE_PYTHONS: False

build_wheels:
name: Build ${{ matrix.only }}
needs: generate-wheels-matrix
strategy:
matrix:
include: ${{ fromJson(needs.generate-wheels-matrix.outputs.include) }}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # such that setuptools_scm can do its job correctly

- name: Set up QEMU
if: runner.os == 'Linux'
uses: docker/setup-qemu-action@v3
with:
platforms: all

# this will set the system compiler
- name: Set Windows env
if: matrix.os == 'windows-latest'
uses: ilammy/msvc-dev-cmd@v1

- uses: pypa/[email protected]
env:
# skip testing PyPy builds
CIBW_TEST_SKIP: "pp*"

CIBW_ENVIRONMENT_LINUX: >
SKBUILD_CMAKE_ARGS="-DENABLE_ARCH_FLAGS=OFF;-DENABLE_OPENMP=OFF"
CIBW_ENVIRONMENT_MACOS: >
SKBUILD_CMAKE_ARGS="-DENABLE_ARCH_FLAGS=OFF;-DENABLE_OPENMP=OFF"
CIBW_ENVIRONMENT_WINDOWS: >
SKBUILD_CMAKE_ARGS="-GNinja;-DCMAKE_CXX_COMPILER=clang-cl;-DENABLE_ARCH_FLAGS=OFF;-DENABLE_OPENMP=OFF"
with:
only: ${{ matrix.only }}

- name: Verify clean directory
run: git diff --exit-code
shell: bash

- uses: actions/upload-artifact@v4
with:
name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }}
path: ./wheelhouse/*.whl

upload_all:
name: Upload if release
needs:
- build_wheels
- build_sdist
environment: pypi
permissions:
id-token: write
runs-on: ubuntu-latest
#if: github.event_name == 'release' && github.event.action == 'published'

steps:
- uses: actions/download-artifact@v4
with:
pattern: cibw-*
path: dist
merge-multiple: true

- uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@ __pycache__
*.egg-info
*.eggs
.ipynb_checkpoints/

# autogenerated by setuptools-scm
_version.py
Loading

0 comments on commit 1d2d0be

Please sign in to comment.