Skip to content

fix: fix build_python_functions_file generating malformed source#7381

Open
SinzoL wants to merge 1 commit intomicrosoft:mainfrom
SinzoL:fix/7209-build-python-functions-file-format
Open

fix: fix build_python_functions_file generating malformed source#7381
SinzoL wants to merge 1 commit intomicrosoft:mainfrom
SinzoL:fix/7209-build-python-functions-file-format

Conversation

@SinzoL
Copy link

@SinzoL SinzoL commented Mar 13, 2026

When global_imports is empty, the function produced a leading blank line followed by an extra trailing newline per function. This resulted in source code that fails linting tools and confuses downstream parsing. Rewrite the assembly logic to only emit the import block when there are actual imports, sort imports for deterministic output, use a single join with double newlines for clean separation, and end with exactly one trailing newline (PEP 8). Fixes #7209

When global_imports is empty, the function produced a leading blank
line followed by an extra trailing newline per function. This resulted
in source code that fails linting tools and confuses downstream
parsing.

Rewrite the assembly logic to:
- Only emit the import block when there are actual imports
- Sort imports for deterministic output
- Use a single join with double newlines for clean separation
- End with exactly one trailing newline (PEP 8)

Fixes microsoft#7209
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.

bubuild_python_functions_file produces malformed source code when using @with_requirements with other decorators

1 participant