Skip to content

Commit 523290c

Browse files
janniklasroseIsaac
andauthored
Remove unused imports before sorting in pydabs-codegen (#7375)
## Why `./task pydabs-codegen` fixes the generated code with a single `ruff check --fix`. In that run the unused-import removal (F401) and the import sort (I001) overlap, and ruff defers whichever comes second to the next iteration. Which one runs first depends on the neighbouring statements: a whole-statement deletion swallows its newline, so the fix for the statement right after it waits a round, and by then the sort runs first. A long import sorted while it still carries its unused names is wrapped with a trailing comma. The trim keeps the comma, and isort's `split-on-trailing-comma` plus the formatter's magic trailing comma then keep it multi-line for good. The output is deterministic for a given input, but not local: adding one import to a package can rewrap unrelated imports in the same file. #7366 shows the effect, with `depends_on` imports flipping between one line and multi-line across packages for reasons unrelated to that change. ## Changes - `pydabs-codegen` runs `ruff check --fix --select F401` on its own before the existing full fix and format steps, so wrapping depends only on the final line. - Regenerated models: 32 files collapse imports that were wrapped this way. No other line changes. ## Tests - Running the task a second time produces no further changes. - `./task lint-python`, `ruff format --check`, the pydabs test suite (530 tests) and pyright pass locally. This pull request and its description were written by Isaac. Co-authored-by: Isaac <no-reply@databricks.com>
1 parent 7adc80d commit 523290c

33 files changed

Lines changed: 44 additions & 144 deletions

File tree

‎python/Taskfile.yml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ tasks:
9191
- cd codegen && uv run --frozen -m codegen.main --output ..
9292
# Generated code is fixed and formatted by the global ruff (see ../ruff.toml).
9393
# `uv tool run`, not `uvx`: the SDK bumper runs this with only `uv` installed.
94+
#
95+
# Unused imports (F401) are removed in a pass of their own first. In a single
96+
# `check --fix` the F401 and I001 (import sort) fixes overlap, and the sort can
97+
# run before a statement is trimmed: a long import then gets wrapped with a
98+
# trailing comma that survives the trim and is never folded back. Which
99+
# statements that hits depends on their neighbours, so adding one import could
100+
# rewrap unrelated ones. With F401 first, wrapping depends only on the final line.
101+
- uv tool run ruff@0.15.17 check --fix --select F401 databricks databricks_tests || true
94102
- uv tool run ruff@0.15.17 check --fix databricks databricks_tests || true
95103
- uv tool run ruff@0.15.17 format
96104

‎python/databricks/bundles/alerts/_models/alert.py‎

Lines changed: 1 addition & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎python/databricks/bundles/apps/_models/app.py‎

Lines changed: 1 addition & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎python/databricks/bundles/apps/_models/lifecycle_with_started.py‎

Lines changed: 1 addition & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎python/databricks/bundles/catalogs/_models/catalog.py‎

Lines changed: 1 addition & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎python/databricks/bundles/clusters/_models/cluster.py‎

Lines changed: 1 addition & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎python/databricks/bundles/clusters/_models/lifecycle_with_started.py‎

Lines changed: 1 addition & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎python/databricks/bundles/dashboards/_models/dashboard.py‎

Lines changed: 1 addition & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎python/databricks/bundles/dashboards/_models/lifecycle.py‎

Lines changed: 1 addition & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎python/databricks/bundles/experiments/_models/lifecycle.py‎

Lines changed: 1 addition & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)