Skip to content

01 modernize - #99

Merged
eriknw merged 8 commits into
python-graphblas:mainfrom
eriknw:01-modernize
Nov 20, 2026
Merged

eriknw merged 8 commits into
python-graphblas:mainfrom
eriknw:01-modernize

Conversation

@eriknw

@eriknw eriknw commented Nov 20, 2026

Copy link
Copy Markdown
Member

First step to modernize and begin bringing graphblas-algorithms up to date

The project files date from NetworkX 3.2, and pre-commit no longer runs
to completion on a current interpreter: pyupgrade 3.15 fails under
Python 3.14. Hook pins now track python-graphblas, and the formatting
the new hooks ask for is applied in the same commit.

- Require Python 3.11 (classifiers, black, ruff and pyupgrade targets).
- Declare the license as a PEP 639 expression (setuptools >= 77).
- Drop the networkx.plugins entry point and the graphs'
  __networkx_plugin__ attribute, which NetworkX stopped reading in 3.3;
  networkx.backends, networkx.backend_info and __networkx_backend__
  remain.
- The test extra requires networkx >= 3.6, adds pytest-xdist and drops
  tomli: test_core reads pyproject.toml with tomllib.
- pytest runs with --strict-config, --strict-markers and -ra.
- Move ruff's lint settings under [tool.ruff.lint], and ignore the rules
  its new version adds that this code does not follow.
- New hooks: shellcheck, prettier (README included; the generator's
  markers take prettier's form), actionlint, zizmor, yamllint, schema
  checks for the workflows, and a check for plain ASCII punctuation.
- Current GitHub actions, pinned by commit as zizmor asks; checkouts no
  longer persist credentials, every workflow's token is read-only, and
  Dependabot waits a week before proposing an action's new release. The
  upload to PyPI still uses an API token, so zizmor's trusted-publishing
  audit is waived on that line.
- Add dev-requirements.txt, the pip mirror of environment.yml.
The function list NetworkX reads from _nx_graphblas was kept by hand,
beside a dispatch table that already had a generator. A new
_nx_graphblas/core.py writes it from the Dispatcher and the wrappers'
signatures, and documents each parameter NetworkX's signature lacks
with its live default. The generated get_info() equals the hand-written
one, with the functions in sorted order.

scripts/maketree.py finds the implemented names by scanning nxapi
against NetworkX's registry instead of reading the dispatch table it
writes, so a new wrapper no longer has to be listed by hand first.

`make all` runs both generators, the dispatch table first, since the
backend info is read from it. run_nx_tests.sh drops
NETWORKX_GRAPH_CONVERT, which NetworkX no longer reads.
The README said the package registers a "networkx.plugin" entry point
and that graphs carry `__networkx_plugin__`. NetworkX has dispatched
through the "networkx.backends" group and `__networkx_backend__` since
3.2, and the plugins entry point is gone. Drop the sentence calling
dispatch a new feature of NetworkX 3.0.
The structure checks in test_match_nx.py ran only with
--check-structure, which CI passes, and test_dispatched_funcs_in_nxapi
fails there: the aliases fast_graph_could_be_isomorphic,
faster_graph_could_be_isomorphic and tournament.is_path displace the
real definitions in its map of where each dispatched name lives.
NetworkX 3.6 dispatches none of the three, so they go. The option, its
marker and the root conftest.py that defined it go too, and the
structure checks always run.
Three files are written by generators: the function list and parameter
table in _nx_graphblas/__init__.py, the algorithm tree in README.md and
the dispatch table in interface.py. Nothing noticed when one of them
fell behind the code.

test_autogenerated_code_is_fresh runs both generators against copies in
tmp_path and compares, so a stale checkout fails instead of being
repaired; it skips where scripts/ is not shipped. A second test compares
the committed backend info with the Dispatcher, which also works on an
installed package. rich, which maketree imports, joins the test extra
and the CI install list.

maketree splices its two files itself instead of calling
python-graphblas's private _autogenerate_code, which wrote a file back
unchanged when a marker was missing, so a damaged file compared as
fresh, and took a duplicate marker for a second block. Both generators
now require each marker exactly once. The splice reads and writes
UTF-8, since the README tree is box-drawing characters that Windows'
default code page cannot encode. maketree no longer runs black; its
output is already formatted.

maketree's get_names stops on a public nxapi name that NetworkX does
not dispatch, instead of leaving it out of the generated code while it
stays importable. A module's public names are its __all__, or else the
functions it defines. On the older supported NetworkX this also stops on
a wrapper for a name only the newer one dispatches.

The README test matches whole words: as a substring, degree_centrality
counts as documented by in_degree_centrality. The fixture of
implemented names scans nxapi as the generator does, not the generated
table, and the branch for NetworkX 3.0 and 3.1 goes.

Two tests pin where dispatched names come from: every Dispatcher entry
is an nxapi wrapper, and nxapi.linalg's submodules are its own. Without
__all__ in nxapi/linalg/graphmatrix.py, the star imports replace
nxapi.linalg with the kernel package, and adjacency_matrix dispatches to
the kernel.

dispatcher_functions lives in tests/_dispatched.py, a helper module the
test-naming hook now skips.
Each cell of the Tests matrix ran our tests and then NetworkX's suite
through the backend in one step. The suite does not pass yet, so the
step failed, and fail-fast let the first failing cell cancel the rest:
whether the package installs and passes its own tests was not visible.

The suite moves to a job of its own, one cell on ubuntu with Python
3.13, which still uploads its coverage. Its step may fail and the job
still passes; the next step writes the summary line to the step
summary, with a warning annotation when the suite failed. The step sets
pipefail itself, since the runner adds none to a custom shell and tee
would otherwise decide its status.

In the pytest job:
- fail-fast is off, so one failing cell no longer cancels the others.
- The cells are named "pytest (os, version)", which renames the checks.
- macos-15-intel and ubuntu-24.04-arm join, at Python 3.13.
- setuptools, which test_packages needs, is installed. pytest-mpl,
  which brings matplotlib for NetworkX's drawing tests, moves to the
  NetworkX job.
- The pypy conditionals on the channels go; no cell is pypy.
@codecov

codecov Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.59788% with 31 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.44%. Comparing base (35dbc90) to head (75cd9b6).

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #99      +/-   ##
==========================================
- Coverage   76.82%   74.44%   -2.38%     
==========================================
  Files         118      120       +2     
  Lines        4271     4403     +132     
  Branches      818      727      -91     
==========================================
- Hits         3281     3278       -3     
- Misses        751      877     +126     
- Partials      239      248       +9     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

On Windows, setup-miniconda writes a bash wrapper for mamba that runs
`cmd.exe /C CALL mamba.bat`. Git Bash rewrites `/C` to the path `C:/`,
so cmd.exe opens an interactive prompt, reads end of input and exits 0.
Nothing was installed, and the Windows cells failed later on
`import graphblas`. conda's default solver is libmamba, so calling
conda directly costs nothing.
The backend info and the generator that writes it live in
_nx_graphblas, outside the measured source, so the tests that run the
generator counted for nothing.
@eriknw

eriknw commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

Passing CI! This is a good first step. Merging.

@eriknw
eriknw merged commit 8306216 into python-graphblas:main Nov 20, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant