Skip to content

Sorting dependencies in pyproject.toml does not work as expected #10076

@paduszyk

Description

@paduszyk

Related issues

Relates to #6203.

Setup

  • uv 0.5.11 (Homebrew 2024-12-20)
  • Python 3.13
  • macOS Sequoia 15.1.1

Observed behavior

When adding a series of dependencies with uv add:

uv add ruff
uv add pytest
uv add pytest-mock
uv add pytest-randomly

this is what I get in my pyproject.toml:

[project]
# ...
dependencies = [
    "pytest-mock>=3.14.0",
    "pytest>=8.3.4",
    "ruff>=0.8.4",
    "pytest-randomly>=3.16.0",
]

The list of dependencies is updated as follows:

  1. uv add ruff: ruff is added.
  2. uv add pytest: pytest is inserted before ruff.
  3. uv add pytest-mock: pytest-mock is inserted before pytest.
  4. uv add pytest-randomly: pytest-randomly is appended as the last item.

So, sorting is broken at point 3.

Expected behavior

Since uv should sort the dependencies alphabetically (see #6388), I would rather expect:

[project]
# ...
dependencies = [
    "pytest>=8.3.4",
    "pytest-mock>=3.14.0",
    "pytest-randomly>=3.16.0",
    "ruff>=0.8.4",
]

or, assuming that >= are taken into account in sorting:

[project]
# ...
dependencies = [
    "pytest-mock>=3.14.0",
    "pytest-randomly>=3.16.0",
    "pytest>=8.3.4",
    "ruff>=0.8.4",
]

I believe that the first options seems to be more intuitive. In fact, by "sorting" dependencies I would rather think of sorting dependency names, not its specifiers.

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