Switch formatter to ruff in preparation for Universe migration#1443
Merged
Conversation
Aligns the public SDK formatter with the Databricks Universe default (`bazel/rules/python/format/ruff.toml`) in preparation for moving the source of truth into Universe. Without this swap, every Universe-side sync would create a permanent formatting diff against the public mirror. - `pyproject.toml`: drop black/isort/autoflake, add ruff>=0.6.0, add `[tool.ruff]` config matching Universe (line-length 120, double quotes, py310 target, lint select E4/E7/E9/F). - `Makefile`: `make fmt` runs `ruff format`; `make lint` runs `ruff check` + `ruff format --check`. - Reformat databricks/ and tests/ in place. Lint cleanup so `make lint` is green under the stricter ruff config: - TYPE_CHECKING blocks for the `"Config"` forward refs in azure.py and credentials_provider.py (F821). - `except:` -> `except Exception:` in _widgets/__init__.py, credentials_provider.py, mixins/files.py (E722). - `type(x) == foo` -> `type(x) is foo` in _base_client.py, _widgets/ipywidgets_utils.py, config.py (E721). - Hoist mid-file `import html, re` to the top of dbutils.py (E402). Per-file ignores for intentional patterns: - `__init__.py`: F401/F403/F405/F811 (public API re-exports). - `databricks/sdk/service/*.py`: F841 (codegen `op_response = self._api.do(...)` pattern). - `databricks/sdk/core.py`: F403/F405 (backwards-compat star imports).
Builds on the prior formatter swap to make `genkit update-sdk` + `make
fmt` produce a lint-green tree. Without these, every regen would
generate an import-reorder diff (no isort active) and surface
codegen-emitted unused imports.
- `Makefile`: `make fmt` now runs `ruff check --fix-only` after `ruff
format` (replaces autoflake's unused-import stripping). `make lint`
scope widened from `databricks` to `databricks tests`.
- `pyproject.toml`: add `"I"` to lint select so imports are kept
sorted; drop F401 from the service ignore (fmt strips them); add
per-file ignores for `errors/overrides.py`, `tests/generated/*.py`,
and `tests/databricks/sdk/service/*.py` to cover codegen-emitted
patterns ruff can't auto-fix (`from X import *`, codegen
`query = {}` initialization).
- Tests: fix 16 pre-existing lint issues that the widened `make lint`
now surfaces. Most are unused locals from tests that rely on a
`@raises` decorator (drop the assignment); 2 `== None` -> `is
None`, 1 `type(x) != bytes` -> `is not bytes`, 1 `== False` ->
`is False`, 1 `lambda` assignment -> `def`.
Regenerate via `genkit update-sdk` against the current Universe master genkit binary so reviewers can see the SDK with the new formatter applied. The OpenAPI spec is unchanged (still 87b666fa172b01444d306112309b6109c096f98b); the diff is pure codegen template evolution between the genkit binary used at commit 10fdbcc ("Update SDK API to 87b666fa...") and today's binary: - Service modules: each gets a fat shared import header (typing extensions, requests, threading, Duration, Timestamp, FieldMask, HostType, Token, OperationTimeout, OperationFailed, _internal helpers). `make fmt` (via `ruff check --fix-only`) strips the unused ones per file, but the format is now one-import-per-line rather than grouped multi-line imports. - API call sites: unconditional `query = {}` initialization before headers. - Generated test files and `errors/overrides.py`: switched from explicit named imports to `from X import *`. - `pyrefly.toml`: new pyrefly type-checker config produced by genkit. `make lint` passes. The next `Update SDK API to <sha>` PR would have landed this regardless; bundling it here lets the formatter migration ship with the new look applied.
`tests/conftest.py` had `from .integration.conftest import restorable_env # type: ignore` to expose the integration-conftest fixture to unit tests under `tests/`. autoflake left it alone, but ruff's F401 auto-fix (now run by `make fmt`) stripped it as unused, breaking `tests/test_dbutils.py::test_dbutils_proxy_overrides`. Restore the import with `# noqa: F401` to mark it explicitly as a side-effect re-export. Add NEXT_CHANGELOG entry for the formatter swap.
7114788 to
663187c
Compare
Remove the comment referring to a specific internal config path. The SDK ruff config stands on its own.
The internal repo runs ruff 0.5.6. Newer ruff (0.6+) has different defaults around blank-line stripping after function definitions, so keeping `ruff>=0.6.0` here would produce files that the internal repo's formatter wants to rewrite. Pin to match exactly. Re-running `make fmt` strips ~30 such blank lines across databricks/ and tests/. No behavior change.
|
If integration tests don't run automatically, an authorized user can run them manually by following the instructions below: Trigger: Inputs:
Checks will be approved automatically on success. |
Divyansh-db
approved these changes
May 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces black/isort/autoflake with ruff (format + lint), aligning the SDK formatter with Databricks' internal Python formatting guidelines. Without this, the upcoming source-of-truth move would create a permanent reformatting diff between this repo and its upstream.
Why
The SDK is moving its source-of-truth into a separate internal repository, with this public repo becoming a downstream mirror published from that location. The internal repo standardizes on ruff for Python formatting; this SDK currently uses black/isort/autoflake. If we don't align before the cutover, every code sync would carry a large permanent reformatting diff.
This PR is a one-shot alignment: same ruff config as the internal standard, same lint select (
E4, E7, E9, F, I), same per-file ignore patterns added where the codegen template's output requires them. Behavior of the published SDK is unchanged.What changed
Interface changes
None.
Behavioral changes
None (pure formatter migration).
Internal changes
pyproject.toml— dropblack,isort,autoflakefrom[dev]; addruff>=0.6.0. Add[tool.ruff]matching the internal standard (line-length 120, double quotes, py310 target). Add lint select["E4", "E7", "E9", "F", "I"]and per-file ignores for:**/__init__.py(F401/F403/F405/F811) — public API re-exports.databricks/sdk/service/*.py(F811/F841) — codegen patterns.databricks/sdk/core.py(F403/F405) — backwards-compat star imports.databricks/sdk/errors/overrides.py(F403/F405) — codegen-emitted star import.tests/generated/*.py(F403/F405),tests/databricks/sdk/service/*.py(F841) — generated transport-layer tests.Makefile:make fmtrunsruff format+ruff check --fix-only(replaces autoflake's unused-import stripping).make lintwidened fromdatabrickstodatabricks tests.Hand-fixed lint issues to support the formatter swap and the widened lint scope:
"Config"forward refs inazure.pyandcredentials_provider.py(F821).except:→except Exception:in_widgets/__init__.py,credentials_provider.py,mixins/files.py.type(x) == foo→type(x) is fooin_base_client.py,_widgets/ipywidgets_utils.py,config.py.dbutils.py.make linttotests/: 11× unused-locals in test functions that rely on a@raisesdecorator (drop the assignment), 2×== None→is None, 1×type(x) != bytes→is not bytes, 1×== False→is False, 1×lambda→def.Codegen regeneration: also includes a
genkit update-sdkrun against the current codegen binary, against the same OpenAPI spec. This is not caused by the formatter swap — it's pre-existing template evolution between the last codegen sync and the current codegen state. Bundled here so reviewers see the end-state with the new formatter applied. Notable shapes:requests,threading,Duration,Timestamp,FieldMask,HostType,Token,OperationTimeout/OperationFailed, more_internalhelpers).make fmt's--fix-onlystrips unused ones per file.query = {}initialization before API call sites.errors/overrides.pyand 4 generated test files switch from explicit named imports tofrom X import *.pyrefly.toml(pyrefly type-checker config) emitted by codegen.How is this tested?
make fmtis idempotent on the committed tree (two back-to-back runs produce zero diff).make lintis green on the committed tree.make fmtvia post_generate) →make lintpasses; remaining diff is template-evolution only, not formatter noise.