From 65cd95b278a4fbda72afab7a98c930756aca20ac Mon Sep 17 00:00:00 2001 From: Luka Peschke Date: Fri, 26 Jan 2024 16:39:05 +0100 Subject: [PATCH] feat: Add windows support (#157) --- .github/workflows/CI.yml | 72 +++++++++++++++++++++++++++++------ .github/workflows/release.yml | 47 ++++++++++++++++++++++- Makefile | 2 +- pyproject.toml | 2 +- 4 files changed, 109 insertions(+), 14 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 0acd019..0c8d27b 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -7,18 +7,24 @@ on: pull_request: types: [opened, synchronize, reopened] +env: + MIN_PYTHON_VERSION: "3.8" + + +defaults: + run: + # Prevents windows runners from running on powershell + shell: bash + jobs: - linux: + lint: runs-on: ubuntu-latest - strategy: - matrix: - python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] steps: - uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v5 with: - python-version: "${{ matrix.python-version }}" + python-version: "${{ env.MIN_PYTHON_VERSION }}" - name: Set up rust toolchain uses: actions-rs/toolchain@v1 with: @@ -40,21 +46,65 @@ jobs: source .venv/bin/activate make lint - - name: Test + # GitHub provides only x86_64 runners, so we cannot test on arm architecture + test: + runs-on: ${{ matrix.os }} + strategy: + matrix: + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + os: ["ubuntu-latest", "macos-latest", "windows-latest"] + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Set up rust toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + + # Maturin requires a venv to be activated, that's why we have to create one here + - name: Create virtualenv + env: + BIN: ${{ matrix.os == 'windows-latest' && 'Scripts' || 'bin' }} run: | - source .venv/bin/activate - make test-ci + python -m venv .venv + echo "${{ github.workspace }}/.venv/${{ env.BIN }}" >> $GITHUB_PATH + + - name: Install dependencies + run: | + echo "PATH IS $PATH" + make install-test-requirements - macos: - runs-on: macos-latest + - name: Test + run: make test-ci + + check-wheel-build: + runs-on: ${{ matrix.os }} strategy: matrix: python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + os: ["ubuntu-latest", "macos-latest", "windows-latest"] + architecture: [x86-64, aarch64] + exclude: + - os: windows-latest + architecture: aarch64 steps: - uses: actions/checkout@v4 + - name: Set Rust target for aarch64 + if: matrix.architecture == 'aarch64' + id: target + run: | + TARGET=${{ matrix.os == 'macos-latest' && 'aarch64-apple-darwin' || 'aarch64-unknown-linux-gnu'}} + echo "target=$TARGET" >> $GITHUB_OUTPUT + - name: build (fast) uses: messense/maturin-action@v1 with: + manylinux: auto command: build - target: universal2-apple-darwin args: "-o dist --interpreter python${{ matrix.python-version }}" + target: ${{ steps.target.outputs.target }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 81f6492..c2dc6b5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -45,6 +45,24 @@ jobs: name: "wheels-macos-python-${{ matrix.python-version }}" path: dist + windows: + runs-on: windows-latest + strategy: + matrix: + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + steps: + - uses: actions/checkout@v4 + - name: build (release) + uses: messense/maturin-action@v1 + with: + command: build + args: "--release -o dist --interpreter python${{ matrix.python-version }}" + - name: Upload wheels + uses: actions/upload-artifact@v4 + with: + name: "wheels-windows-python-${{ matrix.python-version }}" + path: dist + # NOTE: Cannot use a matrix here, as we only want a single release release: name: Release @@ -103,13 +121,39 @@ jobs: name: "wheels-macos-python-3.12" path: wheels-macos + - name: Download Windows 3.8 wheels + uses: actions/download-artifact@v4 + with: + name: "wheels-windows-python-3.8" + path: wheels-windows + - name: Download Windows 3.9 wheels + uses: actions/download-artifact@v4 + with: + name: "wheels-windows-python-3.9" + path: wheels-windows + - name: Download Windows 3.10 wheels + uses: actions/download-artifact@v4 + with: + name: "wheels-windows-python-3.10" + path: wheels-windows + - name: Download Windows 3.11 wheels + uses: actions/download-artifact@v4 + with: + name: "wheels-windows-python-3.11" + path: wheels-windows + - name: Download Windows 3.12 wheels + uses: actions/download-artifact@v4 + with: + name: "wheels-windows-python-3.12" + path: wheels-windows + - name: Publish to PyPI uses: messense/maturin-action@v1 env: MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }} with: command: upload - args: "--skip-existing wheels-linux/*.whl wheels-macos/*.whl" + args: "--skip-existing wheels-linux/*.whl wheels-macos/*.whl wheels-windows/*.whl" - name: Release uses: softprops/action-gh-release@v1 @@ -118,3 +162,4 @@ jobs: files: | wheels-linux/*.whl wheels-macos/*.whl + wheels-windows/*.whl diff --git a/Makefile b/Makefile index cdde098..a59b9e8 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ ruff = ruff python/ *.py format = ruff format python/ *.py mypy = mypy python/ *.py -pytest = python -m pytest +pytest = pytest ## Rust clippy = cargo clippy fmt = cargo fmt diff --git a/pyproject.toml b/pyproject.toml index 0296c8d..55430ee 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,6 +43,6 @@ testpaths = [ [tool.ruff] line-length = 100 - +target-version = "py38" # Enable Pyflakes `E` and `F` codes by default. select = ["E", "F", "I", "Q", "FA102"]