4

Context

We use poetry to track dependencies in our python project. We commit poetry.lock into git.

I added recently one package with poetry add. But then in diff I observed that poetry changed order to fields in the whole file generating a huge useless diff:

diff

It goes like this for the whole lock file. Its main drawback is generation of conflicts when trying to merge.

Question

How can I force poetry to use existing order of fields? Or what other solution do you propose to this problem?

hans
  • 1,043
  • 12
  • 33
  • 1
    Did you update poetry in between (or using 2 different versions to generate the 2 lock files)? – sinoroc Jan 08 '21 at 09:05
  • 1
    Potentially relevant: [maybe don't commit the lockfile](https://stackoverflow.com/questions/61037557/should-i-commit-lock-file-changes-separately-what-should-i-write-for-the-commi) – Arne Jan 08 '21 at 15:40
  • @Arne is right, unless your project is an application. My rule is: if it's not an application (i.e. it's a library, plug-in, etc.), then don't commit the lock file, or the frozen `requirements.txt`, or pinned dependencis in general; if it's an application then it could make sense to commit the lock file. – sinoroc Jan 08 '21 at 17:14
  • The project is an application. – hans Sep 15 '21 at 08:30

2 Answers2

2

Solution

Use the same poetry version by all team members. Apparently poetry does not version... poetry ;)

hans
  • 1,043
  • 12
  • 33
  • 1
    My assumption, is that from now on and with all following poetry releases, the content of the lock file should be expected to be stable (no change in the ordering). If not then it should probably raised as a bug. Meaning there should be no need to version poetry itself. -- Some poetry versioning might still be in the works though, and if I am not mistaken the lock files themselves are already versioned . -- Feel free to ask here for confirmation from the maintainers: https://github.com/python-poetry/poetry/discussions – sinoroc Jan 08 '21 at 17:39
1

Poetry diffs are often hard to make sense of. To keep track of what your dependencies are I have written a Github Action that will post a nicely readable summary of all changes to your pull requests. Maybe you will find this helpful: https://github.com/marketplace/actions/diff-poetry-lock

Nils Borrmann
  • 245
  • 2
  • 7