From ae13e9541bee4ce8fb868493fbaea3a765e50e0a Mon Sep 17 00:00:00 2001 From: Jalin Wang Date: Fri, 3 Apr 2026 14:51:35 +0800 Subject: [PATCH] fix(ci): wrong wheel version on Windows (#308) use first-time setuptools-scm detected version to avoid leftover dir incfluence subsequent wheel version detection --- .github/workflows/build_wheel_on_windows.yml | 47 ++++++++++++-------- pyproject.toml | 8 +++- 2 files changed, 35 insertions(+), 20 deletions(-) diff --git a/.github/workflows/build_wheel_on_windows.yml b/.github/workflows/build_wheel_on_windows.yml index 64978bb..74d17cf 100644 --- a/.github/workflows/build_wheel_on_windows.yml +++ b/.github/workflows/build_wheel_on_windows.yml @@ -65,6 +65,10 @@ jobs: & "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -all -products * -prerelease -format json shell: powershell + - name: Enable git long paths + shell: powershell + run: git config --global core.longpaths true + - name: Checkout code uses: actions/checkout@v6 with: @@ -86,31 +90,33 @@ jobs: with: arch: x64 - - name: Install cibuildwheel - run: | - pip install --upgrade pip - pip install cibuildwheel==3.4.0 - - name: Add Git bin to PATH run: echo "C:\Program Files\Git\usr\bin" >> $env:GITHUB_PATH shell: powershell - - name: Cache built wheels - id: cache-wheels - uses: actions/cache@v4 - with: - path: wheelhouse - key: ${{ runner.os }}-wheels-${{ hashFiles('**/pyproject.toml', '**/setup.py', '**/*.py', '**/*.c', '**/*.cpp') }} + # - name: Cache built wheels + # id: cache-wheels + # uses: actions/cache@v4 + # with: + # path: wheelhouse + # key: ${{ runner.os }}-wheels-${{ hashFiles('**/pyproject.toml', '**/setup.py', '**/*.py', '**/*.c', '**/*.cpp') }} - name: Build wheels using cibuildwheel - if: steps.cache-wheels.outputs.cache-hit != 'true' + # if: steps.cache-wheels.outputs.cache-hit != 'true' shell: powershell -# env: -# CIBW_BUILD_VERBOSITY: 1 -# CIBW_DEBUG_TRACEBACK: 1 -# CIBW_DEBUG_KEEP_CONTAINER: 1 - run: | + # 1. Generate and capture the version from setuptools_scm + pip install --upgrade pip + pip install cibuildwheel==3.4.0 + pip install setuptools-scm>=8.0 + + $SCM_VERSION = python -m setuptools_scm + echo "Detected Version: $SCM_VERSION" + + # 2. Set it as an environment variable for the current shell and subsequent steps + $env:SETUPTOOLS_SCM_PRETEND_VERSION = $SCM_VERSION + + # 3. Run cibuildwheel python -m cibuildwheel --output-dir wheelhouse - name: Install and test wheel @@ -190,6 +196,11 @@ jobs: runs-on: ${{ matrix.platform }} steps: + - name: Set up Python + uses: actions/setup-python@v6 + with: + python-version: ${{ matrix.python-version }} + - name: Smoke test from PyPI shell: powershell env: @@ -217,7 +228,7 @@ jobs: $PSNativeCommandUseErrorActionPreference = $false $found = $false for ($i = 1; $i -le 30; $i++) { - python -m pip install --force-reinstall @indexArgs --dry-run "zvec==$version" 1>$null 2>$null + python -m pip install --force-reinstall @indexArgs --dry-run "zvec==$version" if ($LASTEXITCODE -eq 0) { Write-Host "Version $version is available." $found = $true diff --git a/pyproject.toml b/pyproject.toml index c45b39e..c7125a3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -189,9 +189,13 @@ environment = { CMAKE_GENERATOR = "Unix Makefiles", CMAKE_BUILD_PARALLEL_LEVEL = [tool.cibuildwheel.windows] archs = ["auto64"] -test-command = "cd /d {project} && pytest python/tests -v --tb=short --basetemp=./.pytest_tmp && if exist .pytest_tmp rmdir /s /q .pytest_tmp" +test-command = "cd /d {project} && pytest python/tests -v --tb=short --basetemp=./.pytest_tmp" environment = { CMAKE_GENERATOR = "Ninja" } -config-settings = { build-dir = "build/{wheel_tag}" } +#config-settings = { build-dir = "build/{wheel_tag}" } +#&& if exist .pytest_tmp rmdir /s /q .pytest_tmp" +before-build = [ + "python -c \"import shutil, glob, os; [shutil.rmtree(p, ignore_errors=True) for p in ['build', '.pytest_tmp']];\"" +] ###################################################################################################### # CODE QUALITY & FORMATTING (Ruff)