Skip to content

uv add also performs unprompted (and unrelated) toml formatting #16719

@neutrinoceros

Description

@neutrinoceros

Summary

This is one ((or possibly two) minor) bug(s) I frequently encounter when working on astropy, reproduced here with a minimal example.
Both of these are small sources of friction in my workflow, but I hit them frequently enough that I decided to report them any way.

Starting from the following pyproject.toml contents:

[project]
name = "test-uv"
version = "0.1.0"
requires-python = ">=3.10"
dependencies = [
    "attrs>=25.4.0",     # perhaps weirdly comment formatted comment
]

[build-system]
requires = ["uv_build>=0.9.9,<0.10.0"]
build-backend = "uv_build"

[tool.ruff]
lint.extend-select = []
exclude = []
lint.ignore = []

And using, for instance

uv add pytest

produces the following patch

diff --git a/pyproject.toml b/pyproject.toml
index a2b9bad..82d55d1 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -3,7 +3,8 @@ name = "test-uv"
 version = "0.1.0"
 requires-python = ">=3.10"
 dependencies = [
-    "attrs>=25.4.0",     # perhaps weirdly comment formatted comment
+    "attrs>=25.4.0", # perhaps weirdly comment formatted comment
+    "pytest>=9.0.1",
 ]
 
 [build-system]
@@ -12,5 +13,5 @@ build-backend = "uv_build"
 
 [tool.ruff]
 lint.extend-select = []
-exclude = []
 lint.ignore = []
+exclude = []

The problems should be evident, but let's list them anyway:

  • a comment from an unrelated (albeit adjadent) line is moved
  • a completely unrelated table (here, tool.ruff) is re-formatted

At least no actual data is lost, but having larger than strictly needed footprints means that I can't just commit the result of a uv add invoke, and must resort to manual editing to only commit the bits I want.

Platform

Darwin 24.6.0 arm64

Version

uv 0.9.9 (4fac4cb 2025-11-12)

Python version

Python 3.14.0 (shouldn't be relevant though)

Metadata

Metadata

Assignees

No one assigned

    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