Skip to content

Commit 0ef5cc2

Browse files
Switch formatter to ruff in preparation for Universe migration (#1443)
## 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) == foo` → `type(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× `== None` → `is None`, 1× `type(x) != bytes` → `is not bytes`, 1× `== False` → `is False`, 1× `lambda` → `def`. **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.
1 parent 10fdbcc commit 0ef5cc2

96 files changed

Lines changed: 730 additions & 783 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ __pycache__
1010
databricks-sdk-py.iml
1111
.databricks
1212
.coverage
13-
htmlcov
13+
htmlcov
14+
pyrefly.toml

Makefile

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,16 @@ install:
55
uv sync --locked
66

77
fmt:
8-
uv run black databricks tests
9-
uv run autoflake -ri databricks tests
10-
uv run isort databricks tests
8+
uv run ruff format databricks tests
9+
uv run ruff check --fix-only databricks tests
1110

1211
fmte:
13-
uv run black examples
14-
uv run autoflake -ri examples
15-
uv run isort examples
12+
uv run ruff format examples
13+
uv run ruff check --fix-only examples
1614

1715
lint:
18-
uv run pycodestyle databricks
19-
uv run autoflake --check-diff --quiet --recursive databricks
16+
uv run ruff check databricks tests
17+
uv run ruff format --check databricks tests
2018

2119
test:
2220
uv run pytest -m 'not integration and not benchmark' --cov=databricks --cov-report html tests

NEXT_CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@
1414

1515
### Internal Changes
1616

17+
* Switch the formatter and linter from black/isort/autoflake to ruff (format + lint), aligning the SDK formatter with Databricks' internal Python formatting guidelines in preparation for moving the source of truth to a separate internal repository. `make fmt` now runs `ruff format` + `ruff check --fix-only`; `make lint` runs `ruff check` and `ruff format --check` across `databricks` and `tests`. No behavioral changes to the published SDK.
18+
1719
### API Changes

databricks/sdk/__init__.py

Lines changed: 186 additions & 112 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)