@@ -36,7 +36,7 @@ use crate::implementation::{
3636use crate :: installation:: PythonInstallationKey ;
3737use crate :: libc:: LibcDetectionError ;
3838use crate :: managed:: ManagedPythonInstallation ;
39- use crate :: platform:: { self , Arch , Libc , Os } ;
39+ use crate :: platform:: { self , Arch , ArchMode , Libc , Os } ;
4040use crate :: { Interpreter , PythonRequest , PythonVersion , VersionRequest } ;
4141
4242#[ derive( Error , Debug ) ]
@@ -125,6 +125,8 @@ pub struct PythonDownloadRequest {
125125 /// Whether to allow pre-releases or not. If not set, defaults to true if [`Self::version`] is
126126 /// not None, and false otherwise.
127127 pub ( crate ) prereleases : Option < bool > ,
128+
129+ pub ( crate ) arch_mode : Option < ArchMode > ,
128130}
129131
130132impl PythonDownloadRequest {
@@ -135,6 +137,7 @@ impl PythonDownloadRequest {
135137 os : Option < Os > ,
136138 libc : Option < Libc > ,
137139 prereleases : Option < bool > ,
140+ arch_mode : Option < ArchMode > ,
138141 ) -> Self {
139142 Self {
140143 version,
@@ -143,6 +146,7 @@ impl PythonDownloadRequest {
143146 os,
144147 libc,
145148 prereleases,
149+ arch_mode,
146150 }
147151 }
148152
@@ -188,6 +192,12 @@ impl PythonDownloadRequest {
188192 self
189193 }
190194
195+ #[ must_use]
196+ pub fn with_arch_mode ( mut self , arch_mode : ArchMode ) -> Self {
197+ self . arch_mode = Some ( arch_mode) ;
198+ self
199+ }
200+
191201 /// Construct a new [`PythonDownloadRequest`] from a [`PythonRequest`] if possible.
192202 ///
193203 /// Returns [`None`] if the request kind is not compatible with a download, e.g., it is
@@ -249,6 +259,7 @@ impl PythonDownloadRequest {
249259 Some ( Os :: from_env ( ) ) ,
250260 Some ( Libc :: from_env ( ) ?) ,
251261 None ,
262+ None ,
252263 ) )
253264 }
254265
@@ -293,6 +304,11 @@ impl PythonDownloadRequest {
293304 if !arch. supports ( key. arch ) {
294305 return false ;
295306 }
307+ if let Some ( mode) = self . arch_mode {
308+ if !mode. allows ( arch, & key. arch ) {
309+ return false ;
310+ }
311+ }
296312 }
297313
298314 if let Some ( libc) = & self . libc {
@@ -414,6 +430,7 @@ impl From<&ManagedPythonInstallation> for PythonDownloadRequest {
414430 Some ( key. os ) ,
415431 Some ( key. libc ) ,
416432 Some ( key. prerelease . is_some ( ) ) ,
433+ None ,
417434 )
418435 }
419436}
@@ -485,7 +502,15 @@ impl FromStr for PythonDownloadRequest {
485502 _ => return Err ( Error :: TooManyParts ( s. to_string ( ) ) ) ,
486503 }
487504 }
488- Ok ( Self :: new ( version, implementation, arch, os, libc, None ) )
505+ Ok ( Self :: new (
506+ version,
507+ implementation,
508+ arch,
509+ os,
510+ libc,
511+ None ,
512+ None ,
513+ ) )
489514 }
490515}
491516
0 commit comments