Skip to content

Commit 766c5d7

Browse files
authored
Merge pull request #19 from warestack/feat/harden-pre-commit-hooks
feat: add Python version compatibility checks and syntax validation
2 parents 4e1e1a3 + 6727cbf commit 766c5d7

3 files changed

Lines changed: 29 additions & 7 deletions

File tree

.github/workflows/pre-commit-hooks.yaml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,18 @@ jobs:
2727
with:
2828
fetch-depth: 0
2929

30-
# Set up Python
30+
# Set up Python (must match requires-python in pyproject.toml)
3131
- name: Set up Python
3232
uses: actions/setup-python@v5
3333
with:
3434
python-version: '3.12'
3535

36+
# Verify Python version matches project requirements
37+
- name: Verify Python version
38+
run: |
39+
python --version
40+
python -c "import sys; assert sys.version_info >= (3, 12), f'Python 3.12+ required, got {sys.version}'"
41+
3642
# Set up a Python virtual environment
3743
- name: Set up Python and Virtual Environment
3844
run: |
@@ -48,7 +54,14 @@ jobs:
4854
pre-commit install
4955
5056
# Run pre-commit hooks on all files
51-
- name: Run pre-commit
57+
# This includes:
58+
# - Python syntax validation (check-ast)
59+
# - Code formatting (ruff-format)
60+
# - Linting and import sorting (ruff)
61+
# - Python version compatibility checks (pyupgrade for Python 3.12+)
62+
# - YAML/JSON validation
63+
# - Trailing whitespace and end-of-file fixes
64+
- name: Run pre-commit hooks
5265
run: |
5366
source venv/bin/activate
5467
pre-commit run --all-files --show-diff-on-failure

.pre-commit-config.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ repos:
1717
# Checks YAML files for syntax errors
1818
- id: check-json
1919
# Checks JSON files for syntax errors
20+
- id: check-ast
21+
name: "Check Python syntax (AST validation)"
22+
# Validates that Python files have valid syntax
2023

2124
# Ruff hooks for Python linting and formatting
2225
- repo: https://github.com/astral-sh/ruff-pre-commit
@@ -31,6 +34,15 @@ repos:
3134
name: "Linting and import sorting"
3235
args: ["--fix"]
3336

37+
# Pyupgrade: Check and fix Python version incompatibilities and outdated syntax
38+
- repo: https://github.com/asottile/pyupgrade
39+
rev: v3.15.2
40+
hooks:
41+
- id: pyupgrade
42+
name: "Upgrade syntax for Python 3.12+"
43+
args: [--py312-plus]
44+
# Auto-fixes outdated syntax to Python 3.12+ compatible code
45+
3446
# Conventional pre-commit hooks for commit messages
3547
- repo: https://github.com/compilerla/conventional-pre-commit
3648
rev: v4.0.0

pyproject.toml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,6 @@ classifiers = [
102102
"Intended Audience :: Developers",
103103
"License :: OSI Approved :: MIT License",
104104
"Programming Language :: Python :: 3",
105-
"Programming Language :: Python :: 3.9",
106-
"Programming Language :: Python :: 3.10",
107-
"Programming Language :: Python :: 3.11",
108105
"Programming Language :: Python :: 3.12",
109106
"Topic :: Software Development :: Libraries :: Python Modules",
110107
"Topic :: Software Development :: Quality Assurance",
@@ -160,7 +157,7 @@ watchflow = "src.main:app"
160157

161158
[tool.black]
162159
line-length = 88
163-
target-version = ['py39']
160+
target-version = ['py312']
164161
include = '\.pyi?$'
165162
extend-exclude = '''
166163
/(
@@ -183,7 +180,7 @@ line_length = 88
183180
known_first_party = ["src"]
184181

185182
[tool.mypy]
186-
python_version = "3.9"
183+
python_version = "3.12"
187184
warn_return_any = true
188185
warn_unused_configs = true
189186
disallow_untyped_defs = true

0 commit comments

Comments
 (0)