Skip to content

Preserve PEP 723 metadata when wrapping Python source notebooks - #2356

Open
hengzhan wants to merge 1 commit into
databricks:mainfrom
hengzhan:fix/workflow-notebook-metadata
Open

hengzhan wants to merge 1 commit into
databricks:mainfrom
hengzhan:fix/workflow-notebook-metadata

Conversation

@hengzhan

@hengzhan hengzhan commented Nov 25, 2026 •

Copy link
Copy Markdown

Changes

Run File as Workflow adds a bootstrap cell to Python source notebooks. If the notebook starts with PEP 723 environment metadata, that metadata ends up inside the first original code cell. When %run follows it, the command is no longer recognized correctly.

For example, this notebook reproduces the issue:

# Databricks notebook source
# /// script
# [tool.databricks.environment]
# environment_version = "5"
# ///
# MAGIC %run ./setup

This fix keeps the metadata just below the notebook header, before the bootstrap code, so %run stays in its own cell. It also preserves the metadata when %pip and Python restart commands are moved to the beginning.

The regression tests cover LF and CRLF line endings, cell rearrangement turned on and off, and notebooks with %pip and Python restart commands.

Tests

  • yarn test passed, including all 11 wrapper tests.
  • Regression tests confirm the generated notebook preserves the environment metadata and keeps %run in its own cell.

@github-actions

Copy link
Copy Markdown
Contributor

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

Trigger:
go/deco-tests-run/vscode

Inputs:

  • PR number: 2356
  • Commit SHA: 774c44245312889a9f64dd106b301042cd760046

Checks will be approved automatically on success.

@hengzhan
hengzhan marked this pull request as ready for review November 25, 2026 11:40

This branch has not been deployed

No deployments
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.

1 participant