Skip to content

feat: implement uv-style dependency sorting and multiline formatting#5677

Open
kajal-jotwani wants to merge 9 commits intoprefix-dev:mainfrom
kajal-jotwani:feat/sort-dependencies
Open

feat: implement uv-style dependency sorting and multiline formatting#5677
kajal-jotwani wants to merge 9 commits intoprefix-dev:mainfrom
kajal-jotwani:feat/sort-dependencies

Conversation

@kajal-jotwani
Copy link
Contributor

@kajal-jotwani kajal-jotwani commented Mar 14, 2026

Description

When running pixi add --pypi with multiple packages, dependencies were previously written as inline arrays with inconsistent ordering, which could create unnecessary diffs when removing and re-adding packages.

This PR updates PyPI dependency formatting to follow uv-style behavior:

  • arrays are always written in multiline format (one dependency per line)
  • if the existing list is alphabetically sorted, new dependencies are inserted in order
  • if not, the existing order is preserved and new dependencies are appended

The multiline formatting logic is adapted from uv’s reformat_array_multiline, which preserves inline and trailing comments.

Fixes #5651

How Has This Been Tested?

Added three unit tests covering sorting behavior, multiline formatting, and the remove-and-readd zero-diff case. Snapshot tests were updated accordingly.

AI Disclosure

  • This PR contains AI-generated content.
    • I have tested any AI-generated content in my PR.
    • I take responsibility for any AI-generated content in my PR.

Tools: {e.g., Claude, Codex, GitHub Copilot, ChatGPT, etc.}

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added sufficient tests to cover my changes.
  • I have verified that changes that would impact the JSON schema have been made in schema/model.py.

@kajal-jotwani kajal-jotwani marked this pull request as ready for review March 16, 2026 10:00
@baszalmstra
Copy link
Contributor

Can you add unit tests specifically for reformat_array_multiline? Especially with some edge cases?

@kajal-jotwani
Copy link
Contributor Author

Can you add unit tests specifically for reformat_array_multiline? Especially with some edge cases?

Thanks for the review! I’ve added unit tests for reformat_array_multiline, covering edge cases like empty arrays, idempotency, and preservation of different comment types (own-line, end-of-line, and trailing) and inline comment spacing.

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.

Sort dependencies alphabetically and put them on separate lines in toml

2 participants