Skip to content

uv add --script deletes user comments after script-comment-block #13447

@qwerbzuio

Description

@qwerbzuio

Summary

When updating inline script metadata of a python script via uv add --script, user's comments after the script-comment-block are deleted.

Reproducer:

Create python script foo.py with contents:

# /// script
# requires-python = ">=3.13"
# dependencies = [
#     "numpy",
# ]
# ///
#
# Some description

Run uv add --script test.py matplotlib. foo.py:

# /// script
# requires-python = ">=3.13"
# dependencies = [
#     "matplotlib",
#     "numpy",
# ]
# ///

As you can see, # Some description has been deleted by uv, even though it is placed after the closing # /// of the script-block.

Adding an empy line (no leading #) helps to preserve the user-comment, but I believe that uv should not touch anything outside the block-boundaries.

Platform

Windows 11 x86_64

Version

uv 0.7.3 (3c413f7 2025-05-07)

Python version

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions