Skip to content

Commit cb73f87

Browse files
Takishimaclaude
andauthored
Fix Windows CI and update Python version support (#131)
* Fix PowerShell system test exit code handling - Replace $? with $LASTEXITCODE for proper exit code capture - Fix inverted test logic: cmake_good should fail when exit code != 0, cmake_bad should fail when exit code == 0 - Add exit code to error message for easier debugging $? in PowerShell is a boolean (True/False), not the actual exit code. The correct way to capture external program exit codes is $LASTEXITCODE. * Fix Windows CI: use scoop for cppcheck installation The Chocolatey cppcheck package is broken - it was compiled with a hardcoded FILESDIR path that doesn't exist on GitHub Actions runners: "Failed to load std.cfg. The Cppcheck binary was compiled with FILESDIR set to R:/winlibs64ucrt_stage/inst_cppcheck-2.14.0/share/Cppcheck" The official cppcheck project marks the Chocolatey package as outdated and recommends using Scoop instead. This change: - Installs cppcheck via Scoop instead of Chocolatey - Adds Scoop shims directory to PATH for the job * Update CHANGELOG for Windows CI fixes * Drop Python 3.8/3.9, add Python 3.13 support - 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 - Update ruff target-version to py310 - Fix Windows CI: use pip cppcheck wheel instead of broken Chocolatey package (Strawberry Perl's bundled cppcheck was being picked up instead of scoop's) * Exclude Python 3.10 on macOS (M1 gettext/libintl issue) * Fix Windows CI: restore Python path after VsDevShell * Fix Windows CI: don't persist VsDevShell in PROFILE The PROFILE was running Enter-VsDevShell in every PowerShell step, resetting PATH each time and overriding the Python set by setup-python. Now VsDevShell setup only runs in the Prepare env step itself. * Simplify Windows CI: use ilammy/msvc-dev-cmd instead of manual VsDevShell The ilammy/msvc-dev-cmd action already sets up MSVC environment and exports it to GITHUB_ENV before setup-python runs. The manual Enter-VsDevShell call was redundant and caused PATH conflicts. * Fix Windows CI: move MSVC dev cmd after chocolatey install (#132) The Update-SessionEnvironment call from chocolatey was overwriting MSVC environment variables set by ilammy/msvc-dev-cmd. By moving the MSVC dev command step after chocolatey packages are installed, we ensure the MSVC environment persists to subsequent steps. Co-authored-by: Claude <noreply@anthropic.com> * Fix Windows CI: restore Python PATH after MSVC setup (#133) * Fix Windows CI: restore Python PATH after MSVC setup The ilammy/msvc-dev-cmd action runs vcvarsall.bat which prepends Visual Studio paths to PATH. VS 2022 includes a bundled Python 3.9, which then takes precedence over the Python 3.10+ set up by actions/setup-python. This caused pre-commit to use Python 3.9 when installing the cmake-pre-commit-hooks package, which fails because the package requires Python 3.10+. Fix by adding a step after msvc-dev-cmd that writes the correct Python path to GITHUB_PATH, ensuring it's prepended in subsequent steps. * Add debugging for Windows Python PATH verification Add a step to verify which Python and pre-commit are being used after the PATH restoration to help diagnose CI failures. * Fix Windows CI: ensure python3 points to correct Python Pre-commit looks for 'python3' when creating virtualenvs for hooks. After MSVC dev cmd runs, 'python3' might point to VS's bundled Python 3.9 instead of the Python 3.10+ from actions/setup-python. This fix: 1. Creates python3.exe as a copy of python.exe if it doesn't exist 2. Uses a fresh PRE_COMMIT_HOME to avoid cached environments 3. Adds detailed PATH debugging to diagnose issues * Fix Windows CI: restore Python PATH after Update-SessionEnvironment The chocolatey Update-SessionEnvironment command resets PATH from system environment variables, which overwrites the Python path set by actions/setup-python. This caused pip to install packages into Python 3.9.13 (system Python) instead of Python 3.12.10. Fix by explicitly restoring pythonLocation to PATH immediately after Update-SessionEnvironment, before running pip install. * Remove debugging code from Windows CI --------- Co-authored-by: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 2ad3c44 commit cb73f87

4 files changed

Lines changed: 53 additions & 46 deletions

File tree

.github/workflows/ci.yml

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,14 @@ jobs:
1717
matrix:
1818
runs-on: [ubuntu-latest, windows-latest, macos-latest]
1919
python:
20-
- 3.8
21-
- 3.9
2220
- '3.10'
2321
- '3.11'
2422
- '3.12'
23+
- '3.13'
2524
exclude:
26-
# macos-latest is now running on M1 macs
25+
# Python 3.10 has issues on macOS M1 runners (missing gettext/libintl)
2726
- runs-on: macos-latest
28-
python: 3.8
29-
- runs-on: macos-latest
30-
python: 3.9
31-
- runs-on: macos-latest
32-
python: 3.10
27+
python: '3.10'
3328

3429
name: "Unit tests • ${{ matrix.python }} • ${{ matrix.runs-on }} • x64 ${{ matrix.args }}"
3530
runs-on: ${{ matrix.runs-on }}
@@ -81,19 +76,14 @@ jobs:
8176
matrix:
8277
runs-on: [ubuntu-latest, windows-latest, macos-latest]
8378
python:
84-
- 3.8
85-
- 3.9
8679
- '3.10'
8780
- '3.11'
8881
- '3.12'
82+
- '3.13'
8983
exclude:
90-
# macos-latest is now running on M1 macs
91-
- runs-on: macos-latest
92-
python: 3.8
84+
# Python 3.10 has issues on macOS M1 runners (missing gettext/libintl)
9385
- runs-on: macos-latest
94-
python: 3.9
95-
- runs-on: macos-latest
96-
python: 3.10
86+
python: '3.10'
9787

9888
name: "System tests ${{ matrix.python }} • ${{ matrix.runs-on }} • x64 ${{ matrix.args }}"
9989
runs-on: ${{ matrix.runs-on }}
@@ -110,10 +100,6 @@ jobs:
110100
git fetch --prune --unshallow
111101
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
112102
113-
- name: Enable Developer Command Prompt
114-
if: runner.os == 'Windows'
115-
uses: ilammy/msvc-dev-cmd@v1.13.0
116-
117103
- name: Setup Python ${{ matrix.python }}
118104
uses: actions/setup-python@v5
119105
with:
@@ -142,28 +128,36 @@ jobs:
142128
- name: Prepare env (Windows)
143129
if: runner.os == 'Windows'
144130
run: |
145-
choco install -y llvm cppcheck ninja
146-
if (!(Test-Path -Path $PROFILE)) {
147-
New-Item -ItemType File -Path $PROFILE -Force
148-
}
131+
choco install -y llvm ninja
132+
Import-Module "${ENV:ChocolateyInstall}\helpers\chocolateyProfile.psm1"
133+
Update-SessionEnvironment
149134
150-
Write-Output 'Import-Module "${ENV:ChocolateyInstall}\helpers\chocolateyProfile.psm1"' | Out-File -FilePath $PROFILE -Append -Encoding utf8
151-
Write-Output 'Update-SessionEnvironment' | Out-File -FilePath $PROFILE -Append -Encoding utf8
152-
Write-Output '$id = vswhere -property instanceId' | Out-File -FilePath $PROFILE -Append -Encoding utf8
153-
Write-Output 'Import-Module "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"' `
154-
| Out-File -FilePath $PROFILE -Append -Encoding utf8
155-
Write-Output 'Enter-VsDevShell -InstanceId $id' | Out-File -FilePath $PROFILE -Append -Encoding utf8
156-
Write-Output 'Set-Location -Path "${ENV:GITHUB_WORKSPACE}"' | Out-File -FilePath $PROFILE -Append -Encoding utf8
157-
Get-Content -Path $PROFILE
135+
# Restore Python to PATH after Update-SessionEnvironment (it resets PATH from system)
136+
$env:PATH = "$env:pythonLocation;$env:pythonLocation\Scripts;$env:PATH"
158137
159-
. $PROFILE
160-
Get-Location
138+
# Install cppcheck via pip (choco package is broken, pip wheel works correctly)
139+
python -m pip install pre-commit cpplint lizard cppcheck
161140
162-
Write-Output "CMAKE_PREFIX_PATH=$env:PATH" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
141+
Get-Command @("python", "clang-format", "clang-tidy", "cppcheck", "cpplint", "lizard", "pre-commit")
163142
164-
python -m pip install pre-commit cpplint lizard
143+
# Enable MSVC dev command AFTER chocolatey packages are installed to avoid
144+
# Update-SessionEnvironment overwriting MSVC environment variables
145+
- name: Enable Developer Command Prompt
146+
if: runner.os == 'Windows'
147+
uses: ilammy/msvc-dev-cmd@v1.13.0
165148

166-
Get-Command @("python", "clang-format", "clang-tidy", "cppcheck", "cpplint", "lizard", "pre-commit")
149+
# Restore Python to front of PATH after MSVC setup
150+
# (MSVC's vcvarsall.bat prepends paths including VS's bundled Python 3.9,
151+
# which conflicts with our Python 3.10+ requirement)
152+
- name: Restore Python PATH
153+
if: runner.os == 'Windows'
154+
run: |
155+
"$env:pythonLocation" >> $env:GITHUB_PATH
156+
"$env:pythonLocation\Scripts" >> $env:GITHUB_PATH
157+
# Ensure python3 also points to the correct Python (pre-commit looks for python3)
158+
if (-not (Test-Path "$env:pythonLocation\python3.exe")) {
159+
Copy-Item "$env:pythonLocation\python.exe" "$env:pythonLocation\python3.exe"
160+
}
167161
168162
- name: Build and install package
169163
run: python -m pip install -e .[test]
@@ -180,6 +174,8 @@ jobs:
180174
CC: cl
181175
CXX: cl
182176
LOGLEVEL: DEBUG
177+
# Use a fresh pre-commit cache to avoid Python version mismatch
178+
PRE_COMMIT_HOME: ${{ runner.temp }}/pre-commit-cache
183179
run: ./tests/run_tests.ps1
184180

185181
sonarcloud:

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Changed
11+
12+
- Drop support for Python 3.8 and 3.9 (end-of-life)
13+
- Add support for Python 3.13
14+
- Minimum required Python version is now 3.10
15+
16+
### Fixed
17+
18+
- Fixed PowerShell system test script using `$?` instead of `$LASTEXITCODE` for exit code handling
19+
1020
### Repository
1121

22+
- Fixed Windows CI by using pip to install cppcheck (Chocolatey package is broken)
23+
1224
- Clarify where to put the settings in `pyproject.toml`
1325
- Update GitHub Action `actions/download-artifact` to v4
1426
- Update GitHub Action `actions/upload-artifact` to v4

pyproject.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,18 @@ authors = [
1111
]
1212
description = 'pre-commit hooks for CMake-based projects'
1313
readme = 'README.md'
14-
requires-python = '>=3.8'
14+
requires-python = '>=3.10'
1515
keywords = [
1616
]
1717
license = {text = 'Apache2'}
1818
classifiers = [
1919
'License :: OSI Approved :: Apache Software License',
2020
'Programming Language :: Python :: 3',
2121
'Programming Language :: Python :: 3 :: Only',
22-
'Programming Language :: Python :: 3.8',
23-
'Programming Language :: Python :: 3.9',
2422
'Programming Language :: Python :: 3.10',
2523
'Programming Language :: Python :: 3.11',
2624
'Programming Language :: Python :: 3.12',
25+
'Programming Language :: Python :: 3.13',
2726
]
2827
dependencies = [
2928
'toml',
@@ -66,7 +65,7 @@ namespaces = false
6665

6766
[tool.ruff]
6867
line-length = 120
69-
target-version = 'py38'
68+
target-version = 'py310'
7069

7170
[tool.ruff.lint]
7271

tests/run_tests.ps1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ cp .pre-commit-win.yaml .pre-commit-win.yaml.bak
8484
git add *.txt *.cpp .pre-commit*.yaml
8585
git commit -m 'Initial commit'
8686
pre-commit run -c .pre-commit-win.yaml --all-files
87-
$ret=$?
87+
$ret=$LASTEXITCODE
8888
mv -Force .pre-commit-win.yaml.bak .pre-commit-win.yaml
8989
rm -Force -Recurse .git
90-
if ($ret -eq 0) {
91-
echo "Pre-commit on tests/cmake_good failed!"
90+
if ($ret -ne 0) {
91+
echo "Pre-commit on tests/cmake_good failed with exit code $ret!"
9292
Exit 1
9393
}
9494
cd ../..
@@ -102,10 +102,10 @@ cp .pre-commit-win.yaml .pre-commit-win.yaml.bak
102102
git add *.txt *.cpp .pre-commit*.yaml
103103
git commit -m 'Initial commit'
104104
pre-commit run -c .pre-commit-win.yaml --all-files
105-
$ret=$?
105+
$ret=$LASTEXITCODE
106106
mv -Force .pre-commit-win.yaml.bak .pre-commit-win.yaml
107107
rm -Force -Recurse .git
108-
if ($ret -eq 1) {
108+
if ($ret -eq 0) {
109109
echo "Pre-commit on tests/cmake_bad unexpectedly passed!"
110110
Exit 1
111111
}

0 commit comments

Comments
 (0)