Skip to content

Commit

Permalink
adding python env to CI
Browse files Browse the repository at this point in the history
  • Loading branch information
BenJourdan committed Oct 11, 2024
1 parent eca21b7 commit 51831b4
Showing 1 changed file with 40 additions and 78 deletions.
118 changes: 40 additions & 78 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
# This file is autogenerated by maturin v1.7.4
# To update, run
#
# maturin generate-ci github
#
name: CI

on:
push:
branches:
- main
tags:
- '*'
pull_request:
workflow_dispatch:

permissions:
contents: read
Expand All @@ -25,99 +17,69 @@ jobs:
platform:
- runner: ubuntu-latest
target: x86_64
- runner: ubuntu-latest
target: x86
- runner: ubuntu-latest
target: aarch64
- runner: ubuntu-latest
target: armv7
- runner: ubuntu-latest
target: s390x
- runner: ubuntu-latest
target: ppc64le
steps:
- uses: actions/checkout@v4
- runner: windows-latest
target: x64

# Set up Python
- uses: actions/setup-python@v5
steps:
# Step 1: Set up Python environment
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: 3.x
python-version: ${{ matrix.python-version }}

# Create and activate virtual environment
- name: Create and activate virtual environment
# Step 2: Create a virtual environment and install dependencies (including black and ruff)
- name: Install dependencies
run: |
python -m venv venv
if [ ${{ runner.os }} == 'Windows' ]; then
.\venv\Scripts\activate
else
source venv/bin/activate
fi
# Install Maturin and build in same session
- name: Install Maturin and build Rust library
run: |
source venv/bin/activate
pip install maturin
maturin develop --release
source venv/bin/activate || .\venv\Scripts\activate # Linux/Windows compatible
python -m pip install --upgrade pip
pip install maturin black ruff pytest sphinx sphinx-rtd-theme # Install Black, Ruff, Maturin, etc.
pip install -r requirements.txt # Install additional project-specific dependencies
# Install dependencies
- name: Install linters, formatters, test tools, and docs tools
run: |
source venv/bin/activate
pip install ruff black pytest sphinx sphinx-rtd-theme
shell: bash

# Run Ruff for linting and import sorting
# Step 3: Run Ruff for linting and import sorting
- name: Run Ruff (Python linter)
run: |
source venv/bin/activate
ruff check . --fix
source venv/bin/activate || .\venv\Scripts\activate
ruff check . --fix # Run Ruff for linting, and --fix to auto-fix issues
shell: bash

# Run Black to ensure code formatting (non-fix mode)
# Step 4: Run Black to ensure code formatting (non-fix mode)
- name: Run Black (Python formatter check)
run: |
source venv/bin/activate
black --check .
source venv/bin/activate || .\venv\Scripts\activate
black --check . # Black is run in check mode to ensure formatting is correct
# Run Pytest to ensure Python tests pass
- name: Run Python tests with pytest
run: |
source venv/bin/activate
pytest
shell: bash

# Set up Rust toolchain
- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
# Step 5: Build and install the Rust library using Maturin (in release mode)
- name: Build and install Rust library (release mode)
run: |
source venv/bin/activate || .\venv\Scripts\activate
maturin develop --release # Build the Rust library and install it
# Run Rust tests
- name: Run Rust tests
run: cargo test
shell: bash

# Build wheels using Maturin
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
manylinux: auto
# Step 6: Run Python tests with pytest
- name: Run Python tests with pytest
run: |
source venv/bin/activate || .\venv\Scripts\activate
pytest tests/ # Run tests
# Upload wheels as artifacts
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-linux-${{ matrix.platform.target }}
path: dist
shell: bash

# Build Sphinx Documentation
# Step 7: Build Sphinx Documentation
- name: Build Sphinx Documentation
run: |
source venv/bin/activate || .\venv\Scripts\activate
cd docs
make html
# Upload Documentation as an Artifact
shell: bash

# Step 8: Upload Documentation as an Artifact
- name: Upload Documentation
uses: actions/upload-artifact@v4
with:
Expand Down

0 comments on commit 51831b4

Please sign in to comment.