Skip to content

Commit

Permalink
Make rust extension optional
Browse files Browse the repository at this point in the history
  • Loading branch information
ariebovenberg committed Apr 25, 2024
1 parent fb8dc85 commit 7f64c32
Show file tree
Hide file tree
Showing 12 changed files with 331 additions and 98 deletions.
62 changes: 28 additions & 34 deletions .github/workflows/test.yml → .github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Test
name: Checks

on:
push:
Expand All @@ -8,63 +8,56 @@ on:
workflow_dispatch:

jobs:
Testing:
Test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ["3.9", "3.10", "3.11", "3.12"]
# Note: pypy/pytest fails sometimes (https://github.com/pypy/pypy/issues/3959)
python-version: ["3.9", "3.10", "3.11", "3.12", "pypy3.8", "pypy3.9", "pypy3.10"]
steps:
- uses: actions/checkout@v4

- uses: actions-rust-lang/setup-rust-toolchain@v1

- name: Set up Python
uses: actions/setup-python@v5
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Create virtual environment
run: |
python -m venv venv
- name: "Test Rust"
if: matrix.os == 'ubuntu-latest'
run: |
cargo test
- name: Install and test (Windows)
if: matrix.os == 'windows-latest'
shell: bash
run: |
source venv/Scripts/activate
python -m pip install --upgrade pip
pip install -U pip maturin
pip install -r requirements/test.txt
maturin develop --release
pytest tests/
- name: Install and test
if: ${{ matrix.os != 'windows-latest' && !((matrix.python-version == '3.12') && (matrix.os == 'ubuntu-latest')) }}
if: ${{ !((matrix.python-version == '3.12') && (matrix.os == 'ubuntu-latest')) }}
shell: bash
run: |
source venv/bin/activate
pip install -U pip maturin
pip install .
pip install -r requirements/test.txt
maturin develop --release
pytest tests/
- name: Install and test (incl coverage)
if: ${{ (matrix.python-version == '3.12') && (matrix.os == 'ubuntu-latest') }}
shell: bash
run: |
source venv/bin/activate
pip install -U pip maturin
pip install .
pip install -r requirements/test.txt
maturin develop --release
pytest tests/ --cov=whenever
Test-pure-python-implementation:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- run: |
pip install .
pip install -r requirements/test.txt
pytest tests/ --ignore tests/test_extension_demo.py
env:
WHENEVER_NO_BUILD_RUST_EXT: "1"
Linting:
runs-on: ubuntu-latest
steps:
Expand All @@ -73,9 +66,11 @@ jobs:
with:
python-version: '3.12'
- run: |
pip install -U pip maturin twine
pip install -U pip
pip install -r requirements/lint.txt
make ci-lint
env:
WHENEVER_NO_BUILD_RUST_EXT: "1"
Typecheck:
runs-on: ubuntu-latest
Expand All @@ -85,10 +80,9 @@ jobs:
with:
python-version: '3.12'
- run: |
python -m venv venv
source venv/bin/activate
pip install -U pip maturin
pip install .
pip install -r requirements/typecheck.txt
pip install -r requirements/test.txt
maturin develop
make typecheck
env:
WHENEVER_NO_BUILD_RUST_EXT: "1"
58 changes: 28 additions & 30 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build
name: Build and publish wheels

on:
push:
Expand All @@ -19,21 +19,19 @@ jobs:
target: [x86_64, x86, aarch64, armv7, s390x, ppc64le]
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
- uses: actions/setup-python@v5
with:
python-version: '3.10'
python-version: '3.12'
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
manylinux: auto
run: |
pip install cibuildwheel==2.17.0
cibuildwheel --output-dir dist
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-linux-${{ matrix.target }}
path: dist
name: cibw-wheels-linux-${{ matrix.target }}
path: dist/*.whl

windows:
runs-on: windows-latest
Expand All @@ -42,21 +40,20 @@ jobs:
target: [x64, x86]
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
- uses: actions/setup-python@v5
with:
python-version: '3.10'
python-version: '3.12'
architecture: ${{ matrix.target }}
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
run: |
pip install cibuildwheel==2.17.0
cibuildwheel --output-dir dist
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-windows-${{ matrix.target }}
path: dist
path: dist/*.whl

macos:
runs-on: macos-latest
Expand All @@ -65,15 +62,14 @@ jobs:
target: [x86_64, aarch64]
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
- uses: actions/setup-python@v5
with:
python-version: '3.10'
python-version: '3.12'
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
run: |
pip install cibuildwheel==2.17.0
cibuildwheel --output-dir dist
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
Expand All @@ -85,10 +81,9 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Build sdist
uses: PyO3/maturin-action@v1
with:
command: sdist
args: --out dist
run: |
pip install build
python -m build --sdist --outdir dist
- name: Upload sdist
uses: actions/upload-artifact@v4
with:
Expand All @@ -103,10 +98,13 @@ jobs:
steps:
- uses: actions/download-artifact@v4
- name: Publish to PyPI
uses: PyO3/maturin-action@v1
run: |
pip install twine
twine upload dist/*
env:
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
MATURIN_REPOSITORY: testpypi
TWINE_UESRNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
TWINE_REPOSITORY: testpypi
with:
command: upload
args: --non-interactive --skip-existing wheels-*/*
Loading

0 comments on commit 7f64c32

Please sign in to comment.