Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,18 @@ jobs:
with:
fetch-depth: 0
persist-credentials: false
- uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: "3.11"
- uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
# The steps of pre-commit/action, spelled out because its latest release
# (v3.0.1) uses actions/cache@v4, which runs on the deprecated Node.js 20.
- name: Install pre-commit
run: |
python -m pip install pre-commit
python -m pip freeze --local
- uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ~/.cache/pre-commit
key: pre-commit-3|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }}
- name: Run pre-commit
run: pre-commit run --show-diff-on-failure --color=always --all-files
26 changes: 21 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ concurrency:
jobs:
test:
runs-on: ${{ matrix.os }}
# A hung test would otherwise hold the runner for GitHub's default of 6 hours. These
# jobs take a few minutes.
timeout-minutes: 30
defaults:
run:
# -e: a custom shell gets no errexit, so without it a multi-command step
Expand All @@ -29,8 +32,7 @@ jobs:
# os: ["ubuntu-latest"]
# source: ["source"]
# A trailing "t" means the free-threaded (no-GIL) build of that version.
# TODO: add "3.15t" once conda-forge builds cffi and numpy for cp315t.
python-version: ["3.11", "3.12", "3.13", "3.14", "3.14t", "3.15"]
python-version: ["3.11", "3.12", "3.13", "3.14", "3.14t", "3.15", "3.15t"]
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
Expand All @@ -57,16 +59,22 @@ jobs:
cp continuous_integration/environment.yml environment-ci.yml
echo " - python=$pyver" >> environment-ci.yml
echo " - $variant" >> environment-ci.yml
if [[ $PYVER == *t ]]; then
echo " - pytest-run-parallel" >> environment-ci.yml # see "Test"
fi
cat environment-ci.yml
- name: Conda
uses: conda-incubator/setup-miniconda@be893c923ea9cf1cf7cd510fbdde27c7e18cbdcb # v4.1.0
with:
auto-update-conda: true
environment-file: environment-ci.yml
channels: conda-forge,nodefaults
# setup-miniconda deprecated a `nodefaults` channel here in favor of
# conda-remove-defaults (environment.yml keeps it for conda itself).
channels: conda-forge
conda-remove-defaults: true
channel-priority: strict
activate-environment: suitesparse-graphblas
auto-activate-base: false
auto-activate: false
- name: GraphBLAS (from conda-forge)
if: (contains(matrix.source, 'conda-forge'))
run: |
Expand Down Expand Up @@ -98,7 +106,7 @@ jobs:
run: |
# Cython's coverage plugin (see [tool.coverage.run] in pyproject.toml)
# needs coverage's C tracer. Where conda-forge has no compiled build of
# coverage for a Python (3.15, for now), it installs a pure-Python build
# coverage for a Python (3.15t, for now), it installs a pure-Python build
# that lacks the tracer. There, loading the plugin raises ImportError and
# every `coverage run` dies before it runs anything, so run the tests
# directly instead.
Expand All @@ -113,10 +121,18 @@ jobs:
- name: Test
env:
CYTHON_COVERAGE: true
PYVER: ${{ matrix.python-version }}
run: |
pytest -s -k test_print_jit_config
$COV -m pytest
$COV suitesparse_graphblas/tests/test_initialize.py
if [[ $PYVER == *t ]]; then
# Without a GIL, threads run Python code in parallel, so also run each test in 4
# threads at once, 10 times each, to find races (in psg, GraphBLAS, or a test).
# pytest-run-parallel ignores warnings raised in its threads, so this adds to the
# run above rather than replacing it.
pytest --parallel-threads=4 --iterations=10
fi
- name: create_headers.py check
if: (! contains(matrix.os, 'windows'))
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/update_graphblas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
fetch-depth: 0
persist-credentials: false

- uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: "3.11"

Expand All @@ -44,7 +44,7 @@ jobs:
shell: bash

- name: Create Pull Request
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
uses: peter-evans/create-pull-request@3ffccacd46053766916f087ce41d627c0b8cf2d1 # v8.1.3
with:
# See documentation: https://github.com/peter-evans/create-pull-request
# Action behavior: https://github.com/peter-evans/create-pull-request#action-behaviour
Expand Down
24 changes: 21 additions & 3 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ jobs:
build_wheels:
name: Wheels - ${{ matrix.cibw_archs }} ${{ matrix.arch_note}} - ${{ matrix.os }}
runs-on: ${{ matrix.os }}
# A hung test would otherwise hold the runner for GitHub's default of 6 hours. The
# slowest job, a full (release) build on macos-15-intel, has taken up to 35 minutes.
timeout-minutes: 90
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -85,9 +88,16 @@ jobs:
# Linux aarch64 — native ARM runner (no QEMU emulation needed)
- os: ubuntu-24.04-arm
cibw_archs: "auto"
# numpy wheels not available for aarch64 musllinux
# skip musllinux (built in the next job)
cibw_skip: "*musl*"

# Linux aarch64 musllinux, on its own runner for the same reason as x86_64's
- os: ubuntu-24.04-arm
cibw_archs: "auto"
arch_note: "musl"
# skip manylinux (built in the previous job)
cibw_skip: "*many*"

# macOS x86_64 — macos-15-intel is the last Intel macOS runner.
# libomp from Homebrew determines the minimum supported macOS version.
- os: macos-15-intel
Expand Down Expand Up @@ -148,7 +158,7 @@ jobs:
brew fetch --retry libomp && brew reinstall libomp
echo "MACOSX_DEPLOYMENT_TARGET=$(otool -l "$(brew --prefix libomp)/lib/libomp.dylib" | grep minos | awk '{print $2}')" >> "$GITHUB_ENV"

- uses: pypa/cibuildwheel@8c2dcd2e96041a619f5ff03c9638d7941e2553a4 # v4.3.3
- uses: pypa/cibuildwheel@f9b966cfadf4109556cadc5bb39ddb72d0ce664e # v4.3.5
with:
output-dir: wheelhouse
env:
Expand Down Expand Up @@ -178,9 +188,17 @@ jobs:
# finished with GraphBLAS after 30 CPU-minutes; -O2 takes about a minute. emcc
# appends EMCC_CFLAGS to every command, so its -O2 is the one that counts (also for
# compiling GraphBLAS, which is then smaller and no slower).
# --one-caller-inline-max-function-size=1000 keeps wasm-opt from inlining a large
# function into its only caller. Without it, wasm-opt inlined the FactoryKernels
# into the switches that call them, making functions of up to 3.4 MB (GB_AxB_saxpy3,
# GB_add_phase2, GB_AxB_dot3 and others). Chrome's optimizing compiler then used
# 4 to 5 GB of memory on them, and kernels ran unoptimized meanwhile. With it, the
# largest GraphBLAS function is 0.2 MB, a page using GraphBLAS peaks near 1 GB,
# kernels are as fast or faster, and the wheel is about 0.7 MB larger. It is a
# link setting, so it goes in LDFLAGS (in EMCC_CFLAGS, emcc warns at each compile).
CIBW_BEFORE_ALL_PYODIDE: ""
CIBW_BEFORE_BUILD_PYODIDE: bash suitesparse.sh ${{ env.GB_VERSION_REF }}
CIBW_ENVIRONMENT_PYODIDE: SUITESPARSE_EMSCRIPTEN=1 GRAPHBLAS_PREFIX=/tmp/graphblas-wasm GraphBLAS_ROOT=/tmp/graphblas-wasm EMCC_CFLAGS=-O2
CIBW_ENVIRONMENT_PYODIDE: SUITESPARSE_EMSCRIPTEN=1 GRAPHBLAS_PREFIX=/tmp/graphblas-wasm GraphBLAS_ROOT=/tmp/graphblas-wasm EMCC_CFLAGS=-O2 LDFLAGS="-sBINARYEN_EXTRA_PASSES=--one-caller-inline-max-function-size=1000"

CIBW_ENVIRONMENT_PASS_LINUX: SUITESPARSE_FASTEST_BUILD

Expand Down
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ repos:
- id: name-tests-test
args: ["--pytest-test-first"]
- repo: https://github.com/abravalheri/validate-pyproject
rev: '0.26'
rev: 'v0.27'
hooks:
- id: validate-pyproject
name: Validate pyproject.toml
Expand All @@ -54,15 +54,15 @@ repos:
hooks:
- id: black
- repo: https://github.com/PyCQA/flake8
rev: 7.4.1
rev: 7.5.0
hooks:
- id: flake8
args: ["--config=.flake8"]
additional_dependencies: &flake8_dependencies
# These versions need updated manually
- flake8==7.4.1
- flake8==7.5.0
- flake8-comprehensions==3.17.0
- flake8-bugbear==26.9.30
- flake8-bugbear==26.11.9
# - flake8-simplify==0.22.0
- repo: https://github.com/asottile/yesqa
rev: v1.5.0
Expand Down Expand Up @@ -93,11 +93,11 @@ repos:
hooks:
- id: actionlint
- repo: https://github.com/zizmorcore/zizmor-pre-commit
rev: v1.31.1
rev: v1.32.0
hooks:
- id: zizmor
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.38.2
rev: 0.39.0
hooks:
- id: check-dependabot
- id: check-github-workflows
Expand Down
21 changes: 17 additions & 4 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ This script regenerates **`suitesparse_graphblas.h`**, **`suitesparse_graphblas_
and **`source.c`** from an upstream `GraphBLAS.h`. It:

- Copies `GraphBLAS.h` from the install, runs the C preprocessor (using pycparser's
`fake_libc_include`), and parses the result with pycparser.
`fake_libc_include`), and parses the result with pycparser. Use conda-forge's pycparser:
the wheels on PyPI leave `fake_libc_include` out. Pass `--graphblas <path to GraphBLAS.h>`
unless GraphBLAS is installed in `sys.prefix`.
- Emits a cleaned-up header that cffi can `cdef()`, plus a complex-free variant for
platforms (notably MSVC) where `_Complex` types don't work.
- Manually tracks `DEFINES`, `CHAR_DEFINES`, `IGNORE_DEFINES`, and `DEPRECATED` sets.
Expand Down Expand Up @@ -204,9 +206,20 @@ When claiming a buffer from `GxB_*_unload`, use the arena in the returned `handl
(`handling - GrB_DEFAULT`), and never claim one with `handling >= GxB_IS_READONLY`: whoever
loaded it read-only still owns it.

The file is marked `freethreading_compatible=True`. The package does nothing special for
free-threading itself — correctness depends on SuiteSparse:GraphBLAS being thread-safe,
which it is required to be.
The file is marked `freethreading_compatible=True`. Correctness depends on
SuiteSparse:GraphBLAS being thread-safe, which it is required to be. The shared mutable state
in `utils.pyx` is per arena: its allocator functions (`arenas`), NumPy handler struct
(`arena_handlers`) and handler capsule (`_handlers`). `_handler` fills them once, under
`_handlers_lock`, so threads racing an arena's first use share one handler; after that they
are only read.

The free-threaded CI jobs (3.14t and 3.15t in `test.yml`) also run the suite with
pytest-run-parallel, each test in 4 threads at once (`pytest --parallel-threads=4
--iterations=10`), so tests must be thread-safe: keep state per test or per thread, and guard
one-time setup (such as `GxB_arena_init`) with a lock. Mark a test that can't be, because it
changes process-wide state as `doctest` does, with `@pytest.mark.thread_unsafe(reason=...)`;
`conftest.py` registers the marker when the plugin isn't installed. Doctests always run in
one thread.

## Style and tooling

Expand Down
2 changes: 1 addition & 1 deletion GB_VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
10.5.2
10.5.3
2 changes: 1 addition & 1 deletion suitesparse.sh
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ cd "GraphBLAS-${VERSION}/build" || exit
# Disable optimizing some rarely-used types for significantly faster builds and significantly smaller wheel size.
# Also the build with all types enabled sometimes stalls on GitHub Actions. Probably due to exceeded resource limits.
# These can still be used, they'll just have reduced performance (AFAIK similar to UDTs).
# GraphBLAS's own GB_control.h (as of 10.5.2) already disables INT8, INT16, UINT8 and UINT16, so
# GraphBLAS's own GB_control.h (as of 10.5.3) already disables INT8, INT16, UINT8 and UINT16, so
# the types left without FactoryKernels here are those four plus FC32, FC64 and UINT32.
# shellcheck disable=SC2129
# echo "#define GxB_NO_BOOL 1" >> ../Source/GB_control.h #
Expand Down
10 changes: 10 additions & 0 deletions suitesparse_graphblas/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@
_set_numpy_warn_if_no_mem_policy = None


def pytest_configure(config):
# The marker tells pytest-run-parallel (`--parallel-threads`) to run a test in one thread.
# The plugin registers it; without the plugin, an unknown marker fails `--strict-markers`
# and `-W error`.
if not config.pluginmanager.hasplugin("run-parallel"):
config.addinivalue_line(
"markers", "thread_unsafe: run the test in one thread under pytest-run-parallel"
)


@pytest.fixture(scope="session", autouse=True)
def intialize_suitesparse_graphblas():
initialize()
Expand Down
25 changes: 16 additions & 9 deletions suitesparse_graphblas/create_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,8 @@ def visit_Struct(self, node):


def get_ast(filename):
fake_include = os.path.dirname(pycparser.__file__) + "utils/fake_libc_include"
ast = parse_file(filename, cpp_args=f"-I{fake_include}")
return ast
# filename has already been through the preprocessor
return parse_file(filename)


def get_groups(ast):
Expand Down Expand Up @@ -891,13 +890,21 @@ def main():
# Run it through the preprocessor
print(f"Step 2: run preprocessor to create {processed_h}")
include = os.path.join(os.path.dirname(pycparser.__file__), "utils", "fake_libc_include")
command = (
f"gcc -nostdinc -E -I{include} {graphblas_h} "
f"| sed 's/ complex / _Complex /g' > {processed_h}"
if not os.path.isdir(include):
# pycparser's wheels on PyPI leave these headers out; conda-forge's package has them.
raise FileNotFoundError(
f"pycparser's fake libc headers not found: {include}\n"
"Install pycparser from conda-forge, which includes them."
)
# Not a shell pipeline: a failure in the preprocessor must stop us here, or the steps
# below would write empty headers.
res = subprocess.run(
["gcc", "-nostdinc", "-E", f"-I{include}", graphblas_h],
stdout=subprocess.PIPE,
check=True,
)
res = subprocess.run(command, shell=True)
if res.returncode != 0:
raise RuntimeError("Subprocess command failed", res)
with open(processed_h, "wb") as f:
f.write(res.stdout.replace(b" complex ", b" _Complex "))

# Create final header file
print(f"Step 3: parse header file to create {final_h}")
Expand Down
3 changes: 3 additions & 0 deletions suitesparse_graphblas/tests/test_doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
import importlib
import pkgutil

import pytest

from suitesparse_graphblas import api, utils


@pytest.mark.thread_unsafe(reason="doctest patches sys.stdout and linecache process-wide")
def test_run_doctests():
# Every module of the functional API, found rather than listed so none is missed: the
# wheel builds' test command does not collect doctests, so they run only through here
Expand Down
Loading
Loading