diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8003605..031b8d4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,19 +17,14 @@ jobs: matrix: runs-on: [ubuntu-latest, windows-latest, macos-latest] python: - - 3.8 - - 3.9 - '3.10' - '3.11' - '3.12' + - '3.13' exclude: - # macos-latest is now running on M1 macs + # Python 3.10 has issues on macOS M1 runners (missing gettext/libintl) - runs-on: macos-latest - python: 3.8 - - runs-on: macos-latest - python: 3.9 - - runs-on: macos-latest - python: 3.10 + python: '3.10' name: "Unit tests • ${{ matrix.python }} • ${{ matrix.runs-on }} • x64 ${{ matrix.args }}" runs-on: ${{ matrix.runs-on }} @@ -81,19 +76,14 @@ jobs: matrix: runs-on: [ubuntu-latest, windows-latest, macos-latest] python: - - 3.8 - - 3.9 - '3.10' - '3.11' - '3.12' + - '3.13' exclude: - # macos-latest is now running on M1 macs - - runs-on: macos-latest - python: 3.8 + # Python 3.10 has issues on macOS M1 runners (missing gettext/libintl) - runs-on: macos-latest - python: 3.9 - - runs-on: macos-latest - python: 3.10 + python: '3.10' name: "System tests ${{ matrix.python }} • ${{ matrix.runs-on }} • x64 ${{ matrix.args }}" runs-on: ${{ matrix.runs-on }} @@ -110,10 +100,6 @@ jobs: git fetch --prune --unshallow git fetch --depth=1 origin +refs/tags/*:refs/tags/* - - name: Enable Developer Command Prompt - if: runner.os == 'Windows' - uses: ilammy/msvc-dev-cmd@v1.13.0 - - name: Setup Python ${{ matrix.python }} uses: actions/setup-python@v5 with: @@ -142,28 +128,36 @@ jobs: - name: Prepare env (Windows) if: runner.os == 'Windows' run: | - choco install -y llvm cppcheck ninja - if (!(Test-Path -Path $PROFILE)) { - New-Item -ItemType File -Path $PROFILE -Force - } + choco install -y llvm ninja + Import-Module "${ENV:ChocolateyInstall}\helpers\chocolateyProfile.psm1" + Update-SessionEnvironment - Write-Output 'Import-Module "${ENV:ChocolateyInstall}\helpers\chocolateyProfile.psm1"' | Out-File -FilePath $PROFILE -Append -Encoding utf8 - Write-Output 'Update-SessionEnvironment' | Out-File -FilePath $PROFILE -Append -Encoding utf8 - Write-Output '$id = vswhere -property instanceId' | Out-File -FilePath $PROFILE -Append -Encoding utf8 - Write-Output 'Import-Module "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"' ` - | Out-File -FilePath $PROFILE -Append -Encoding utf8 - Write-Output 'Enter-VsDevShell -InstanceId $id' | Out-File -FilePath $PROFILE -Append -Encoding utf8 - Write-Output 'Set-Location -Path "${ENV:GITHUB_WORKSPACE}"' | Out-File -FilePath $PROFILE -Append -Encoding utf8 - Get-Content -Path $PROFILE + # Restore Python to PATH after Update-SessionEnvironment (it resets PATH from system) + $env:PATH = "$env:pythonLocation;$env:pythonLocation\Scripts;$env:PATH" - . $PROFILE - Get-Location + # Install cppcheck via pip (choco package is broken, pip wheel works correctly) + python -m pip install pre-commit cpplint lizard cppcheck - Write-Output "CMAKE_PREFIX_PATH=$env:PATH" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + Get-Command @("python", "clang-format", "clang-tidy", "cppcheck", "cpplint", "lizard", "pre-commit") - python -m pip install pre-commit cpplint lizard + # Enable MSVC dev command AFTER chocolatey packages are installed to avoid + # Update-SessionEnvironment overwriting MSVC environment variables + - name: Enable Developer Command Prompt + if: runner.os == 'Windows' + uses: ilammy/msvc-dev-cmd@v1.13.0 - Get-Command @("python", "clang-format", "clang-tidy", "cppcheck", "cpplint", "lizard", "pre-commit") + # Restore Python to front of PATH after MSVC setup + # (MSVC's vcvarsall.bat prepends paths including VS's bundled Python 3.9, + # which conflicts with our Python 3.10+ requirement) + - name: Restore Python PATH + if: runner.os == 'Windows' + run: | + "$env:pythonLocation" >> $env:GITHUB_PATH + "$env:pythonLocation\Scripts" >> $env:GITHUB_PATH + # Ensure python3 also points to the correct Python (pre-commit looks for python3) + if (-not (Test-Path "$env:pythonLocation\python3.exe")) { + Copy-Item "$env:pythonLocation\python.exe" "$env:pythonLocation\python3.exe" + } - name: Build and install package run: python -m pip install -e .[test] @@ -180,6 +174,8 @@ jobs: CC: cl CXX: cl LOGLEVEL: DEBUG + # Use a fresh pre-commit cache to avoid Python version mismatch + PRE_COMMIT_HOME: ${{ runner.temp }}/pre-commit-cache run: ./tests/run_tests.ps1 sonarcloud: diff --git a/CHANGELOG.md b/CHANGELOG.md index 26d082f..9bb23bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,8 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- Drop support for Python 3.8 and 3.9 (end-of-life) +- Add support for Python 3.13 +- Minimum required Python version is now 3.10 + +### Fixed + +- Fixed PowerShell system test script using `$?` instead of `$LASTEXITCODE` for exit code handling + ### Repository +- Fixed Windows CI by using pip to install cppcheck (Chocolatey package is broken) + - Clarify where to put the settings in `pyproject.toml` - Update GitHub Action `actions/download-artifact` to v4 - Update GitHub Action `actions/upload-artifact` to v4 diff --git a/pyproject.toml b/pyproject.toml index 2f5dc3b..833335d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,7 +11,7 @@ authors = [ ] description = 'pre-commit hooks for CMake-based projects' readme = 'README.md' -requires-python = '>=3.8' +requires-python = '>=3.10' keywords = [ ] license = {text = 'Apache2'} @@ -19,11 +19,10 @@ classifiers = [ 'License :: OSI Approved :: Apache Software License', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3 :: Only', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9', 'Programming Language :: Python :: 3.10', 'Programming Language :: Python :: 3.11', 'Programming Language :: Python :: 3.12', + 'Programming Language :: Python :: 3.13', ] dependencies = [ 'toml', @@ -66,7 +65,7 @@ namespaces = false [tool.ruff] line-length = 120 -target-version = 'py38' +target-version = 'py310' [tool.ruff.lint] diff --git a/tests/run_tests.ps1 b/tests/run_tests.ps1 index 8769b10..f3a87bf 100644 --- a/tests/run_tests.ps1 +++ b/tests/run_tests.ps1 @@ -84,11 +84,11 @@ cp .pre-commit-win.yaml .pre-commit-win.yaml.bak git add *.txt *.cpp .pre-commit*.yaml git commit -m 'Initial commit' pre-commit run -c .pre-commit-win.yaml --all-files -$ret=$? +$ret=$LASTEXITCODE mv -Force .pre-commit-win.yaml.bak .pre-commit-win.yaml rm -Force -Recurse .git -if ($ret -eq 0) { - echo "Pre-commit on tests/cmake_good failed!" +if ($ret -ne 0) { + echo "Pre-commit on tests/cmake_good failed with exit code $ret!" Exit 1 } cd ../.. @@ -102,10 +102,10 @@ cp .pre-commit-win.yaml .pre-commit-win.yaml.bak git add *.txt *.cpp .pre-commit*.yaml git commit -m 'Initial commit' pre-commit run -c .pre-commit-win.yaml --all-files -$ret=$? +$ret=$LASTEXITCODE mv -Force .pre-commit-win.yaml.bak .pre-commit-win.yaml rm -Force -Recurse .git -if ($ret -eq 1) { +if ($ret -eq 0) { echo "Pre-commit on tests/cmake_bad unexpectedly passed!" Exit 1 }