@@ -958,8 +958,8 @@ impl<InstalledPackages: InstalledPackagesProvider> ResolverState<InstalledPackag
958958 ) ;
959959 return Ok ( None ) ;
960960 }
961- MetadataResponse :: RequiresPython ( _ ) => {
962- unreachable ! ( "`requires-python` is not known upfront for URL requirements " )
961+ MetadataResponse :: RequiresPython ( .. ) => {
962+ unreachable ! ( "`requires-python` is only known upfront for registry distributions " )
963963 }
964964 } ;
965965
@@ -1077,72 +1077,54 @@ impl<InstalledPackages: InstalledPackagesProvider> ResolverState<InstalledPackag
10771077 }
10781078 } ;
10791079
1080- let incompatibility = match dist {
1080+ // Validate the Python requirement.
1081+ let requires_python = match dist {
10811082 CompatibleDist :: InstalledDist ( _) => None ,
10821083 CompatibleDist :: SourceDist { sdist, .. }
10831084 | CompatibleDist :: IncompatibleWheel { sdist, .. } => {
1084- // Source distributions must meet both the _target_ Python version and the
1085- // _installed_ Python version (to build successfully).
1086- sdist
1087- . file
1088- . requires_python
1089- . as_ref ( )
1090- . and_then ( |requires_python| {
1091- // if !python_requirement
1092- // .installed()
1093- // .is_contained_by(requires_python)
1094- // {
1095- // return Some(IncompatibleDist::Source(
1096- // IncompatibleSource::RequiresPython(
1097- // requires_python.clone(),
1098- // PythonRequirementKind::Installed,
1099- // ),
1100- // ));
1101- // }
1102- if !python_requirement. target ( ) . is_contained_by ( requires_python) {
1103- return Some ( IncompatibleDist :: Source (
1104- IncompatibleSource :: RequiresPython (
1105- requires_python. clone ( ) ,
1106- PythonRequirementKind :: Target ,
1107- ) ,
1108- ) ) ;
1109- }
1110- None
1111- } )
1112- }
1113- CompatibleDist :: CompatibleWheel { wheel, .. } => {
1114- // Wheels must meet the _target_ Python version.
1115- wheel
1116- . file
1117- . requires_python
1118- . as_ref ( )
1119- . and_then ( |requires_python| {
1120- if python_requirement. installed ( ) == python_requirement. target ( ) {
1121- if !python_requirement
1122- . installed ( )
1123- . is_contained_by ( requires_python)
1124- {
1125- return Some ( IncompatibleDist :: Wheel (
1126- IncompatibleWheel :: RequiresPython (
1127- requires_python. clone ( ) ,
1128- PythonRequirementKind :: Installed ,
1129- ) ,
1130- ) ) ;
1131- }
1132- } else {
1133- if !python_requirement. target ( ) . is_contained_by ( requires_python) {
1134- return Some ( IncompatibleDist :: Wheel (
1135- IncompatibleWheel :: RequiresPython (
1136- requires_python. clone ( ) ,
1137- PythonRequirementKind :: Target ,
1138- ) ,
1139- ) ) ;
1140- }
1141- }
1142- None
1143- } )
1085+ sdist. file . requires_python . as_ref ( )
11441086 }
1087+ CompatibleDist :: CompatibleWheel { wheel, .. } => wheel. file . requires_python . as_ref ( ) ,
11451088 } ;
1089+ let incompatibility = requires_python. and_then ( |requires_python| {
1090+ if python_requirement. installed ( ) == python_requirement. target ( ) {
1091+ if !python_requirement
1092+ . installed ( )
1093+ . is_contained_by ( requires_python)
1094+ {
1095+ return if matches ! ( dist, CompatibleDist :: CompatibleWheel { .. } ) {
1096+ Some ( IncompatibleDist :: Wheel ( IncompatibleWheel :: RequiresPython (
1097+ requires_python. clone ( ) ,
1098+ PythonRequirementKind :: Installed ,
1099+ ) ) )
1100+ } else {
1101+ Some ( IncompatibleDist :: Source (
1102+ IncompatibleSource :: RequiresPython (
1103+ requires_python. clone ( ) ,
1104+ PythonRequirementKind :: Installed ,
1105+ ) ,
1106+ ) )
1107+ } ;
1108+ }
1109+ } else {
1110+ if !python_requirement. target ( ) . is_contained_by ( requires_python) {
1111+ return if matches ! ( dist, CompatibleDist :: CompatibleWheel { .. } ) {
1112+ Some ( IncompatibleDist :: Wheel ( IncompatibleWheel :: RequiresPython (
1113+ requires_python. clone ( ) ,
1114+ PythonRequirementKind :: Target ,
1115+ ) ) )
1116+ } else {
1117+ Some ( IncompatibleDist :: Source (
1118+ IncompatibleSource :: RequiresPython (
1119+ requires_python. clone ( ) ,
1120+ PythonRequirementKind :: Target ,
1121+ ) ,
1122+ ) )
1123+ } ;
1124+ }
1125+ }
1126+ None
1127+ } ) ;
11461128
11471129 // The version is incompatible due to its Python requirement.
11481130 if let Some ( incompatibility) = incompatibility {
@@ -1345,17 +1327,26 @@ impl<InstalledPackages: InstalledPackagesProvider> ResolverState<InstalledPackag
13451327 UnavailableVersion :: InvalidStructure ,
13461328 ) ) ;
13471329 }
1348- MetadataResponse :: RequiresPython ( err) => {
1349- warn ! ( "Unable to extract metadata for {name}: {err}" ) ;
1330+ MetadataResponse :: RequiresPython ( requires_python, python_version) => {
1331+ warn ! (
1332+ "Unable to extract metadata for {name}: {}" ,
1333+ uv_distribution:: Error :: RequiresPython (
1334+ requires_python. clone( ) ,
1335+ python_version. clone( )
1336+ )
1337+ ) ;
13501338 self . incomplete_packages
13511339 . entry ( name. clone ( ) )
13521340 . or_default ( )
13531341 . insert (
13541342 version. clone ( ) ,
1355- IncompletePackage :: RequiresPython ( err. to_string ( ) ) ,
1343+ IncompletePackage :: RequiresPython (
1344+ requires_python. clone ( ) ,
1345+ python_version. clone ( ) ,
1346+ ) ,
13561347 ) ;
13571348 return Ok ( Dependencies :: Unavailable (
1358- UnavailableVersion :: RequiresPython ,
1349+ UnavailableVersion :: RequiresPython ( requires_python . clone ( ) ) ,
13591350 ) ) ;
13601351 }
13611352 } ;
@@ -1904,33 +1895,22 @@ impl<InstalledPackages: InstalledPackagesProvider> ResolverState<InstalledPackag
19041895 }
19051896 }
19061897
1907- match dist {
1908- CompatibleDist :: InstalledDist ( _) => { }
1898+ // Validate the Python requirement.
1899+ let requires_python = match dist {
1900+ CompatibleDist :: InstalledDist ( _) => None ,
19091901 CompatibleDist :: SourceDist { sdist, .. }
19101902 | CompatibleDist :: IncompatibleWheel { sdist, .. } => {
1911- // Source distributions must meet both the _target_ Python version and the
1912- // _installed_ Python version (to build successfully).
1913- if let Some ( requires_python) = sdist. file . requires_python . as_ref ( ) {
1914- // if !python_requirement
1915- // .installed()
1916- // .is_contained_by(requires_python)
1917- // {
1918- // return Ok(None);
1919- // }
1920- if !python_requirement. target ( ) . is_contained_by ( requires_python) {
1921- return Ok ( None ) ;
1922- }
1923- }
1903+ sdist. file . requires_python . as_ref ( )
19241904 }
19251905 CompatibleDist :: CompatibleWheel { wheel, .. } => {
1926- // Wheels must meet the _target_ Python version.
1927- if let Some ( requires_python) = wheel. file . requires_python . as_ref ( ) {
1928- if !python_requirement. target ( ) . is_contained_by ( requires_python) {
1929- return Ok ( None ) ;
1930- }
1931- }
1906+ wheel. file . requires_python . as_ref ( )
19321907 }
19331908 } ;
1909+ if let Some ( requires_python) = requires_python. as_ref ( ) {
1910+ if !python_requirement. target ( ) . is_contained_by ( requires_python) {
1911+ return Ok ( None ) ;
1912+ }
1913+ }
19341914
19351915 // Emit a request to fetch the metadata for this version.
19361916 if self . index . distributions ( ) . register ( candidate. version_id ( ) ) {
0 commit comments