Skip to content

Import nubots formatter and format code base - #6

Open
jpptm wants to merge 2 commits into
mainfrom
montano/import-nubots-formatter
Open

jpptm wants to merge 2 commits into
mainfrom
montano/import-nubots-formatter

Conversation

@jpptm

@jpptm jpptm commented Sep 13, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

jpptm and others added 2 commits September 13, 2026 11:59
Adds `./b format`, a port of NUbots' tools/format.py, plus the .clang-format and
.cmake-format.py configs it drives. Formatter versions are pinned in pyproject.toml
to the ones NUbots uses (clang-format 14.0.6 — the same LLVM release NUbots builds
into its image — cmakelang 0.6.13, isort 5.13.2, black 24.10.0), so a given file
formats identically in either repo.

The port differs from the original only where NUSim's plumbing forces it:

  * the formatters run on the host out of the uv project environment rather than
    inside the docker image, since ./b here is a stdlib-only host-side dispatcher
  * --check diffs with difflib instead of shelling out to colordiff
  * files are formatted on a thread pool, not a process pool: b.py loads tool
    modules under a name absent from sys.modules, so a forked child cannot unpickle
    the work function. The work is all subprocess calls, so threads lose nothing
  * no licence-header formatter (commented out upstream) and therefore no pygit2
  * no eslint/prettier, as there is no JavaScript in this repo

.cmake-format.py drops NUbots' custom-command declarations and wraps k1sim_role()
instead of nuclear_role(). mujoco/idl_gen/ is excluded from clang-format: it is
fastddsgen output that the build regenerates.

Aligning black/isort with NUbots also lifts the requires-python <3.13 cap, which
only existed to accommodate black 20.8b1.

This commit adds the tooling only; the reformat is the commit that follows.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Pure mechanical output of `./b format --all` using the configs added in the previous
commit. No behavioural change: the sim builds and all six unit tests pass, and
`./b format --check --all` is clean.

Most of the diff is NamespaceIndentation: All, which NUbots' .clang-format sets and
this codebase was not written with.

mujoco/idl_gen/ is untouched — it is generated, and excluded in tools/format.py.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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