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

Handle .x in version sorting #6012

Merged
merged 3 commits into from
Jul 31, 2019

Conversation

davidfischer
Copy link
Contributor

  • Handle .x in version sorting (eg. 1.0.x or 2.x). A few projects use this in their branch names like Pallets and Django.
  • Added tests for version sorting

Fixes: #6010

Copy link
Member

@humitos humitos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This solution is good to me. It does not affect anything that it's already working 👍


versions = list(Version.objects.filter(project=self.project))
self.assertEqual(
['latest', 'carrot', 'banana', 'apple'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that this is not a behavior that you changed, but I'd like to sort alphanumeric versions from A to Z instead at some point. Feels more human-readable when you have a many of these.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have any examples of projects that use something like this? I can think of Ubuntu off the top of my head, but that's about it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test-builds, which may not apply as a real project but shows the sorting problem when building alphanumeric branch names

@davidfischer
Copy link
Contributor Author

A side comment that isn't exactly related to this PR is that the sort_versions() function ignores "uncomparable" versions like "latest" and "stable". This is by design it seems but perhaps a comment is warranted. This wasn't immediately clear to be before testing it out. Thoughts on adding a comment?

def sort_versions(version_list):
"""
Take a list of Version models and return a sorted list.
:param version_list: list of Version models
:type version_list: list(readthedocs.builds.models.Version)
:returns: sorted list in descending order (latest version first) of versions
:rtype: list(tupe(readthedocs.builds.models.Version,
packaging.version.Version))
"""
versions = []
for version_obj in version_list:
version_slug = version_obj.verbose_name
comparable_version = parse_version_failsafe(version_slug)
if comparable_version:
versions.append((version_obj, comparable_version))
return list(
sorted(
versions,
key=lambda version_info: version_info[1],
reverse=True,
),
)

@humitos
Copy link
Member

humitos commented Jul 31, 2019

This is by design it seems but perhaps a comment is warranted. This wasn't immediately clear to be before testing it out. Thoughts on adding a comment?

I'm 👍 adding a comment explaining this where you consider necessary.

@davidfischer
Copy link
Contributor Author

I added the comments explaining comparable versions. This is ready to merge, I believe.

Copy link
Member

@ericholscher ericholscher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good change.

@ericholscher
Copy link
Member

I wish this was present in the upstream, but that's a fight for another day :)

@davidfischer davidfischer merged commit 19485e4 into master Jul 31, 2019
@davidfischer davidfischer deleted the davidfischer/handle-x-in-version-sorting branch July 31, 2019 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Versions are sorted by ASCII rather than version or commit date
3 participants