From 556c7cb4ebc587d95e52929be7504b8bf9415f6f Mon Sep 17 00:00:00 2001 From: Mike Taves Date: Thu, 31 Jul 2025 13:00:18 +1200 Subject: [PATCH] Upgrade pre-commit repos and add ruff-check; add "dev" optional --- .pre-commit-config.yaml | 10 +++++++--- pyproject.toml | 1 + run_benchmarks.py | 2 +- src/shapefile.py | 4 ++-- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3849c55..1ef3313 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,16 +1,20 @@ repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.6.4 + rev: v0.12.7 hooks: + # Run the linter + - id: ruff-check + args: [ --fix ] + # Run the formatter - id: ruff-format - repo: https://github.com/pycqa/isort - rev: 5.13.2 + rev: 6.0.1 hooks: - id: isort name: isort (python) args: ["--profile", "black"] - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v2.3.0 + rev: v5.0.0 hooks: - id: check-yaml - id: trailing-whitespace diff --git a/pyproject.toml b/pyproject.toml index ca8f667..7d043ae 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,6 +31,7 @@ dependencies = [ ] [project.optional-dependencies] +dev = ["pyshp[test]", "pre-commit", "ruff"] test = ["pytest"] [project.urls] diff --git a/run_benchmarks.py b/run_benchmarks.py index edc2119..ac31e1c 100644 --- a/run_benchmarks.py +++ b/run_benchmarks.py @@ -41,7 +41,7 @@ def benchmark( time_taken = timeit.timeit(func, number=run_count) print("\b" * len(placeholder), end="") time_suffix = " s" - print(f"{time_taken:{col_widths[1]-len(time_suffix)}.3g}{time_suffix}", end="") + print(f"{time_taken:{col_widths[1] - len(time_suffix)}.3g}{time_suffix}", end="") print() return time_taken diff --git a/src/shapefile.py b/src/shapefile.py index f002bdd..65ffce2 100644 --- a/src/shapefile.py +++ b/src/shapefile.py @@ -1896,7 +1896,7 @@ def __init__( # Close and delete the temporary zipfile try: zipfileobj.close() - except: # pylint: disable=bare-except + except: # pylint: disable=bare-except # noqa: E722 pass # Try to load shapefile if self.shp or self.dbf: @@ -3155,7 +3155,7 @@ def __shpRecord(self, s: Shape) -> tuple[int, int]: # Shape Type if self.shapeType is None and s.shapeType != NULL: self.shapeType = s.shapeType - if not s.shapeType in {NULL, self.shapeType}: + if s.shapeType not in {NULL, self.shapeType}: raise ShapefileException( f"The shape's type ({s.shapeType}) must match " f"the type of the shapefile ({self.shapeType})."