Skip to content

uv does not respect position of comments in pyproject.toml #8343

Closed
@notatallshaw

Description

@notatallshaw

uv 0.4.24

Maybe this is already reported but I couldn't find it.

Steps to reproduce:

1, uv init temp
2. cd temp
3. uv add requests
4. uv add whenever~=0.6.9
5. Edit project.dependencies in pyproject.toml from:

dependencies = [
    "requests>=2.32.3",
    "whenever~=0.6.9",
]

To:

dependencies = [
    "requests>=2.32.3", # Should not expect to be updated frequently
    "whenever~=0.6.9", # Pinned to 0.6 due to API not yet being stable
]
  1. uv add uv zope
  2. Check project.dependencies in pyproject.toml:

Actual output:

dependencies = [
    "requests>=2.32.3",
    "uv>=0.4.24",
    # Should not expect to be updated frequently
    "whenever~=0.6.9",
    "zope>=5.11",
     # Pinned to 0.6 due to API not yet being stable
]

Expected output:

dependencies = [
    "requests>=2.32.3", # Should not expect to be updated frequently
    "uv>=0.4.24",
    "whenever~=0.6.9", # Pinned to 0.6 due to API not yet being stable
    "zope>=5.11", 
]

Context:

I often leave comments in my pyproject.toml to explain why a particular dependency is pinned or given an upper bound.

I appreciate that comments are a hard problem when reading and writing toml, and there will always be edge cases where the user needs to manually update them (e.g. a requirement is removed), but I don't think this example is an edge case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedContribution especially encouraged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions