Standardise section-header comment banners
Project description
sectionise
Standardise section-header comment banners across a codebase to one canonical
style. Runs as a pre-commit hook or a CLI, and is configured from
pyproject.toml (with flag overrides).
A section header is a comment styled as a banner: a title framed by a run of
fill characters. Real code accumulates many variants; sectionise detects them
and rewrites each to the same shape.
What it standardises
| Variant | Example in |
|---|---|
| Single-line, framed both sides | # ------- Loading models ------- |
| Single-line, filled one side | # Ancillary functions ---------- |
| Unicode fill (em/en dash, box rules) | # ——— Loading models ——— |
| Three-line box | a rule line, a title comment, a rule line |
All of them normalise to the configured style, for example the single-line form:
# ---------------------------- Loading models -----------------------------
Detection is conservative: only full-line comments whose content is framed by a
fill run of at least min_run characters are touched. Ordinary comments,
trailing comments, and commented-out code (# print("=== run ===")) are left
alone. Title-less rules (# --------) are ignored unless dividers is enabled.
A title too long to fit the chosen style is reported as an error suggesting a
shorter title or the multi-line box style, rather than being silently
overflowed.
Installation
pip install sectionise
# or: uv add sectionise (add to a project)
# or: uvx sectionise ... (run without installing)
Use as a pre-commit hook
- repo: https://github.com/MitchellNeedham/sectionise
rev: 0.1.0
hooks:
- id: sectionise
It fixes in place and fails the commit if it changed anything (re-stage and
commit again), the same way ruff-format behaves.
Use as a CLI
sectionise path/to/file.py # fix in place
sectionise --check path/to/file.py # report only, no writes
Configuration
Settings resolve with the precedence flags > [tool.sectionise] > defaults.
Put shared settings in each repo's pyproject.toml:
[tool.sectionise]
width = 88
style = "single" # or "box"
fill = "-"
detect_chars = "-=*_~#—–─═"
min_run = 3
require_both_sides = false
dividers = false
# max_title = 60 # optional hard cap on title length
| Setting | Flag | Default | Meaning |
|---|---|---|---|
width |
--width |
88 |
Target total line length. |
style |
--style |
single |
Output form: single line or 3-line box. |
fill |
--fill |
- |
Output fill character. |
detect_chars |
--detect-chars |
-=*_~#—–─═ |
Characters recognised as fill in input. |
min_run |
--min-run |
3 |
Minimum fill-run length to count as a banner side. |
require_both_sides |
--require-both-sides |
false |
Only treat both-sided comments as banners. |
dividers |
--dividers |
false |
Also standardise title-less rules. |
max_title |
--max-title |
none | Hard cap on title length, on top of the width fit. |
Development
uv sync
uv run pytest
uv run ruff check
Publishing
Releases go to PyPI on a version tag.
-
Set the token once. In the GitHub repo, add a repository secret named
PYPI_API_TOKENholding a PyPI API token (Settings > Secrets and variables > Actions). -
Release. Tag a version and push it; the publish workflow builds and uploads:
git tag 0.1.0 git push origin 0.1.0
The version comes from the tag via
hatch-vcs, so the tag is the single source of truth.
To publish from your machine instead, copy .env.example to .env, paste your
token, and run:
set -a && source .env && set +a
uv build && uv publish dist/*
License
MIT. See LICENSE.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sectionise-0.1.1.tar.gz.
File metadata
- Download URL: sectionise-0.1.1.tar.gz
- Upload date:
- Size: 21.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.31 {"installer":{"name":"uv","version":"0.11.31","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c25f4db4b5420dff57fa619b0d4a1d54d1e9efdec5782202e75425cac01169b0
|
|
| MD5 |
9111583fb039720abd9270cdd1d5f128
|
|
| BLAKE2b-256 |
9015a46f875d78e5eed34229e0c86b0037e6e3d6f3073b3a997b8bc446a4be8f
|
File details
Details for the file sectionise-0.1.1-py3-none-any.whl.
File metadata
- Download URL: sectionise-0.1.1-py3-none-any.whl
- Upload date:
- Size: 10.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.31 {"installer":{"name":"uv","version":"0.11.31","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d9c97c25c5170a2335b284b00d77606faa8f1ec71af4e0524dc2fd66cebfbfc4
|
|
| MD5 |
0ddec69665acb2b6cd3f16eaa6f7ed56
|
|
| BLAKE2b-256 |
13728cd491662f119830ac65ffa8fc3ae71c95caa57bfd88c50132b9980c0d55
|