Skip to content

chore: replace black with ruff format - #766

Merged
axellpadilla merged 2 commits into
dbt-msft:masterfrom
joshmarkovic:jm/ruff-format
Jul 27, 2026
Merged

chore: replace black with ruff format#766
axellpadilla merged 2 commits into
dbt-msft:masterfrom
joshmarkovic:jm/ruff-format

Conversation

@joshmarkovic

Copy link
Copy Markdown
Contributor

Summary

Closes #711. This finishes what #707 started. That PR moved linting to Ruff but left black in place as the formatter. This PR swaps black for ruff format, so one tool and one config block now cover both jobs.

The two black hooks are gone. In their place are two ruff-format hooks inside the astral-sh/ruff-pre-commit block we already have, matching the pattern of the existing ruff-check hooks: one that fixes on commit, one manual alias named ruff-format-check that runs --check --diff.

No new configuration. ruff format reads line-length = 99 and target-version = "py311" from the [tool.ruff] block that #707 added.

Why

  • One toolchain. After chore: consolidate isort, flake8, pycln and absolufy-imports into ruff #707 we were running two formatters' worth of tooling for one job. Now it is a single Rust binary, a single version pin, and a single config block for lint and format together.
  • Fewer dependencies. Ruff is a self-contained binary. black pulls in click, mypy-extensions, packaging, pathspec, platformdirs, and pytokens. Dropping it removes one more consumer of pathspec, the package behind the override-dependencies workaround in pyproject.toml. That workaround still has to stay, but this is one less thing depending on it.
  • Speed. Warm --check over dbt/ and tests/ is roughly 0.06s for ruff format against 0.27s for black. Small in absolute terms, but it adds up across pre-commit and CI.
  • Low risk. Ruff targets better than 99.9% black compatibility, which is why the diff below is as small as it is.

What changed in the code

Twelve files, all cosmetic:

  • dbt/adapters/sqlserver/sqlserver_relation.py. Two implicit f-string concatenations get joined onto one line now that they fit in 99 columns. Same string either way.
  • .github/scripts/verify_version.py. Same thing, one joined concatenation. This one was not in the issue write-up, which only measured dbt/ and tests/. Pre-commit runs over every tracked Python file, so it turned up.
  • Ten files under tests/functional/. A blank line removed after a class header, assert cond, (msg) reflowed, decorator arguments wrapped, and f"{ limit }" normalised to f"{limit}". Whitespace inside f-string braces is not part of the output, so that last one is a no-op at runtime.

make black becomes make format. make test checks formatting through ruff-format-check.

The reformat commit is listed in .git-blame-ignore-revs, alongside the two entries already there. GitHub's blame view honours that file automatically. Worth keeping the two commits separate on merge, since a squash would leave the recorded SHA pointing at nothing. Git tolerates an unresolvable entry silently, so nothing breaks either way, but the entry would stop doing its job.

Verification

  • pre-commit run --all-files passes every hook: ruff check, ruff format, mypy, yamllint, and the pre-commit-hooks set.
  • mypy 2.1.0 clean on 17 source files.
  • Unit tests: 303 passed.
  • Functional tests not run locally, they need a live SQL Server. The test edits are formatting only.

Trade-offs

  • One-time blame churn on twelve files, ten of them tests. Handled by the .git-blame-ignore-revs entry.
  • Diverges from dbt-labs/dbt-adapters, which still uses black. Given how close ruff's output is, this should not matter in practice.
  • The manual hook alias is named ruff-format-check, not black-check. Anyone with a local script or muscle memory for make black will need to switch to make format.

Checklist

  • pre-commit run --all-files passes
  • Unit tests pass (303)
  • Reformat is cosmetic only, no behaviour change
  • Reformat commit recorded in .git-blame-ignore-revs

@joshmarkovic
joshmarkovic marked this pull request as ready for review July 27, 2026 02:36
Completes the toolchain consolidation started in dbt-msft#707, which moved
linting to Ruff. The two black hooks are replaced by ruff-format hooks
in the existing astral-sh/ruff-pre-commit block, so lint and format
share one repo, one version pin, and one [tool.ruff] config block.

No new configuration: ruff format reads line-length and target-version
from pyproject.toml.

Makefile: the black target becomes format; the test target checks
formatting with ruff-format-check.

Reformats 12 files. All changes are cosmetic: joined implicit string
concatenations that now fit in 99 columns, assert message reflow,
decorator argument wrapping, and a blank line after a class header.

Closes dbt-msft#711
Adds the previous commit to .git-blame-ignore-revs so the cosmetic
reformat does not shadow the real authors of those lines. Both
git blame --ignore-revs-file and GitHub's blame view honour the file.
@axellpadilla
axellpadilla merged commit e2864bf into dbt-msft:master Jul 27, 2026
15 checks passed
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.

Phase 2: replace black with ruff format

2 participants