Skip to content

Commit

Permalink
Use Maturin directly for building distributions (#755)
Browse files Browse the repository at this point in the history
  • Loading branch information
sdispater authored Sep 30, 2023
1 parent d1a874d commit 5c01d00
Show file tree
Hide file tree
Showing 139 changed files with 556 additions and 379 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/codspeed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@ jobs:
run: poetry config virtualenvs.create false

- name: Install dependencies
run: poetry install --only test --only benchmark -vvv --no-root
run: poetry install --only test --only benchmark --only build -vvv --no-root

- name: Install project
run: poetry install --only test --only benchmark --only build -vvv --no-root

- name: Install pendulum and check extensions
run: |
MATURIN_BUILD_ARGS="--no-default-features -vv" pip install -e . -v
python -c 'import _pendulum; assert _pendulum.__pendulum_default_allocator__'
poetry run pip install -e . -vvv
python -c 'import pendulum._pendulum'
- name: Run benchmarks
uses: CodSpeedHQ/action@v1
Expand Down
137 changes: 71 additions & 66 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,91 +7,99 @@ on:
workflow_dispatch:

jobs:

build_wheels:
name: Build wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}-latest
build:
name: Build on ${{ matrix.platform || matrix.os }} (${{ matrix.target }} - ${{ matrix.manylinux || 'auto' }})
strategy:
fail-fast: false
matrix:
os: [ ubuntu, windows, macos ]
os: [ubuntu, macos, windows]
target: [x86_64, aarch64]
manylinux: [auto]
include:
- os: ubuntu
platform: linux
- os: windows
ls: dir
interpreter: 3.7 3.8 3.9 3.10 3.11 3.12 pypy3.8 pypy3.9 pypy3.10
- os: windows
ls: dir
target: aarch64
interpreter: 3.11 3.12
- os: macos
target: aarch64
interpreter: 3.7 3.8 3.9 3.10 3.11 3.12 pypy3.8 pypy3.9 pypy3.10
- os: ubuntu
platform: linux
target: aarch64
# mimalloc not supported on manylinux2014 cross-compile container
extra-build-args: --no-default-features
# musllinux
- os: ubuntu
platform: linux
target: x86_64
manylinux: musllinux_1_1
- os: ubuntu
platform: linux
target: aarch64
manylinux: musllinux_1_1
- os: ubuntu
platform: linux
target: ppc64le
interpreter: 3.7 3.8 3.9 3.10 3.11 3.12
# mimalloc not supported on manylinux2014 cross-compile container
extra-build-args: --no-default-features
- os: ubuntu
platform: linux
target: s390x
interpreter: 3.7 3.8 3.9 3.10 3.11 3.12
# mimalloc not supported on manylinux2014 cross-compile container
extra-build-args: --no-default-features

runs-on: ${{ matrix.os }}-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up rust
uses: dtolnay/rust-toolchain@stable
- name: set up python
uses: actions/setup-python@v4
with:
toolchain: stable
python-version: '3.11'
architecture: ${{ matrix.python-architecture || 'x64' }}

- name: Setup Rust cache
uses: Swatinem/rust-cache@v2
- name: build wheels
uses: PyO3/maturin-action@v1
with:
key: ${{ matrix.os }}
target: ${{ matrix.target }}
manylinux: ${{ matrix.manylinux || 'auto' }}
container: ${{ matrix.container }}
args: --release --out dist --interpreter ${{ matrix.interpreter || '3.7 3.8 3.9 3.10 3.11 3.12 pypy3.7 pypy3.8 pypy3.9 pypy3.10' }} ${{ matrix.extra-build-args }}
rust-toolchain: stable
docker-options: -e CI

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

- name: Build wheels
uses: pypa/[email protected]
env:
CIBW_ARCHS_LINUX: auto aarch64
CIBW_ARCHS_MACOS: x86_64
CIBW_ARCHS_WINDOWS: AMD64
CIBW_PROJECT_REQUIRES_PYTHON: ">=3.8"
with:
package-dir: .
output-dir: dist
- run: ${{ matrix.ls || 'ls -lh' }} dist/

- uses: actions/upload-artifact@v3
with:
name: dist
path: ./dist/*

build_wheels_macos_arm:
name: Build arm64 wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ macos-12 ]
path: dist

build_sdist:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up rust
uses: dtolnay/rust-toolchain@stable
- name: Build sdist
uses: PyO3/maturin-action@v1
with:
toolchain: stable

- name: Setup Rust cache
uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.os }}

- name: Build wheels
uses: pypa/[email protected]
env:
CIBW_ARCHS_MACOS: arm64
CIBW_PROJECT_REQUIRES_PYTHON: ">=3.8"
with:
package-dir: .
output-dir: dist

- name: Fix wheel tags
run: |
python3 -m pip install wheel
python3 -m wheel tags --platform-tag macosx_12_0_arm64 dist/*-macosx*.whl --remove
- uses: actions/upload-artifact@v3
command: sdist
args: --out dist
- name: Upload sdist
uses: actions/upload-artifact@v3
with:
name: dist
path: ./dist/*
path: dist


Release:
needs: [ build_wheels, build_wheels_macos_arm ]
needs: [ build, build_sdist ]
if: success() && startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest

Expand All @@ -112,9 +120,6 @@ jobs:
- name: Update PATH
run: echo "$HOME/.local/bin" >> $GITHUB_PATH

- name: Build sdist
run: poetry build --format sdist

- name: Check distributions
run: |
ls -la dist
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,17 @@ jobs:
run: timeout 10s poetry run pip --version || rm -rf .venv

- name: Install runtime, testing, and typing dependencies
run: poetry install --only main --only test --only typing -vvv
run: poetry install --only main --only test --only typing --only build --no-root -vvv

- name: Install project
run: poetry run maturin develop

- name: Run type checking
run: poetry run mypy

- name: Uninstall typing dependencies
# This ensures pendulum runs without typing_extensions installed
run: poetry install --only main --only test --sync --no-root -vvv
run: poetry install --only main --only test --only build --sync --no-root -vvv

- name: Test Pure Python
run: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ setup.py

.vscode
/target
/rust/target
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ repos:
- id: black

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.283
rev: v0.0.291
hooks:
- id: ruff

Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ list:
no_targets__:

lint-rust:
cargo fmt --all -- --check
cargo clippy --tests -- -D warnings
cd rust && cargo fmt --all -- --check
cd rust && cargo clippy --tests -- -D warnings


format-rust:
cargo fmt --all
cargo clippy --tests --fix --allow-dirty -- -D warnings
cd rust && cargo fmt --all
cd rust && cargo clippy --tests --fix --allow-dirty -- -D warnings
56 changes: 0 additions & 56 deletions build.py

This file was deleted.

Loading

0 comments on commit 5c01d00

Please sign in to comment.