Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sorting packages #312

Closed
1 task done
tkossak opened this issue Jul 17, 2018 · 13 comments
Closed
1 task done

sorting packages #312

tkossak opened this issue Jul 17, 2018 · 13 comments
Labels
area/cli Related to the command line kind/feature Feature requests/implementations
Milestone

Comments

@tkossak
Copy link

tkossak commented Jul 17, 2018

  • 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.

@nchammas
Copy link
Contributor

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.

@tkossak
Copy link
Author

tkossak commented Jul 17, 2018

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).

@sdispater
Copy link
Member

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.

@sdispater sdispater added enhancement area/cli Related to the command line labels Jul 17, 2018
@rafalkrupinski
Copy link

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

@sdispater sdispater added this to the 1.0 milestone Mar 2, 2019
@brycedrennan brycedrennan added kind/feature Feature requests/implementations and removed enhancement labels Aug 9, 2019
@n8sty
Copy link
Contributor

n8sty commented Aug 29, 2019

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.

@sdispater sdispater modified the milestones: 1.0, Future Oct 4, 2019
@Vozf
Copy link

Vozf commented Nov 10, 2020

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

@VikashKothary
Copy link

Until this gets implemented, I've been using the toml-sort package:

poetry add -D toml-sort
poetry run toml-sort pyproject.toml --all --in-place

The downside is that it sorts the entire file and not just the dependencies, but that was an acceptable trade-off for me. You should also be careful because it seems to remove comments if they're on a new line by themselves.

@andrei-shabanski
Copy link

andrei-shabanski commented Sep 1, 2022

Since Poetry 1.2 introduces the plugin system, this kind of job can be delegated to plugins. That's what I did

https://pypi.org/project/poetry-plugin-sort/ sorts dependencies every time after running add, remove, or init commands. To install the plugin run:

poetry self add poetry-plugin-sort

Note that it's a beta. Please, let me know how it works if someone will try it

@VikashKothary
Copy link

VikashKothary commented Sep 3, 2022

You didn't link your repository so I did it for you: https://github.com/andrei-shabanski/poetry-plugin-sort.

Also your PyPI link didn't work for me: https://pypi.org/project/poetry-plugin-sort/.

I look forward to checking it out.

@rafalkrupinski
Copy link

@tkossak Does Andrei's plug-in solves the problem? Can the issue be closed?

@tkossak
Copy link
Author

tkossak commented Oct 27, 2022

I don't know if it solves the problem, because I stopped using interactive package searching/additions in poetry. Nowadays I just poetry add PKG and that's it.
As for me we can close this ticket.

@dimbleby
Copy link
Contributor

poetry has shown only 10 results for some years now - 2e579c7 - this should probably be closed

Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/cli Related to the command line kind/feature Feature requests/implementations
Projects
None yet
Development

Successfully merging a pull request may close this issue.