Skip to content

Switch formatter to ruff in preparation for Universe migration#1443

Merged
hectorcast-db merged 6 commits into
mainfrom
hectorcastejon/ruff-formatter-migration
May 26, 2026
Merged

Switch formatter to ruff in preparation for Universe migration#1443
hectorcast-db merged 6 commits into
mainfrom
hectorcastejon/ruff-formatter-migration

Conversation

@hectorcast-db

@hectorcast-db hectorcast-db commented May 26, 2026

Copy link
Copy Markdown
Contributor

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 — drop black, isort, autoflake from [dev]; add ruff>=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 fmt runs ruff format + ruff check --fix-only (replaces autoflake's unused-import stripping).
  • make lint widened from databricks to databricks tests.

Hand-fixed lint issues to support the formatter swap and the widened lint scope:

  • 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.
  • type(x) == footype(x) is foo in _base_client.py, _widgets/ipywidgets_utils.py, config.py.
  • Hoist mid-file imports to top of dbutils.py.
  • 16 pre-existing test-code issues surfaced by widening make lint to tests/: 11× unused-locals in test functions that rely on a @raises decorator (drop the assignment), 2× == Noneis None, 1× type(x) != bytesis not bytes, 1× == Falseis False, 1× lambdadef.

Codegen regeneration: also includes a genkit update-sdk run 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:

  • Each service module gets a wider shared import header (typing extensions, requests, threading, Duration, Timestamp, FieldMask, HostType, Token, OperationTimeout/OperationFailed, more _internal helpers). make fmt's --fix-only strips unused ones per file.
  • Imports are now one-per-line (codegen template change), where previously black/isort grouped them.
  • Unconditional query = {} initialization before API call sites.
  • errors/overrides.py and 4 generated test files switch from explicit named imports to from X import *.
  • New pyrefly.toml (pyrefly type-checker config) emitted by codegen.

How is this tested?

  • make fmt is idempotent on the committed tree (two back-to-back runs produce zero diff).
  • make lint is green on the committed tree.
  • Full regen loop verified: clean checkout → codegen regen (which runs make fmt via post_generate) → make lint passes; remaining diff is template-evolution only, not formatter noise.

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.
@hectorcast-db hectorcast-db force-pushed the hectorcastejon/ruff-formatter-migration branch from 7114788 to 663187c Compare May 26, 2026 08:38
@hectorcast-db hectorcast-db requested a review from Divyansh-db May 26, 2026 08:38
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.
@github-actions

Copy link
Copy Markdown

If integration tests don't run automatically, an authorized user can run them manually by following the instructions below:

Trigger:
go/deco-tests-run/sdk-py

Inputs:

  • PR number: 1443
  • Commit SHA: 0c636dedf652a775f5a5d6183272dc3c041472e0

Checks will be approved automatically on success.

@hectorcast-db hectorcast-db added this pull request to the merge queue May 26, 2026
@hectorcast-db hectorcast-db removed this pull request from the merge queue due to a manual request May 26, 2026
@hectorcast-db hectorcast-db added this pull request to the merge queue May 26, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks May 26, 2026
@hectorcast-db hectorcast-db added this pull request to the merge queue May 26, 2026
Merged via the queue into main with commit 0ef5cc2 May 26, 2026
14 checks passed
@hectorcast-db hectorcast-db deleted the hectorcastejon/ruff-formatter-migration branch May 26, 2026 13:23
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.

2 participants