Skip to content

Add isort config and sort imports - #239

Open
john-s-morgan wants to merge 3 commits into
racetimeGG:masterfrom
john-s-morgan:feature/consistency/sort-by-config
Open

Add isort config and sort imports#239
john-s-morgan wants to merge 3 commits into
racetimeGG:masterfrom
john-s-morgan:feature/consistency/sort-by-config

Conversation

@john-s-morgan

@john-s-morgan john-s-morgan commented Jul 10, 2026

Copy link
Copy Markdown

What this is

Adds isort, a tool that keeps import statements in a consistent order; plus a one-time pass applying it across the codebase.

Why bother

Right now import order is freeform, so it drifts. In practice that costs us three small-but-recurring things:

  • Review noise: PRs that add an import often reshuffle nearby lines, and reviewers can't tell the real change from the churn. I hit this while cleaning up Refactor OAuth views and remove PKCE workaround for LiveSplit #231, which is what prompted this PR.
  • Merge conflicts: two branches adding imports to the same file collide for no good reason.
  • Bikeshedding: a tool answers where the import lives in the file, so nobody has to think about it.

None of these are on fire. This is a papercut fix.

What it does not change

  • Zero functional changes. It only reorders/wraps import lines. Every changed file still compiles and behaves identically.
  • It matches the style already dominant in the repo (single-line imports, wrapping long ones vertically). I didn't impose a new aesthetic. I measured what the codebase already does and configured isort to preserve it. I have no strong opinions about any of the settings, and am happy to set them to whatever you'd prefer if different.
  • Generated migrations are skipped, so Django's output is left alone.
  • racetime/views/__init__.py is skipped: its imports are deliberately hand-ordered to pair each view with its OAuth variant (RaceChatPin next to OAuthRaceChatPin). The config respects that instead of flattening it, since we can't auto-sort while preserving that intent.

How it's structured

Two commits, so you can review the decision separately from the churn:

  1. Add isort configuration: just .isort.cfg (~9 lines). This is the only part that's a decision; read this one.
  2. Sort imports with isort: the mechanical result of running the tool. 27 files, all reordering. You can skim or trust it; it's reproducible by running isort ..

What you have to do going forward

Nothing required. If you ever want to keep it tidy, pip install isort && isort . reformats everything; running it twice is a no-op. If you decide you hate it, deleting .isort.cfg reverts to freeform with no other cleanup.

If you love it and want it enforced automatically

Happy to follow up with a CI check (isort --check) and/or a pre-commit hook so it stays consistent without anyone thinking about it. if you'd prefer

Enforce consistent import ordering across the codebase. Uses the Black-compatible
wrapping style (matches the dominant single-line convention while preserving
existing vertical import blocks).

- Skips generated migrations.
- Skips racetime/views/__init__.py, whose imports are hand-ordered to pair each
  view with its OAuth variant.
Apply the isort configuration across the codebase. No functional changes.
@john-s-morgan
john-s-morgan marked this pull request as ready for review July 10, 2026 21:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant