localenv: write [tool.databricks.environment] version on serverless setup-local - #6256
localenv: write [tool.databricks.environment] version on serverless setup-local#6256rugpanov wants to merge 4 commits into
Conversation
…etup-local When `environments setup-local` provisions or regenerates pyproject.toml against a serverless target, write a `[tool.databricks.environment]` section carrying `environment_version` (the resolved serverless version). This lets the same project run interactively, in bundles, and in serverless jobs from one source of truth. The section is env-owned: it is refreshed in place on regeneration (preserving any inline comment and other user keys in the table) via the existing formatting-preserving merge, and appended when absent. Cluster targets leave the version empty, so the section is never written and any existing one is left untouched. DECO-27998 Co-authored-by: Isaac
Co-authored-by: Isaac
…iles Cover the common upgrade path a code review flagged: a pyproject.toml a pre-feature CLI wrote for a serverless target already carries the managed [tool.uv] marker block but no [tool.databricks.environment] section. Assert the section is added without duplicating the marker block, the result is valid TOML, and a second merge is a no-op. Co-authored-by: Isaac
Integration test reportCommit: 5a26e8b
10 interesting tests: 4 RECOVERED, 4 SKIP, 2 flaky
Top 10 slowest tests (at least 2 minutes):
|
| // is preserved when the value is replaced). | ||
| const databricksEnvironmentTable = "[tool.databricks.environment]" | ||
|
|
||
| var environmentVersionRe = regexp.MustCompile(`^(\s*)environment_version\s*=`) |
There was a problem hiding this comment.
Why aren't we using a TOML library to do this merging rather than hand-rolling regexes?
Not a blocker since it seems the rest of this file does the same. This is the first of the merging code I'm reviewing so I'm curious why this approach was taken
|
Reviewed and probed locally (built the branch, ran the package tests, exercised Three things worth addressing. 1. A non-
|
anton-107
left a comment
There was a problem hiding this comment.
Approving. The core is sound — insert / replace-in-place / insert-key / cluster-no-op all behave as documented, output is valid TOML, and idempotency holds including on the pre-feature upgrade path.
One thing I'd like fixed before merge, though it's minor and not a regression: a dotted-key or inline-table spelling of [tool.databricks.environment] makes the merge append a second definition and produces invalid TOML that uv sync then rejects. It's the same pre-existing hazard [tool.uv] already has on main, so I'm not blocking on it — but it's cheap to guard following the existing containsMultilineString/errNoProjectTable "refuse rather than corrupt" precedent.
The stale-version-after-cluster-switch behavior and the --constraints-only carve-out are decisions I'd like stated explicitly (in code comments / PR description) rather than left implicit, but they're not blockers. Details in my comment above.
- Warn when a cluster run finds a stale [tool.databricks.environment] environment_version left over from an earlier serverless run (W_STALE_ENVIRONMENT_VERSION); the section is not managed for cluster targets, so the value would otherwise silently misdescribe the target. - Document why --constraints-only still records environment_version: it reflects the resolved compute target, not a managed dependency like databricks-connect. - Deduplicate the "v"-prefix stripping so Label() reuses ServerlessEnvironmentVersion(). - Tests reference the regionDatabricksEnvironment constant, and add an acceptance test covering the stale-version warning on a cluster target. Co-authored-by: Isaac
Summary
When
databricks environments setup-localprovisions or regeneratespyproject.tomlagainst a serverless target, it now writes a[tool.databricks.environment]section carrying the resolved serverlessenvironment_version:This lets the same project run interactively, in bundles, and in serverless jobs from one source of truth. It pairs with the VS Code side (DECO-27997), which reads this section as a serverless-version source.
Details
--serverless-version, a serverless--job-task, or a serverless bundle target). Cluster targets leave the version empty, so the section is never written and any existing one is left untouched (a no-op).environment_versionis refreshed in place on regeneration — preserving the line's indentation, any inline comment, and other user keys in the table — inserted when the table exists without it, and the whole table appended when absent. The merge stays idempotent.RenderFreshPyprojectemits the section for serverless targets.Testing
libs/localenv/merge_test.gocover insert/replace/insert-key/cluster-no-op and greenfield rendering, all asserting valid TOML and idempotency.acceptance/localenvgoldens; cluster-target acceptance tests are unchanged, confirming the no-op.DECO-27998