Poetry: sorting packages

Created on 17 Jul 2018  路  6Comments  路  Source: python-poetry/poetry

  • [x] I have searched the issues of this repo and believe that this is not a duplicate.

Issue

When I use 'poetry init' and get to the step for searching packages, it looks like huge mess: https://imgur.com/a/WA9CcnJ
Maybe we can get this list sorted alphabetically? Or/except maybe display packages that are most likely what I look for (because the name is exactly what i typed) on the bottom, so I don't have to scroll the list in search for its number.

CLI Feature

Most helpful comment

I'd sort dependencies alphabetically even in pyproject.toml, I find that helps with merging branches if they both have new entries added

All 6 comments

I found this to be a minor issue with poetry init, too. One easy improvement that could be made would be to always rank any exact match at the top.

Further improvements are certainly possible (perhaps Poetry could somehow leverage the search result rankings returned by https://pypi.org/), but just placing exact matches at the top would be a nice improvement by itself.

Not at the top - at the bottom (like https://github.com/Jguer/yay is doing) so we don't have to scroll for best matches but see them instantly where the cursor is (on the bottom that is).

I agree that it is a usability issue. The idea of putting the more relevant packages at the bottom seems a good improvement to start with.

I'd sort dependencies alphabetically even in pyproject.toml, I find that helps with merging branches if they both have new entries added

I took a crack at trying to fix this to learn a bit more about Poetry's guts and contribute to a tool that's made my work a bit easier. I think I may have discovered another issue that relates to specifying packages interactively, and is potentially solved by sorting.

When I go through a poetry init flow in an empty directory and specify either Django or django I can't actually get either one picked up by https://github.com/sdispater/poetry/blob/f4803e91bca440e6f4af6ad54e396d01c024a76f/poetry/console/commands/init.py#L189-L193. I believe this happens because the choice method of cleo.Command only allows what's returned in the array of choices to be selected from. And, the array of responses when using either of those search terms doesn't include [dD]jango. Digging more, I tried using xmlrpc.client.ServerProxy to query PyPi by xmlrpc.client.ServerProxy("https://pypi.python.org/pypi").search({'name': 'django'}, "or")[0] which returned (what I'm looking for)

{'name': 'Django',
 'summary': 'A high-level Python Web framework that encourages rapid development and clean, pragmatic design.',
 'version': '2.2.4',
 '_pypi_ordering': False}

So, I think @nchammas 's suggestion above about using the search result ordering from PyPi potentially solves this problem. For reference, I'm using the latest version of master https://github.com/sdispater/poetry/tree/f4803e91bca440e6f4af6ad54e396d01c024a76f. I'm happy to try and throw a fix together assuming it's not already in the works.

I also believe that alphabetical storage is the best choice as it is done by npm
For example when I do

poetry remove some-package
poetry add some-package

It deletes the entry of some package from pyproject.toml and adds it in the end. I would expect the pyproject to stay the same

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ulope picture ulope  路  3Comments

probablykasper picture probablykasper  路  3Comments

jbarlow83 picture jbarlow83  路  3Comments

AWegnerGitHub picture AWegnerGitHub  路  3Comments

jackemuk picture jackemuk  路  3Comments