mirror of
https://github.com/astral-sh/uv.git
synced 2025-08-31 15:57:26 +00:00
Fix Python prerelease sorting (#7884)
## Summary Observed from #7880, `rc3` should be sorted before `rc2`.
This commit is contained in:
parent
c708cc82fa
commit
32ab2a5a95
3 changed files with 272 additions and 260 deletions
|
@ -448,14 +448,26 @@ class PyPyFinder(Finder):
|
|||
def render(downloads: list[PythonDownload]) -> None:
|
||||
"""Render `download-metadata.json`."""
|
||||
|
||||
def prerelease_sort_key(prerelease: str) -> tuple[int, int]:
|
||||
if prerelease.startswith("a"):
|
||||
return 0, int(prerelease[1:])
|
||||
if prerelease.startswith("b"):
|
||||
return 1, int(prerelease[1:])
|
||||
if prerelease.startswith("rc"):
|
||||
return 2, int(prerelease[2:])
|
||||
return 3, 0
|
||||
|
||||
def sort_key(download: PythonDownload) -> tuple:
|
||||
# Sort by implementation, version (latest first), and then by triple.
|
||||
impl_order = [ImplementationName.CPYTHON, ImplementationName.PYPY]
|
||||
prerelease = prerelease_sort_key(download.version.prerelease)
|
||||
return (
|
||||
impl_order.index(download.implementation),
|
||||
-download.version.major,
|
||||
-download.version.minor,
|
||||
-download.version.patch,
|
||||
-prerelease[0],
|
||||
-prerelease[1],
|
||||
download.triple,
|
||||
)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue