From f8b0cec21bd8481addf44b502b621f53198cfd44 Mon Sep 17 00:00:00 2001 From: Ludovic Henry Date: Mon, 7 Sep 2026 14:31:48 +0200 Subject: [PATCH 1/3] runstats: add build-runstats.yml for riscv64 wheels Mirrors upstream's own release.yml cibuildwheel build (CIBW_BEFORE_BUILD: pip install cython, test with pytest + benchmark.py), matrixed over cp312/cp313/cp314/cp314t for manylinux_riscv64. Adds an explicit compiled- extension assertion ahead of the test suite since setup.py silently falls back to a pure-Python wheel on any Cython/build failure. --- .github/workflows/build-runstats.yml | 82 ++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 .github/workflows/build-runstats.yml diff --git a/.github/workflows/build-runstats.yml b/.github/workflows/build-runstats.yml new file mode 100644 index 000000000..fe9166bc8 --- /dev/null +++ b/.github/workflows/build-runstats.yml @@ -0,0 +1,82 @@ +# SPDX-FileCopyrightText: 2026 The RISE Project +# SPDX-License-Identifier: MIT +--- +# Based on the `builds` job of +# https://github.com/grantjenks/python-runstats/blob/v2.0.0/.github/workflows/release.yml +name: Build runstats wheels (riscv64) + +on: + workflow_dispatch: + inputs: + version: + description: 'runstats version to build (git tag without leading v, e.g. 2.0.0)' + required: true + default: '2.0.0' + pull_request: + paths: + - '.github/workflows/build-runstats.yml' + +concurrency: + group: ${{ github.workflow }}-${{ inputs.version || '2.0.0' }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +permissions: + contents: read # to fetch code (actions/checkout) + +env: + RUNSTATS_VERSION: ${{ inputs.version || '2.0.0' }} + MANYLINUX_RISCV64_IMAGE: quay.io/pypa/manylinux_2_39_riscv64 + +jobs: + setup: + uses: $/.github/workflows/_setup.yml + + build_wheels: + needs: [setup] + name: Build runstats ${{ inputs.version || '2.0.0' }} ${{ matrix.python }}-manylinux_riscv64 + runs-on: ubuntu-24.04-riscv + strategy: + fail-fast: false + matrix: + python: ["cp312", "cp313", "cp314", "cp314t"] + + steps: + - name: Checkout runstats v${{ env.RUNSTATS_VERSION }} + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + repository: grantjenks/python-runstats + ref: v${{ env.RUNSTATS_VERSION }} + persist-credentials: false + + - name: Build wheels + uses: pypa/cibuildwheel@1828c10ab37f080699c7b81cea34097c684a7074 # v4.2.0 + with: + output-dir: wheelhouse/ + only: ${{ matrix.python }}-manylinux_riscv64 + env: + CIBW_MANYLINUX_RISCV64_IMAGE: ${{ env.MANYLINUX_RISCV64_IMAGE }} + CIBW_BEFORE_BUILD: pip install cython + CIBW_TEST_REQUIRES: pytest pytest-cov pytest-xdist + # setup.py falls back to a pure-Python wheel if cythonize/build_ext raises + # (bare try/except around the Extension build) -- assert the compiled + # extension actually loaded before trusting the test suite (gotcha 91). + CIBW_TEST_COMMAND: >- + python -c "from runstats import _core; assert _core.__file__.endswith('.so'), _core.__file__" + && python -m pytest {project}/tests + && python {project}/tests/benchmark.py + + - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: runstats-${{ env.RUNSTATS_VERSION }}-${{ matrix.python }}-manylinux_riscv64 + path: wheelhouse/*.whl + if-no-files-found: error + + publish: + name: Publish runstats ${{ inputs.version || '2.0.0' }} + needs: [setup, build_wheels] + permissions: + contents: write + pull-requests: write + uses: $/.github/workflows/_publish-wheel.yml + with: + artifact-pattern: runstats-${{ inputs.version || '2.0.0' }}-*-manylinux_riscv64 From 0b8d42abe2877576487c4016fa8219e11edb6243 Mon Sep 17 00:00:00 2001 From: Ludovic Henry Date: Mon, 7 Sep 2026 14:43:30 +0200 Subject: [PATCH 2/3] runstats: build without isolation so cython reaches setup.py setup.py has no [build-system] table, so pypa/build's default isolated venv never sees CIBW_BEFORE_BUILD's cython install and setup.py's bare try/except falls back to a pure-Python wheel, which cibuildwheel then rejects (gotcha 57). --- .github/workflows/build-runstats.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-runstats.yml b/.github/workflows/build-runstats.yml index fe9166bc8..35e39b108 100644 --- a/.github/workflows/build-runstats.yml +++ b/.github/workflows/build-runstats.yml @@ -55,7 +55,11 @@ jobs: only: ${{ matrix.python }}-manylinux_riscv64 env: CIBW_MANYLINUX_RISCV64_IMAGE: ${{ env.MANYLINUX_RISCV64_IMAGE }} - CIBW_BEFORE_BUILD: pip install cython + # setup.py has no [build-system] table, so pypa/build's default isolated + # venv never sees CIBW_BEFORE_BUILD's cython install and silently falls + # back to a pure-Python wheel (CLAUDE.md gotcha 57). + CIBW_BEFORE_BUILD: pip install cython setuptools + CIBW_BUILD_FRONTEND: "pip; args: --no-build-isolation" CIBW_TEST_REQUIRES: pytest pytest-cov pytest-xdist # setup.py falls back to a pure-Python wheel if cythonize/build_ext raises # (bare try/except around the Extension build) -- assert the compiled From 88a4d8924129276eeed77092e4ac86a38ffcde3c Mon Sep 17 00:00:00 2001 From: Ludovic Henry Date: Mon, 7 Sep 2026 15:03:40 +0200 Subject: [PATCH 3/3] runstats: patch Statistics.__rmul__ and fix test staging CI showed two real failures beyond the earlier build-isolation fix: Cython 3.x never wires the compiled Statistics type's __rmul__ (the "__rmul__ = __mul__" alias only adds a dict entry, it does not retroactively fill the nb_multiply slot), so "2 * stats" raised TypeError; and running pytest against {project}/tests let the checkout's own runstats/ package shadow the installed wheel under tox.ini's discovered config, which also pulled in a --cov-fail-under=100 gate unrelated to the port. Patches the __rmul__ definition and stages just tests/ into an empty cwd instead. --- .github/workflows/build-runstats.yml | 23 +++++++++-- ...istics.__rmul__-explicitly-instead-o.patch | 38 +++++++++++++++++++ 2 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 patches/runstats/2.0.0/0001-core-define-Statistics.__rmul__-explicitly-instead-o.patch diff --git a/.github/workflows/build-runstats.yml b/.github/workflows/build-runstats.yml index 35e39b108..6096a0df7 100644 --- a/.github/workflows/build-runstats.yml +++ b/.github/workflows/build-runstats.yml @@ -15,6 +15,7 @@ on: pull_request: paths: - '.github/workflows/build-runstats.yml' + - 'patches/runstats/**' concurrency: group: ${{ github.workflow }}-${{ inputs.version || '2.0.0' }}-${{ github.head_ref || github.run_id }} @@ -48,6 +49,15 @@ jobs: ref: v${{ env.RUNSTATS_VERSION }} persist-credentials: false + - name: Checkout python-wheels + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + path: python-wheels + persist-credentials: false + + - name: Patch runstats source + run: git apply python-wheels/patches/runstats/${{ env.RUNSTATS_VERSION }}/*.patch + - name: Build wheels uses: pypa/cibuildwheel@1828c10ab37f080699c7b81cea34097c684a7074 # v4.2.0 with: @@ -60,14 +70,19 @@ jobs: # back to a pure-Python wheel (CLAUDE.md gotcha 57). CIBW_BEFORE_BUILD: pip install cython setuptools CIBW_BUILD_FRONTEND: "pip; args: --no-build-isolation" - CIBW_TEST_REQUIRES: pytest pytest-cov pytest-xdist + CIBW_TEST_REQUIRES: pytest + # test/__init__.py exists, so build-from-checkout's own runstats/ would + # shadow the installed wheel under pytest's default import mode; stage + # only tests/ into an empty cwd instead (gotcha 25). Also sidesteps + # tox.ini's --cov-fail-under=100, which measures unrelated dev checks. + CIBW_TEST_SOURCES: tests # setup.py falls back to a pure-Python wheel if cythonize/build_ext raises # (bare try/except around the Extension build) -- assert the compiled # extension actually loaded before trusting the test suite (gotcha 91). CIBW_TEST_COMMAND: >- - python -c "from runstats import _core; assert _core.__file__.endswith('.so'), _core.__file__" - && python -m pytest {project}/tests - && python {project}/tests/benchmark.py + python -c "import runstats._core; assert runstats._core.__file__.endswith('.so'), runstats._core.__file__" + && python -m pytest tests + && python tests/benchmark.py - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 with: diff --git a/patches/runstats/2.0.0/0001-core-define-Statistics.__rmul__-explicitly-instead-o.patch b/patches/runstats/2.0.0/0001-core-define-Statistics.__rmul__-explicitly-instead-o.patch new file mode 100644 index 000000000..5d6c2635e --- /dev/null +++ b/patches/runstats/2.0.0/0001-core-define-Statistics.__rmul__-explicitly-instead-o.patch @@ -0,0 +1,38 @@ +From 05bc58febe93abc362e2204aaa7d4504d2bc24a8 Mon Sep 17 00:00:00 2001 +From: Ludovic Henry +Date: Mon, 7 Sep 2026 14:56:43 +0200 +Subject: [PATCH] core: define Statistics.__rmul__ explicitly instead of + aliasing __mul__ + +Cython 3.x compiles cdef class special methods from the textual "def" it +sees; the "__rmul__ = __mul__" alias only adds a dict entry after the +class body runs, it does not retroactively wire the type's nb_multiply +slot to also try the reflected method, so "2 * stats" raises TypeError +on the compiled _core.Statistics while the pure-Python core.Statistics +(an ordinary class, where CPython's own slot machinery checks __dict__ +dynamically) still supports it. Affects any build against a modern +Cython, independent of architecture. + +Upstream-Status: To upstream [not yet submitted; RISE's python-wheels port policy disallows opening issues/PRs against third-party repos] +--- + runstats/core.py | 4 +++- + 1 file changed, 3 insertions(+), 1 deletion(-) + +diff --git a/runstats/core.py b/runstats/core.py +index bc9f14e..3af5275 100644 +--- a/runstats/core.py ++++ b/runstats/core.py +@@ -241,7 +241,9 @@ class Statistics: + # https://stackoverflow.com/q/33218006/232571 + return that._mul(self) # pragma: no cover + +- __rmul__ = __mul__ ++ def __rmul__(self, that): ++ """Multiply by a scalar to change Statistics weighting.""" ++ return self.__mul__(that) + + def _imul(self, that): + """Multiply by a scalar to change Statistics weighting in-place.""" +-- +2.50.1 (Apple Git-155) +