From 717a463a3ef8932b6258925122ae0443cae42518 Mon Sep 17 00:00:00 2001 From: Peter Byfield Date: Sat, 8 Feb 2025 17:11:05 +0100 Subject: [PATCH 1/4] CI: Split rust checks out from python checks We don't need to run the rust tests for every single python version in the matrix. --- .github/workflows/main.yml | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 686985d7..b141944c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -9,8 +9,8 @@ on: workflow_dispatch: jobs: - tests: - name: Python ${{ matrix.python-version }}, ${{ matrix.os }} + check_python: + name: Check Python ${{ matrix.python-version }}, ${{ matrix.os }} runs-on: ${{ matrix.os }} strategy: @@ -22,14 +22,9 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: actions-rs/toolchain@v1 with: toolchain: stable - - - run: cargo test --no-default-features - working-directory: ./rust - - uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} @@ -43,6 +38,17 @@ jobs: - name: Run tox targets for ${{ matrix.python-version }} run: python -m tox + check_rust: + name: Check Rust + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + - run: cargo test --no-default-features + working-directory: ./rust + benchmarks: runs-on: ubuntu-22.04 steps: From 46635a9717055f316cafb57ad2d9aaa347b4880c Mon Sep 17 00:00:00 2001 From: Peter Byfield Date: Sat, 8 Feb 2025 17:16:51 +0100 Subject: [PATCH 2/4] CI: Add Clippy Clippy is a very popular linter for rust code. The default condifuration is good. Clippy can help us to catch issues related to code correctness, style and performance. https://doc.rust-lang.org/clippy/index.html --- .github/workflows/main.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b141944c..548780e7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -46,7 +46,11 @@ jobs: - uses: actions-rs/toolchain@v1 with: toolchain: stable - - run: cargo test --no-default-features + - name: Run tests + run: cargo test --no-default-features + working-directory: ./rust + - name: Run linter (clippy) + run: cargo clippy --all-targets --all-features working-directory: ./rust benchmarks: From 356627b7b7a25678cd79525f0bac9c8680e84e14 Mon Sep 17 00:00:00 2001 From: Peter Byfield Date: Sat, 8 Feb 2025 17:19:37 +0100 Subject: [PATCH 3/4] CI: Fail on clippy warnings Most of the time clippy warnings are there for a reason and it's best to restructure the code to avoid them. Clippy can often apply automatic fixes with the `--fix` option. In the rare case that clippy is wrong, lints can be ignored at the module/function level. --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 548780e7..30ec463f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -50,7 +50,7 @@ jobs: run: cargo test --no-default-features working-directory: ./rust - name: Run linter (clippy) - run: cargo clippy --all-targets --all-features + run: cargo clippy --all-targets --all-features -- -D warnings working-directory: ./rust benchmarks: From c12e5f11bd7d9908c2925d40621b4783aea1688d Mon Sep 17 00:00:00 2001 From: Peter Byfield Date: Sat, 8 Feb 2025 17:29:28 +0100 Subject: [PATCH 4/4] Add note about rust code to the contributing guide --- CONTRIBUTING.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 5ecedfc5..472226dd 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -61,6 +61,16 @@ To set up `grimp` for local development: 6. Submit a pull request through the GitHub website. +Rust code +--------- + +When working with the rust code (in the ``rust/`` directory): + +* Run tests with ``cargo test --no-default-features``. + The ``--no-default-features`` flag is needed to due to `this PYO3 issue `_. +* Run `clippy `_ (a linter for rust) with ``cargo clippy --all-targets --all-features -- -D warnings``. + It's often possible to apply automatic fixes to clippy issues with the ``--fix`` flag e.g. ``cargo clippy --all-targets --all-features --fix --allow-staged``. + Pull Request Guidelines -----------------------