mirror of
https://github.com/astral-sh/uv.git
synced 2025-08-04 02:48:17 +00:00
Prefer optimized builds for freethreaded Python downloads (#8196)
Addresses report in https://github.com/astral-sh/uv/issues/8194
This commit is contained in:
parent
689611417b
commit
b697cee3e1
3 changed files with 42 additions and 23 deletions
|
@ -151,8 +151,8 @@
|
|||
"minor": 13,
|
||||
"patch": 0,
|
||||
"prerelease": "",
|
||||
"url": "https://github.com/indygreg/python-build-standalone/releases/download/20241008/cpython-3.13.0%2B20241008-aarch64-apple-darwin-freethreaded%2Bdebug-full.tar.zst",
|
||||
"sha256": "4ba7f477c56af4f057ca40535aa6907662b7206e3b8b39971d0a507b1c955e44",
|
||||
"url": "https://github.com/indygreg/python-build-standalone/releases/download/20241008/cpython-3.13.0%2B20241008-aarch64-apple-darwin-freethreaded%2Bpgo%2Blto-full.tar.zst",
|
||||
"sha256": "8cc1586c4ee730bb33b7e6d39f1b6388f895075fadb1771e3c27b0561abb9242",
|
||||
"variant": "freethreaded"
|
||||
},
|
||||
"cpython-3.13.0+freethreaded-darwin-x86_64-none": {
|
||||
|
@ -164,8 +164,8 @@
|
|||
"minor": 13,
|
||||
"patch": 0,
|
||||
"prerelease": "",
|
||||
"url": "https://github.com/indygreg/python-build-standalone/releases/download/20241008/cpython-3.13.0%2B20241008-x86_64-apple-darwin-freethreaded%2Bdebug-full.tar.zst",
|
||||
"sha256": "b72b7df7cd22a4e7462dbe95633c5ca61caab41237d68e0ff89e9774cd4985e7",
|
||||
"url": "https://github.com/indygreg/python-build-standalone/releases/download/20241008/cpython-3.13.0%2B20241008-x86_64-apple-darwin-freethreaded%2Bpgo%2Blto-full.tar.zst",
|
||||
"sha256": "117528b68096379b1303faee1f4f9e32ef3d255207ec92fb063f1bd0b942549d",
|
||||
"variant": "freethreaded"
|
||||
},
|
||||
"cpython-3.13.0+freethreaded-linux-aarch64-gnu": {
|
||||
|
@ -242,8 +242,8 @@
|
|||
"minor": 13,
|
||||
"patch": 0,
|
||||
"prerelease": "",
|
||||
"url": "https://github.com/indygreg/python-build-standalone/releases/download/20241008/cpython-3.13.0%2B20241008-x86_64-unknown-linux-gnu-freethreaded%2Bdebug-full.tar.zst",
|
||||
"sha256": "2b46a0f38711cfcdffab90f69ea1372288bd6dcb0f9676b765babb491d42ce06",
|
||||
"url": "https://github.com/indygreg/python-build-standalone/releases/download/20241008/cpython-3.13.0%2B20241008-x86_64-unknown-linux-gnu-freethreaded%2Bpgo%2Blto-full.tar.zst",
|
||||
"sha256": "00a159a64640ce614bdac064b270a9854d86d40d1d8387a822daf1fe0881e64b",
|
||||
"variant": "freethreaded"
|
||||
},
|
||||
"cpython-3.13.0+freethreaded-windows-i686-none": {
|
||||
|
|
|
@ -50,7 +50,7 @@ import json
|
|||
import logging
|
||||
import os
|
||||
import re
|
||||
from dataclasses import dataclass
|
||||
from dataclasses import dataclass, field
|
||||
from enum import StrEnum
|
||||
from pathlib import Path
|
||||
from typing import Generator, Iterable, NamedTuple, Self
|
||||
|
@ -120,6 +120,7 @@ class PythonDownload:
|
|||
filename: str
|
||||
url: str
|
||||
sha256: str | None = None
|
||||
build_options: list[str] = field(default_factory=list)
|
||||
variant: Variant | None = None
|
||||
|
||||
def key(self) -> str:
|
||||
|
@ -211,14 +212,15 @@ class CPythonFinder(Finder):
|
|||
download
|
||||
)
|
||||
|
||||
# Collapse CPython variants to a single URL flavor per triple and variant
|
||||
# Collapse CPython variants to a single flavor per triple and variant
|
||||
downloads = []
|
||||
for version_downloads in downloads_by_version.values():
|
||||
selected: dict[
|
||||
tuple[PlatformTriple, Variant | None], tuple[PythonDownload, int]
|
||||
tuple[PlatformTriple, Variant | None],
|
||||
tuple[PythonDownload, tuple[int, int]],
|
||||
] = {}
|
||||
for download in version_downloads:
|
||||
priority = self._get_flavor_priority(download.flavor)
|
||||
priority = self._get_priority(download)
|
||||
existing = selected.get((download.triple, download.variant))
|
||||
if existing:
|
||||
existing_download, existing_priority = existing
|
||||
|
@ -301,10 +303,10 @@ class CPythonFinder(Finder):
|
|||
|
||||
version, _date, triple, build_options, flavor = match.groups()
|
||||
|
||||
variants = build_options.split("+") if build_options else []
|
||||
build_options = build_options.split("+") if build_options else []
|
||||
variant: Variant | None
|
||||
for variant in Variant:
|
||||
if variant in variants:
|
||||
if variant in build_options:
|
||||
break
|
||||
else:
|
||||
variant = None
|
||||
|
@ -322,6 +324,7 @@ class CPythonFinder(Finder):
|
|||
implementation=self.implementation,
|
||||
filename=filename,
|
||||
url=url,
|
||||
build_options=build_options,
|
||||
variant=variant,
|
||||
)
|
||||
|
||||
|
@ -355,13 +358,29 @@ class CPythonFinder(Finder):
|
|||
def _normalize_os(self, os: str) -> str:
|
||||
return os
|
||||
|
||||
def _get_flavor_priority(self, flavor: str) -> int:
|
||||
"""Returns the priority of a flavor. Lower is better."""
|
||||
def _get_priority(self, download: PythonDownload) -> tuple[int, int]:
|
||||
"""
|
||||
Returns the priority of a download, a lower score is better.
|
||||
"""
|
||||
flavor_priority = self._flavor_priority(download.flavor)
|
||||
build_option_priority = self._build_option_priority(download.build_options)
|
||||
return (flavor_priority, build_option_priority)
|
||||
|
||||
def _flavor_priority(self, flavor: str) -> int:
|
||||
try:
|
||||
pref = self.FLAVOR_PREFERENCES.index(flavor)
|
||||
priority = self.FLAVOR_PREFERENCES.index(flavor)
|
||||
except ValueError:
|
||||
pref = len(self.FLAVOR_PREFERENCES) + 1
|
||||
return pref
|
||||
priority = len(self.FLAVOR_PREFERENCES) + 1
|
||||
return priority
|
||||
|
||||
def _build_option_priority(self, build_options: list[str]) -> int:
|
||||
# Prefer optimized builds
|
||||
return -1 * sum(
|
||||
(
|
||||
"lgo" in build_options,
|
||||
"pgo" in build_options,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
class PyPyFinder(Finder):
|
||||
|
|
|
@ -196,8 +196,8 @@ pub(crate) const PYTHON_DOWNLOADS: &[ManagedPythonDownload] = &[
|
|||
variant: PythonVariant::Freethreaded
|
||||
|
||||
},
|
||||
url: "https://github.com/indygreg/python-build-standalone/releases/download/20241008/cpython-3.13.0%2B20241008-aarch64-apple-darwin-freethreaded%2Bdebug-full.tar.zst",
|
||||
sha256: Some("4ba7f477c56af4f057ca40535aa6907662b7206e3b8b39971d0a507b1c955e44")
|
||||
url: "https://github.com/indygreg/python-build-standalone/releases/download/20241008/cpython-3.13.0%2B20241008-aarch64-apple-darwin-freethreaded%2Bpgo%2Blto-full.tar.zst",
|
||||
sha256: Some("8cc1586c4ee730bb33b7e6d39f1b6388f895075fadb1771e3c27b0561abb9242")
|
||||
},
|
||||
ManagedPythonDownload {
|
||||
key: PythonInstallationKey {
|
||||
|
@ -212,8 +212,8 @@ pub(crate) const PYTHON_DOWNLOADS: &[ManagedPythonDownload] = &[
|
|||
variant: PythonVariant::Freethreaded
|
||||
|
||||
},
|
||||
url: "https://github.com/indygreg/python-build-standalone/releases/download/20241008/cpython-3.13.0%2B20241008-x86_64-apple-darwin-freethreaded%2Bdebug-full.tar.zst",
|
||||
sha256: Some("b72b7df7cd22a4e7462dbe95633c5ca61caab41237d68e0ff89e9774cd4985e7")
|
||||
url: "https://github.com/indygreg/python-build-standalone/releases/download/20241008/cpython-3.13.0%2B20241008-x86_64-apple-darwin-freethreaded%2Bpgo%2Blto-full.tar.zst",
|
||||
sha256: Some("117528b68096379b1303faee1f4f9e32ef3d255207ec92fb063f1bd0b942549d")
|
||||
},
|
||||
ManagedPythonDownload {
|
||||
key: PythonInstallationKey {
|
||||
|
@ -308,8 +308,8 @@ pub(crate) const PYTHON_DOWNLOADS: &[ManagedPythonDownload] = &[
|
|||
variant: PythonVariant::Freethreaded
|
||||
|
||||
},
|
||||
url: "https://github.com/indygreg/python-build-standalone/releases/download/20241008/cpython-3.13.0%2B20241008-x86_64-unknown-linux-gnu-freethreaded%2Bdebug-full.tar.zst",
|
||||
sha256: Some("2b46a0f38711cfcdffab90f69ea1372288bd6dcb0f9676b765babb491d42ce06")
|
||||
url: "https://github.com/indygreg/python-build-standalone/releases/download/20241008/cpython-3.13.0%2B20241008-x86_64-unknown-linux-gnu-freethreaded%2Bpgo%2Blto-full.tar.zst",
|
||||
sha256: Some("00a159a64640ce614bdac064b270a9854d86d40d1d8387a822daf1fe0881e64b")
|
||||
},
|
||||
ManagedPythonDownload {
|
||||
key: PythonInstallationKey {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue