-
Notifications
You must be signed in to change notification settings - Fork 2
Code Formatting
FindHao edited this page Aug 31, 2025
·
1 revision
This project uses a simple, script-driven formatting workflow:
- C/C++/CUDA files are formatted with clang-format.
- Python uses a three-step pipeline: usort (imports) → ruff (lint autofix) → black (code style).
- Directories scanned (if present):
src
,include
,tests
,tutorial
,.ci
. - File patterns for C/C++/CUDA:
*.h
,*.hpp
,*.cpp
,*.cu
,*.cuh
.
- clang-format (required for C/C++/CUDA)
- Debian/Ubuntu:
sudo apt install clang-format
- Fedora/CentOS:
sudo dnf install clang-tools-extra
- macOS (Homebrew):
brew install clang-format
- Debian/Ubuntu:
- Python tools (for Python files):
usort
,ruff
,black
- Install:
pip install usort ruff black
- Install:
If a tool is missing, format.sh
prints a clear message and exits non‑zero for “check”.
From the repo root:
./format.sh check
- Runs clang-format in dry-run mode with
--Werror
and checks Python withusort/ruff/black
(no changes). - Exits with non-zero if any file would change or Python checks fail.
./format.sh format
- Applies clang-format in-place to all matched C/C++/CUDA files and lists changed files.
- Runs Python formatting:
usort format .
→ruff check . --fix
→black .
.
Notes 📝:
- The script only processes directories that actually exist.
- Third-party content is not included unless it lives under the scanned directories.
- clang-format style is whatever your local
clang-format
resolves to (no custom config in this repo unless you add one).
- Run
./format.sh format
before committing. - If adding new source folders or file types, update
DIRECTORIES_TO_SCAN
orFILE_PATTERNS
insideformat.sh
.