diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 28fa31b..469b2da 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -57,32 +57,68 @@ jobs: - 'Cargo.toml' - 'pyproject.toml' - check-quizx: - name: 🦀 Check quizx package + # Rust formatting check + rust-fmt: + name: 🦀 Rust formatting needs: changes - if: ${{ needs.changes.outputs.quizx == 'true' }} + if: ${{ needs.changes.outputs.quizx == 'true' || needs.changes.outputs.pybindings == 'true' }} runs-on: ubuntu-latest + env: + RUSTC_WRAPPER: sccache steps: - uses: actions/checkout@v4 - name: Install stable toolchain uses: dtolnay/rust-toolchain@stable with: - components: rustfmt, clippy + components: rustfmt + - uses: mozilla-actions/sccache-action@v0.0.9 + - name: Check rust formatting (workspace) + run: cargo fmt --all -- --check + + # Rust clippy check + rust-clippy: + name: 🦀 Rust clippy + needs: changes + if: ${{ needs.changes.outputs.quizx == 'true' || needs.changes.outputs.pybindings == 'true' }} + runs-on: ubuntu-latest + env: + RUSTC_WRAPPER: sccache + steps: + - uses: actions/checkout@v4 + - name: Install stable toolchain + uses: dtolnay/rust-toolchain@stable + with: + components: clippy + - uses: mozilla-actions/sccache-action@v0.0.9 + - name: Run clippy (workspace) + run: cargo clippy --workspace --all-targets --all-features -- ${{ env.CLIPPY_FLAGS }} + + # Rust documentation for quizx + rust-doc-quizx: + name: 🦀 Rust documentation (quizx) + needs: changes + if: ${{ needs.changes.outputs.quizx == 'true' }} + runs-on: ubuntu-latest + env: + RUSTC_WRAPPER: sccache + steps: + - uses: actions/checkout@v4 + - name: Install stable toolchain + uses: dtolnay/rust-toolchain@stable - uses: mozilla-actions/sccache-action@v0.0.9 - - name: Check rust formatting - run: cargo fmt -p quizx -- --check - - name: Run clippy - run: cargo clippy --all-targets --all-features -p quizx -- ${{ env.CLIPPY_FLAGS }} - name: Build docs run: cargo doc --no-deps --all-features env: RUSTDOCFLAGS: "-Dwarnings" - check-pybindings: - name: 🦀🐍 Check quizx_pybindings + # Python type checking with mypy + python-mypy: + name: 🐍 Python type checking needs: changes if: ${{ needs.changes.outputs.pybindings == 'true' }} runs-on: ubuntu-latest + env: + RUSTC_WRAPPER: sccache steps: - uses: actions/checkout@v4 - uses: mozilla-actions/sccache-action@v0.0.9 @@ -90,28 +126,76 @@ jobs: uses: dtolnay/rust-toolchain@stable with: components: rustfmt, clippy + - name: Build quizx crate + run: cargo build -p quizx - name: Install uv uses: astral-sh/setup-uv@v6 with: enable-cache: true - name: Install the project libraries run: uv sync --frozen - - name: Check rust formatting - run: cargo fmt -p quizx_pybindings -- --check - - name: Run clippy - run: cargo clippy --all-targets --all-features -p quizx_pybindings -- ${{ env.CLIPPY_FLAGS }} - name: Type check python with mypy - run: uv run mypy . + run: uv run mypy pybindings + + # Python formatting with ruff + python-ruff-format: + name: 🐍 Python formatting + needs: changes + if: ${{ needs.changes.outputs.pybindings == 'true' }} + runs-on: ubuntu-latest + env: + RUSTC_WRAPPER: sccache + steps: + - uses: actions/checkout@v4 + - uses: mozilla-actions/sccache-action@v0.0.9 + - name: Install rust stable toolchain + uses: dtolnay/rust-toolchain@stable + with: + components: rustfmt, clippy + - name: Build quizx crate + run: cargo build -p quizx + - name: Install uv + uses: astral-sh/setup-uv@v6 + with: + enable-cache: true + - name: Install the project libraries + run: uv sync --frozen - name: Check python formatting with ruff - run: uv run ruff format --check --exclude scratchpads + run: uv run ruff format --check + + # Python linting with ruff + python-ruff-lint: + name: 🐍 Python linting + needs: changes + if: ${{ needs.changes.outputs.pybindings == 'true' }} + runs-on: ubuntu-latest + env: + RUSTC_WRAPPER: sccache + steps: + - uses: actions/checkout@v4 + - uses: mozilla-actions/sccache-action@v0.0.9 + - name: Install rust stable toolchain + uses: dtolnay/rust-toolchain@stable + with: + components: rustfmt, clippy + - name: Build quizx crate + run: cargo build -p quizx + - name: Install uv + uses: astral-sh/setup-uv@v6 + with: + enable-cache: true + - name: Install the project libraries + run: uv sync --frozen - name: Lint python with ruff - run: uv run ruff check --exclude scratchpads + run: uv run ruff check test-quizx-stable: needs: changes if: ${{ needs.changes.outputs.quizx == 'true' }} runs-on: ubuntu-latest name: 🦀 Test quizx (Rust stable) + env: + RUSTC_WRAPPER: sccache steps: - uses: actions/checkout@v4 - uses: mozilla-actions/sccache-action@v0.0.9 @@ -137,6 +221,8 @@ jobs: matrix: rust: ['1.81', beta, nightly] name: 🦀 Test quizx (Rust ${{ matrix.rust }}) + env: + RUSTC_WRAPPER: sccache steps: - uses: actions/checkout@v4 - id: toolchain @@ -158,6 +244,8 @@ jobs: needs: changes if: ${{ needs.changes.outputs.pybindings == 'true' }} runs-on: ubuntu-latest + env: + RUSTC_WRAPPER: sccache steps: - uses: actions/checkout@v4 - uses: mozilla-actions/sccache-action@v0.0.9 @@ -184,7 +272,7 @@ jobs: # even if they are skipped due to no changes in the relevant files. required-checks: name: Required checks 🐍 - needs: [changes, check-quizx, check-pybindings, test-quizx-stable, test-pybindings] + needs: [changes, rust-fmt, rust-clippy, rust-doc-quizx, python-mypy, python-ruff-format, python-ruff-lint, test-quizx-stable, test-pybindings] if: ${{ !cancelled() }} runs-on: ubuntu-latest steps: @@ -195,8 +283,12 @@ jobs: # See https://github.com/orgs/community/discussions/80788 if: | needs.changes.result == 'failure' || needs.changes.result == 'cancelled' || - needs.check-quizx.result == 'failure' || needs.check-quizx.result == 'cancelled' || - needs.check-pybindings.result == 'failure' || needs.check-pybindings.result == 'cancelled' || + needs.rust-fmt.result == 'failure' || needs.rust-fmt.result == 'cancelled' || + needs.rust-clippy.result == 'failure' || needs.rust-clippy.result == 'cancelled' || + needs.rust-doc-quizx.result == 'failure' || needs.rust-doc-quizx.result == 'cancelled' || + needs.python-mypy.result == 'failure' || needs.python-mypy.result == 'cancelled' || + needs.python-ruff-format.result == 'failure' || needs.python-ruff-format.result == 'cancelled' || + needs.python-ruff-lint.result == 'failure' || needs.python-ruff-lint.result == 'cancelled' || needs.test-quizx-stable.result == 'failure' || needs.test-quizx-stable.result == 'cancelled' || needs.test-pybindings.result == 'failure' || needs.test-pybindings.result == 'cancelled' run: | diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2f3fbc9..b6e5cc4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -52,14 +52,14 @@ repos: - id: ruff format name: ruff format description: Format python code with `ruff format`. - entry: uv run ruff format --exclude scratchpads + entry: uv run ruff format language: system files: \.py$ pass_filenames: false - id: ruff lint name: ruff lint description: Lint python code with `ruff lint`. - entry: uv run ruff check --exclude scratchpads + entry: uv run ruff check language: system files: \.py$ pass_filenames: false diff --git a/pyproject.toml b/pyproject.toml index d2776a7..1d92f19 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,3 +22,6 @@ build-backend = "hatchling.build" manifest-path = "pybindings/Cargo.toml" python-source = "pybindings" module-name = "quizx" + +[tool.ruff] +exclude = ["scratchpads"]