From 6727cbf286a3e198a3b9379e148c4f510a57915a Mon Sep 17 00:00:00 2001 From: Dimitris Kargatzis Date: Thu, 13 Nov 2025 18:18:21 +0200 Subject: [PATCH] feat: add Python version compatibility checks and syntax validation - Add pyupgrade hook to check and fix Python version incompatibilities - Add check-ast hook for Python syntax validation - Add Python version verification step in GitHub Actions workflow - Update pyproject.toml to target Python 3.12 Signed-off-by: Dimitris Kargatzis --- .github/workflows/pre-commit-hooks.yaml | 17 +++++++++++++++-- .pre-commit-config.yaml | 12 ++++++++++++ pyproject.toml | 7 ++----- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/.github/workflows/pre-commit-hooks.yaml b/.github/workflows/pre-commit-hooks.yaml index ae057dc..59aa7b0 100644 --- a/.github/workflows/pre-commit-hooks.yaml +++ b/.github/workflows/pre-commit-hooks.yaml @@ -27,12 +27,18 @@ jobs: with: fetch-depth: 0 - # Set up Python + # Set up Python (must match requires-python in pyproject.toml) - name: Set up Python uses: actions/setup-python@v5 with: python-version: '3.12' + # Verify Python version matches project requirements + - name: Verify Python version + run: | + python --version + python -c "import sys; assert sys.version_info >= (3, 12), f'Python 3.12+ required, got {sys.version}'" + # Set up a Python virtual environment - name: Set up Python and Virtual Environment run: | @@ -48,7 +54,14 @@ jobs: pre-commit install # Run pre-commit hooks on all files - - name: Run pre-commit + # This includes: + # - Python syntax validation (check-ast) + # - Code formatting (ruff-format) + # - Linting and import sorting (ruff) + # - Python version compatibility checks (pyupgrade for Python 3.12+) + # - YAML/JSON validation + # - Trailing whitespace and end-of-file fixes + - name: Run pre-commit hooks run: | source venv/bin/activate pre-commit run --all-files --show-diff-on-failure diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2771ced..ce6dcd3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,6 +17,9 @@ repos: # Checks YAML files for syntax errors - id: check-json # Checks JSON files for syntax errors + - id: check-ast + name: "Check Python syntax (AST validation)" + # Validates that Python files have valid syntax # Ruff hooks for Python linting and formatting - repo: https://github.com/astral-sh/ruff-pre-commit @@ -31,6 +34,15 @@ repos: name: "Linting and import sorting" args: ["--fix"] + # Pyupgrade: Check and fix Python version incompatibilities and outdated syntax + - repo: https://github.com/asottile/pyupgrade + rev: v3.15.2 + hooks: + - id: pyupgrade + name: "Upgrade syntax for Python 3.12+" + args: [--py312-plus] + # Auto-fixes outdated syntax to Python 3.12+ compatible code + # Conventional pre-commit hooks for commit messages - repo: https://github.com/compilerla/conventional-pre-commit rev: v4.0.0 diff --git a/pyproject.toml b/pyproject.toml index 18ed329..47835fd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -102,9 +102,6 @@ classifiers = [ "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", "Topic :: Software Development :: Libraries :: Python Modules", "Topic :: Software Development :: Quality Assurance", @@ -160,7 +157,7 @@ watchflow = "src.main:app" [tool.black] line-length = 88 -target-version = ['py39'] +target-version = ['py312'] include = '\.pyi?$' extend-exclude = ''' /( @@ -183,7 +180,7 @@ line_length = 88 known_first_party = ["src"] [tool.mypy] -python_version = "3.9" +python_version = "3.12" warn_return_any = true warn_unused_configs = true disallow_untyped_defs = true