Commit 0ef5cc2
authored
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
File tree
- databricks/sdk
- _widgets
- errors
- mixins
- runtime
- service
- tests
- databricks/sdk/service
- generated
- integration
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
| 14 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
9 | | - | |
10 | | - | |
| 8 | + | |
| 9 | + | |
11 | 10 | | |
12 | 11 | | |
13 | | - | |
14 | | - | |
15 | | - | |
| 12 | + | |
| 13 | + | |
16 | 14 | | |
17 | 15 | | |
18 | | - | |
19 | | - | |
| 16 | + | |
| 17 | + | |
20 | 18 | | |
21 | 19 | | |
22 | 20 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
| 18 | + | |
17 | 19 | | |
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments