poetry icon indicating copy to clipboard operation
poetry copied to clipboard

when adding dependencies, insert them at the correct ordering index in the list

Open rafalkrupinski opened this issue 4 years ago • 1 comments

  • [X] I have searched the issues of this repo and believe that this is not a duplicate.
  • [X] I have searched the documentation and believe that my question is not covered.

Feature Request

As a python dev team member I'd like to avoid a merge conflict when two users add a different dependency to the project. Currently all are appended to the end of the dependency list. This causes merge conflict when merging two branches with different dependencies added. A simple solution to minimize this, is to keep the dependency list ordered alphabetically.

Ideally all new projects would use sorted lists by default, but runtime overhead and existing unordered dependency lists should be considered.

  • Add new configuration option: dependencies.sort = false
  • If the above option is true, change poetry add behaviour to sort all dependency lists by pretty_name and use binary search to insert the new dependencies.

Let me know if this is acceptable and I'll start working on a PR.

rafalkrupinski avatar Aug 13 '21 22:08 rafalkrupinski

#3996 got hung up on a couple of items and the contributor gave up. Can we resolve those?

Issue 1: dealing with preexisting comments and preexisting unsorted dep lists

To work around that, maybe we should just have poetry insert lines into a sorted list at the top of [tool.poetry.*.dependencies] and leave any manually curated deps (or deps with comments) at the bottom?

We could also just keep all comments attached to the line below them (as I think @andrei-shabanski was suggesting), but as @br3ndonland mentioned, that might do bad things when comments are used for grouping deps. Personally I think that's fine as poetry already has a system for grouping deps.

Issue 2: configuring it to turn it on/off

@rafalkrupinski has a suggestion above that has dependencies.sort default to false. I'd be happy to have the default be true and put this in a minor release. @radoering also asked for inclusion in poetry init, which sounds like a good plan to me. @abn had opinions so CCing them.

jason-curtis avatar Feb 26 '23 20:02 jason-curtis