Skip to content

build: ruff, Dependabot and a PR labeler - #33

Merged
JesperDramsch merged 12 commits into
mainfrom
stage2/tooling
Oct 12, 2026
Merged

JesperDramsch merged 12 commits into
mainfrom
stage2/tooling

Conversation

@JesperDramsch

@JesperDramsch JesperDramsch commented Oct 12, 2026 •

Copy link
Copy Markdown
Owner

Stage 2, PR 4 of 4. ruff for linting and formatting, Dependabot, a PR labeler, and the useful parts of the sync bot's #25.

What changes

  • ruff is configured in pyproject.toml with line length 88, matching the existing code. It runs from pre-commit, and CI's lint job uses ruff check and ruff format --check instead of the flake8 critical check.

  • Lint fixes. ruff check --fix and ruff format each have their own commit. Before them:

    • a test commit pins the behaviour the fixes touch;
    • complexnn.__all__ declares the package namespace;
    • dead code ruff cannot fix safely is removed by hand.

    The two style commits come before the commits that enforce linting, so every commit from there on passes the lint job it introduces.

  • Dependabot checks GitHub Actions and pip monthly, grouped per ecosystem. The pip entry opens no PRs while the requirements are bare lower bounds; the comment in dependabot.yml explains this.

  • Labeler labels PRs by the files they change.

About #25

#25 syncs 38 files from JesperDramsch/github-files. Taken as is, it would replace the new publish.yml (trusted publishing), test_python.yml, pyproject.toml and README, bring back requirements.txt, and reformat the sources. This PR ports only the parts that help: the Dependabot, labeler and ruff configuration. Closing #25 afterwards still leaves the sync bot, which would reopen it. That needs a change on the github-files side, excluding this repository's customised files from the sync.

Verification

On the branch, rebuilt on main after #30, #31 and #32:

Environment Result
TensorFlow 2.21, Keras 3.15 81 passed, 1 expected failure, 404 subtests
TensorFlow 2.15.1, Keras 2 80 passed, 2 skipped, 404 subtests
TensorFlow 2.21 + tf-keras 80 passed, 2 skipped, 404 subtests
  • pre-commit passes all six hooks, including ruff check and ruff format.
  • ruff check . is clean.
  • The docs build with -W passes.
  • Every commit from style: apply ruff format on passes the lint job.

Merge notes

The branch was rebuilt on the current main instead of merged, so the history was force-pushed:

The other commits are the same changes as before.

Use a line length of 88, which the code already follows, and take the
target version (3.11) from requires-python.

Select E, W, F, I, UP and B explicitly. ruff 0.17 enables about 400
rules when nothing is selected, and that default set changes between
releases, so an explicit list keeps the result stable when ruff is
updated.

Ignore E501 only: ruff format wraps code at 88 columns, and the long
lines it leaves are prose in strings and comments.
These tests pass on the current code and must keep passing after the
ruff clean-up:

- the public names of the complexnn package and of
  `from complexnn import *`, including the fft and utils submodules
- ComplexBN and ComplexLayerNorm reject an input of unknown rank with
  ValueError
- ComplexDense output, computed with numpy; the layer multiplies by
  the conjugate of its kernel, unlike ComplexConv
- ComplexConv1D/2D with spectral_parametrization=True raise
  NotImplementedError, from the ifft stubs in conv.py
ruff reported every re-export in complexnn/__init__.py as an unused
import (F401). List them in __all__ instead, which also documents the
public API.

__all__ keeps `from complexnn import *` exactly as it was, so it
includes the fft and utils submodules. fft was only loaded as a side
effect of an import in conv.py that the next commit removes, so import
both submodules explicitly here.
- conv.py imported fft, fft2, ifft and ifft2 from .fft but used none of
  them: the module defines its own ifft and ifft2 stubs, which shadow
  the imports (F401, F811). The stubs stay, so spectral
  parametrisation still raises NotImplementedError.
- ComplexBatchNormalization.build and ComplexLayerNorm.build computed
  `ndim = len(input_shape)` and never used it (F841). For an input of
  unknown rank, len() raised ValueError; the layer's own check for an
  undefined channel dimension now raises ValueError instead.
- ComplexDense.call sliced the input into real and imaginary parts and
  never used the slices (F841). InputSpec(ndim=2) already guarantees
  that the slicing could not fail, so the output is unchanged.

The tests added earlier cover each of these paths.
conv_utils, the helper module that replaced TensorFlow's private copy, is a submodule like utils and fft, so it is imported and listed with them instead of appearing as a side effect of importing conv.
Add the ruff-check (with --fix) and ruff-format hooks from
astral-sh/ruff-pre-commit v0.17.0 after the existing read-only hooks,
which stay as they were. Both hooks read the settings in
pyproject.toml. The lint hook runs first, as the ruff-pre-commit
README asks when fixes are enabled.

pre-commit.ci already runs this file on the repository, so it will
now also apply ruff fixes to pull requests.
The lint job ran flake8 for syntax errors and undefined names only.
Run `ruff check` and `ruff format --check --diff` instead. Both use the
settings in pyproject.toml, and ruff check reports findings as GitHub
annotations.

The job reads the ruff version from the ruff-pre-commit rev in
.pre-commit-config.yaml, so CI and the hooks cannot drift apart when
pre-commit.ci updates the pin. A comment next to the rev says so. The
step fails if it cannot find the version.
Adapted from the github-files template that #25 would add. Both
ecosystems update monthly instead of daily, with one grouped pull
request per ecosystem, which suits a library that only needs to keep
working.

The pip entry watches pyproject.toml and docs/requirements.txt with
versioning-strategy increase-if-necessary, so Dependabot never raises
the tensorflow>=2.15 lower bound that Keras 2 users depend on.

The GitHub Actions entry will also propose replacing the unsupported
github/codeql-action@v2 in codeql.yml (only v3 and v4 are
supported).
Take .github/labeler.yml and .github/workflows/labeler.yml unchanged
from JesperDramsch/github-files, as #25 would. Keeping them identical
to the template lets the github-files "label sync" group keep
updating this repository without overwriting anything specific to it.

The workflow runs actions/labeler v7.0.0 on pull_request_target with
pull-requests: write and never checks out the pull request's code.

actions/labeler v7 only understands changed-files, head-branch and
base-branch, so the template's title and body rules for the "breaking"
label are logged as unknown and that label is never applied. That
needs fixing in the template, not here.
@JesperDramsch
JesperDramsch merged commit 6dddec3 into main Oct 12, 2026
9 checks passed
@JesperDramsch
JesperDramsch deleted the stage2/tooling branch October 12, 2026 19:02
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