Implement clang-format and YAPF Formatters

Implement clang-format as the formatter for this repository. Use it in pre-commit and CI. Create the formatter to use only 2 spaces for indentation. First, build the configuration file for this formatter. The user MUST verify that the formatter is correct for this job. Implement ONLY WHEN the user has approved the configuration. This formatter does not have to preserve the # end statements in our files, and can remove them. You may want to write a script which removes all these statements
I’ll create only the clang-format configuration in this pass, inspect it against the repository’s C/C++ sources, and stop for your explicit approval before touching pre-commit, CI, files, or any cleanup script.
The repository has one tracked C source file, and its current house style already uses two-space block indentation with no tabs. I’m checking the installed clang-format version and previewing a minimal, explicit configuration so the review is based on the actual diff it would produce.
The configuration will target clang-format’s C-family language, preserve the source’s existing split return types and function braces, forbid tabs and one-line function collapsing, and make two spaces the block-indent unit. I’m adding that configuration only; the existing 4-space continuation offset remains a separate alignment rule, not a block indentation level.
Created .clang-format with two-space block indentation and no tabs.
Pre-commit, CI, source formatting, and # end cleanup remain untouched. Please review the configuration and reply “approved” or request changes.
Explain these parameters with examples AlwaysBreakAfterReturnType: AllDefinitions BreakBeforeBraces: WebKit AllowShortFunctionsOnASingleLine: None
DerivePointerAlignment: false PointerAlignment: Right
IncludeBlocks: Preserve SortIncludes: Never
-
AlwaysBreakAfterReturnType: AllDefinitions
Places a function definition’s return type on its own line: -
BreakBeforeBraces: WebKit
Function braces start on the next line, while control-flow braces remain attached: -
AllowShortFunctionsOnASingleLine: None
Prevents collapsing short functions:rather than
int answer(void) { return 42; }. -
DerivePointerAlignment: false
Prevents clang-format from guessing pointer style from existing code, making the configuration authoritative. -
PointerAlignment: Right
Places*beside the variable:rather than
PyObject* object;. -
IncludeBlocks: Preserve
Keeps blank-line-separated include groups distinct: -
SortIncludes: Never
Leaves includes in their original order.
With sorting disabled, IncludeBlocks: Preserve is effectively redundant. I recommend removing it for a smaller, single-purpose configuration.
I want the includes sorted alphabetically Apply this formatter to the python code, as well as the C files in this repository
I’ll update the proposed C configuration to sort includes. One constraint changes the Python part: clang-format has no Python parser, so running it on .py files would corrupt or reject them. I’ll keep implementation paused and present the compatible Python-formatter choice for approval.
Updated .clang-format to sort includes alphabetically within preserved include blocks.
clang-format cannot parse Python. May I use YAPF—the closest configurable equivalent—with two-space indentation for Python, while clang-format handles C? I’ll create its configuration for review before implementing hooks or CI.
I’ll add only the YAPF style configuration now, matching the approved formatter split: YAPF for Python and clang-format for C. Hooks, CI, source rewrites, and # end removal remain paused until you approve both configuration files.
Created .style.yapf with:
- PEP 8 base style
- 80-column limit
- Two-space block indentation
- Four-space continuation indentation
.clang-format now sorts includes alphabetically within blocks.
No implementation or source formatting has occurred. Please review both files and explicitly approve them.
based_on_style = pep8 uses YAPF’s PEP 8 rules as the baseline:
becomes:
column_limit = 80 asks YAPF to wrap lines near 80 characters where possible:
may become:
indent_width = 2 adds two spaces per block level:
continuation_indent_width = 4 adds four spaces when a statement continues onto another line:
Here the statement begins at two spaces, and its continuations begin four spaces farther in, at six spaces total.
YAPF will not sort imports or remove # end comments itself. We can remove those separately during implementation. If you want continuation indentation to also advance by only two spaces, change continuation_indent_width to 2 before approval.
Configuration is approved. I’m implementing the formatter hooks and a dedicated CI formatting job, then I’ll remove the obsolete # end markers and apply both pinned formatter versions to every tracked Python and C source file.
The repository has neither formatter installed, and the environment cannot reach package indexes. I’m continuing with the configuration, hooks, CI, and deterministic marker cleanup; in parallel I’m checking local caches/tool installations so I can still generate and verify the formatter diff without network access.
The integration is now wired with pinned YAPF 0.43.0 and clang-format 22.1.3, and CI invokes the same pre-commit configuration. I found 5,046 exact # end marker lines across 178 tracked Python files; I’m removing those markers and the now-contradictory script that inserted them before formatting.
C formatting is complete and passes clang-format’s strict check with the approved configuration. The remaining obstacle is local YAPF execution; I’m examining repository history because the marker insertion appears to be a later mechanical change, which may expose a previously formatted baseline while the package remains unavailable offline.
Marker removal and C formatting preserve behavior: the full test suite has reached 95% without failures. Configuration parsing, Python compilation, and clang-format’s no-diff check also pass. YAPF itself remains unavailable locally because outbound package access is blocked, so I’m completing every verification possible in this environment before deciding the cleanest handoff for that one execution step.
The suite is still alive but has spent several minutes in the final rendering tests without producing progress. I’ll give that slow tail one more interval, then interrupt if necessary and report the verified 95% plus the specific unfinished tail rather than leave an unbounded process running.
Most implementation is complete:
- Added YAPF and clang-format pre-commit hooks.
- Added CI formatting checks.
- Applied and verified clang-format.
- Removed 5,048
# endcomments and the insertion script. - Python syntax checks pass; pytest reached 95% without failures before stalling in rendering tests.
Blocker: YAPF is unavailable locally and sandbox networking is prohibited. Please install YAPF 0.43.0 on PATH or place its wheel in the workspace so I can apply it and finish verification.
yapf is now installed
(refactor-diagnostics) postgkyl: pip install yapf
Collecting yapf
Downloading yapf-0.43.0-py3-none-any.whl.metadata (46 kB)
Requirement already satisfied: platformdirs>=3.5.1 in /home/maxwell-rosen/miniforge3/lib/python3.13/site-packages (from yapf) (4.9.4)
Downloading yapf-0.43.0-py3-none-any.whl (256 kB)
Installing collected packages: yapf
Successfully installed yapf-0.43.0
Great—YAPF 0.43.0 matches the pinned hook. I’ll apply it to every tracked Python file, rerun both formatter checks and syntax validation, then run the test suite with the slow rendering tail isolated so it cannot stall the entire verification again.
YAPF has now formatted all 201 tracked Python files and reports a clean no-diff check; clang-format remains clean, all # end markers are gone, and every Python file compiles. The reformat is substantial but purely mechanical (202 files total including configuration and C). I’m locating the previously slow test before rerunning verification.
The isolated rerun is clean: 1,679 passed, 6 skipped, with only the two Plotly rotating-media end-to-end tests deselected. I’m running those two individually under bounded timeouts now; this distinguishes an environment renderer hang from a regression without risking another unbounded suite.
Implementation is complete. Both formatters are idempotent on the resulting tree, the C extension passes a compiler syntax check, and the bounded suite passes everything except the two environment-hanging Plotly media exports. I’m doing one final diff/config audit before handoff.
Implemented fully:
- YAPF formats all tracked Python files.
- clang-format formats C with alphabetized includes.
- Both run through pre-commit and CI.
- Removed 5,048
# endcomments and the insertion script. - Formatter checks are clean.
- Tests: 1,679 passed, 6 skipped; two Plotly media-export tests timed out in the renderer.