Skip to content

feat:pre-commit Added pre-commit file and added to Python CI #112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/test-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
50 changes: 50 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since these stages are pre-push, they don't run in CI as can be seen here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm lukewarm about using pre-commit to manage Rust linting. pre-commit is mostly just used in the Python community IIRC

Copy link
Contributor Author

@feefladder feefladder Jul 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm... there was a repo for rust-like linting, but it was rather stale, so I didn't use that.

I searched "Rust pre-commit" and found this commitizen blog where they use it also for rust stuff. Whether commitizen is wanted here I don't know (think not). also this rather large project using pre-commit almost the same as here. Also cargo-deny provides a pre-commit hook.

Then some rust-specific pre-commit info directly uses custom scripts (which I think is suboptimal)

I understand your lukewarm support though, it's a bit double to have it both in pre-commit and CI (and those going out of sync). Commitizen is python-based, but also supports rust.

However, I always spend wayy too much time having failing fmt/clippy tests in CI, so added it here, since I was working on pre-commit hooks anyways.

sidenote: these are crates replacing python pre-commit:

  • snp claim production-ready, but rarely any downloads?
  • prefligit not production-ready

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I now added a comment to clarify that they do nothing unless explicitly installed through pre-commit install -t pre-push
I thought that way it's a clear opt-in for people like me?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kylebarron I think I misinterpreted "lukewarm" first? So now I removed everything rust-related :)

1 change: 0 additions & 1 deletion python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,3 @@ primary_ifd.bits_per_sample[0]
tile = await tiff.fetch_tile(0, 0, 0)
decoded_bytes = await tile.decode_async()
```

4 changes: 2 additions & 2 deletions python/python/async_tiff/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Comment on lines -3 to +7
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This gave ruff errors, not sure if we want to fix those or ignore like now


__version__: str = ___version()
12 changes: 6 additions & 6 deletions tests/image_tiff/images/COPYRIGHT
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
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
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
Comment on lines -4 to +20
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trim-whitespace

OF THIS SOFTWARE.