-
Notifications
You must be signed in to change notification settings - Fork 964
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
simple/<package_name> sort versions correctly #2574
Conversation
I tested this with |
I will add unit tests if this looks good, I am just pondering how to deal with the remainder of the filename properly (the extension etc.). |
…n, reversed filename in that order. Towards fixing issue pypi#2217.
730f891
to
c10379e
Compare
warehouse/legacy/api/simple.py
Outdated
pkg_resources.parse_version(file.version), | ||
# get same extensions together | ||
file.filename[::-1] | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this needs to sort on file.name
, as this is going to be the same for all files within a project.
Instead of sorting on the reversed filename as a secondary sort, you can use file.packagetype
instead.
At this point, the key function should be short enough that you can just do it inline, e.g.:
files = sorted(
request.db.query(File)
...
.all(),
key=lambda f: (pkg_resources.parse_version(f.version), f.packagetype)
)
@cryvate Apologies that this took so long to review! If you are still able to work on this, and get it merged, we'd be able to send you some PyPI stickers as part of Ernest's PyPI Sticker Challenge. |
89f4a83
to
161e6f5
Compare
@di I made the suggested change, and tried to update one of the tests. I cannot run the tests locally at the moment, so not sure it is actually testing what I've fixed. I'd love some stickers! |
@cryvate Thanks! I think instead of modifying an existing test, it'd be better to add a new test here that would have failed before you made this change. I'm thinking something like: def test_file_sorting(self, db_request):
project = ProjectFactory.create()
releases = [
ReleaseFactory.create(project=project)
for version in ["1.0", "2.0", "10.0"]
]
for release in releases:
FileFactory.create(
release=release,
packagetype="sdist",
filename="{}-{}.tar.gz".format(project.name, release.version),
)
FileFactory.create(
release=release,
packagetype="bdist_wheel",
filename="{}-{}.whl".format(project.name, release.version),
)
files = simple.simple_detail(project, db_request)["files"]
# TODO: make an assertion based on the order of `files` I think the easiest way to make the assertion for that test would be to just look at the order of the filenames for each file. Also, if you want to debug what's wrong with testing environment, feel free to ask questions here. It's a lot faster to be able to run tests locally! |
@di work on this is stalled until the 5th as I do not have internet at the moment, and the testing infrastructure does not seem very happy with that! |
Hi @cryvate, hope you're back online! Are you able to run the tests locally yet? |
I did have a stab at it, but I couldn't get it to work. What's the best way to get feedback on what's going wrong, pypa IRC? |
@cryvate Sure, or |
@cryvate I wanted to check in -- if you are working on this issue and have questions, please feel free to ask them here, in |
I've just pinged @cryvate via email. |
@cryvate letting you know about my comment #2217 (comment) . We're very happy to help you with this issue or with another issue if you're up for it, now or when you have time to help with Warehouse. Thank you! |
warehouse/legacy/api/simple.py
Outdated
.order_by(File.filename) | ||
.all() | ||
.all(), | ||
key=lambda f: (pkg_resources.parse_version(f.version), f.packagetype) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So there is a potential for a problem here, if f.packagetype is None problems occur (is that valid? I can make it happen in the tests but not sure it can happen in a real deployment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And similarly, if f.version is None? Looking at recent changes this happens relatively regularly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File.version
and File.packagetype
will not be None
here, and if they are, we've got bigger problems.
Also, I think I would prefer if we used packaging.version.parse
here instead, from the packaging
package.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be good to go then
…on for sorting in simple detail legacy api
@cryvate is this ready for re-review? |
@brainwane: yes |
It looks like some searches are still returning older versions of packages in certain circumstances. It looks like it might be something related to this comment. This is a search run on And this is the same search run on the branch: |
@lgh2 This issue is about the order of links on the simple index for a project, e.g. https://pypi.org/simple/pip/ The search on |
@cryvate Thank you for this fix and thank you for persisting through all the developer environment troubles you had! Unfortunately I think @ewdurbin is now out of stickers :( (Ernest tell me if I'm wrong.) @cryvate I really appreciate your work on this and would be happy to recommend other things around Warehouse that would benefit from your attention. |
It now sorts based on name, pkg_resource parsed version and reversed filename (keep extensions together). Fixes #2217.
Is there a way to extract the extension of the file cleanly? And the remaining metadata for e.g. wheels? Then we can sort on that instead of the 'hacky' reversed filename.