From 6c9b997e31aa7857605d76b40c31b94b0cca9f48 Mon Sep 17 00:00:00 2001 From: Fee Fladder Date: Tue, 29 Jul 2025 19:21:31 +0200 Subject: [PATCH 1/3] feat:pre-commit Added pre-commit file and added to Python CI --- .github/workflows/test-python.yml | 24 +++++++++++++ .pre-commit-config.yaml | 50 ++++++++++++++++++++++++++++ python/README.md | 1 - python/python/async_tiff/__init__.py | 4 +-- tests/image_tiff/images/COPYRIGHT | 12 +++---- 5 files changed, 82 insertions(+), 9 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.github/workflows/test-python.yml b/.github/workflows/test-python.yml index e3276d9..12cd031 100644 --- a/.github/workflows/test-python.yml +++ b/.github/workflows/test-python.yml @@ -7,6 +7,30 @@ on: pull_request: jobs: + pre-commit: + name: Pre-Commit + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v5 + with: + python-version: "3.11" + + # Use ruff-action so we get annotations in the GitHub UI + - uses: astral-sh/ruff-action@v3 + + - name: Cache pre-commit virtualenvs + uses: actions/cache@v4 + with: + path: ~/.cache/pre-commit + key: pre-commit-3|${{ hashFiles('.pre-commit-config.yaml') }} + + - name: run pre-commit + run: | + python -m pip install pre-commit + pre-commit run --all-files + lint-test: name: Lint and Test runs-on: ubuntu-latest diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..5aa88cb --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,50 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks + +# Default to Python 3 +default_language_version: + python: python3 + +# Optionally both commit and push +default_stages: [pre-commit] + +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v5.0.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-added-large-files + args: ["--maxkb=500"] + + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.11.0 + hooks: + - id: ruff + args: ["--fix"] + - id: ruff-format + + - repo: local + hooks: + - id: rust-fmt + name: cargo fmt + entry: cargo fmt --all -- --check + language: system + types: [rust] + stages: [pre-push] + + - id: rust-clippy + name: cargo clippy + entry: cargo clippy --all --all-features --tests -- -D warnings + language: system + types: [rust] + stages: [pre-push] + pass_filenames: false + + - id: rust-test + name: cargo test + entry: cargo test --all --all-features + language: system + types: [rust] + stages: [pre-push] + pass_filenames: false diff --git a/python/README.md b/python/README.md index eea777d..9801a20 100644 --- a/python/README.md +++ b/python/README.md @@ -83,4 +83,3 @@ primary_ifd.bits_per_sample[0] tile = await tiff.fetch_tile(0, 0, 0) decoded_bytes = await tile.decode_async() ``` - diff --git a/python/python/async_tiff/__init__.py b/python/python/async_tiff/__init__.py index 7ed52b8..9453bc6 100644 --- a/python/python/async_tiff/__init__.py +++ b/python/python/async_tiff/__init__.py @@ -1,9 +1,9 @@ from typing import TYPE_CHECKING -from ._async_tiff import * +from ._async_tiff import * # noqa: F403 from ._async_tiff import ___version if TYPE_CHECKING: - from . import store + from . import store # noqa: F401 __version__: str = ___version() diff --git a/tests/image_tiff/images/COPYRIGHT b/tests/image_tiff/images/COPYRIGHT index 8282186..dc255de 100644 --- a/tests/image_tiff/images/COPYRIGHT +++ b/tests/image_tiff/images/COPYRIGHT @@ -1,7 +1,7 @@ Copyright (c) 1988-1997 Sam Leffler Copyright (c) 1991-1997 Silicon Graphics, Inc. -Permission to use, copy, modify, distribute, and sell this software and +Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted without fee, provided that (i) the above copyright notices and this permission notice appear in all copies of the software and related documentation, and (ii) the names of @@ -9,13 +9,13 @@ Sam Leffler and Silicon Graphics may not be used in any advertising or publicity relating to the software without the specific, prior written permission of Sam Leffler and Silicon Graphics. -THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, -EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY -WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. +THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, +EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY +WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF -LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE +WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF +LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. From 7c2662600df7e7c54cf380cb2bd51aea06190c94 Mon Sep 17 00:00:00 2001 From: Fee Fladder Date: Wed, 30 Jul 2025 10:35:36 +0200 Subject: [PATCH 2/3] added comments to rust block in .pre-commit-config.yaml --- .pre-commit-config.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5aa88cb..ef18d49 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -24,6 +24,10 @@ repos: args: ["--fix"] - id: ruff-format + # pre-push rust formatting, linting and testing + # install these "manually" with `pre-commit install -t pre-push` + # otherwise they are ignored + # https://pre-commit.com/#confining-hooks-to-run-at-certain-stages - repo: local hooks: - id: rust-fmt From 30de3d38acd87add8d719e5587810dc47a9e0824 Mon Sep 17 00:00:00 2001 From: Fee Fladder Date: Tue, 5 Aug 2025 11:27:39 +0200 Subject: [PATCH 3/3] removed rust pre-push rules --- .pre-commit-config.yaml | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ef18d49..63b77ab 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -23,32 +23,3 @@ repos: - id: ruff args: ["--fix"] - id: ruff-format - - # pre-push rust formatting, linting and testing - # install these "manually" with `pre-commit install -t pre-push` - # otherwise they are ignored - # https://pre-commit.com/#confining-hooks-to-run-at-certain-stages - - repo: local - hooks: - - id: rust-fmt - name: cargo fmt - entry: cargo fmt --all -- --check - language: system - types: [rust] - stages: [pre-push] - - - id: rust-clippy - name: cargo clippy - entry: cargo clippy --all --all-features --tests -- -D warnings - language: system - types: [rust] - stages: [pre-push] - pass_filenames: false - - - id: rust-test - name: cargo test - entry: cargo test --all --all-features - language: system - types: [rust] - stages: [pre-push] - pass_filenames: false