@@ -96,8 +96,8 @@ pub enum Error {
96
96
"Remote python downloads JSON is not yet supported, please use a local path (without `file://` prefix)"
97
97
) ]
98
98
RemoteJSONNotSupported ( ) ,
99
- #[ error( "The json of the python downloads is invalid: {0}" ) ]
100
- InvalidPythonDownloadsJSON ( String , #[ source] serde_json:: Error ) ,
99
+ #[ error( "The JSON of the python downloads is invalid: {0}" ) ]
100
+ InvalidPythonDownloadsJSON ( PathBuf , #[ source] serde_json:: Error ) ,
101
101
#[ error( "An offline Python installation was requested, but {file} (from {url}) is missing in {}" , python_builds_dir. user_display( ) ) ]
102
102
OfflinePythonMissing {
103
103
file : Box < PythonInstallationKey > ,
@@ -554,20 +554,26 @@ impl ManagedPythonDownload {
554
554
let json_downloads: HashMap < String , JsonPythonDownload > = if let Some ( json_source) =
555
555
python_downloads_json_url
556
556
{
557
- if Url :: parse ( json_source) . is_ok ( ) {
558
- return Err ( Error :: RemoteJSONNotSupported ( ) ) ;
559
- }
560
-
561
- let file = match fs_err:: File :: open ( json_source) {
562
- Ok ( file) => file,
563
- Err ( e) => { Err ( Error :: Io ( e) ) } ?,
557
+ let json_source = if let Ok ( url) = Url :: parse ( json_source) {
558
+ if let Ok ( path) = url. to_file_path ( ) {
559
+ Cow :: Owned ( path)
560
+ } else if url. scheme ( ) . len ( ) > 1 {
561
+ // Schemes of length 1 are likely Windows drive letters.
562
+ return Err ( Error :: RemoteJSONNotSupported ( ) ) ;
563
+ } else {
564
+ Cow :: Borrowed ( Path :: new ( json_source) )
565
+ }
566
+ } else {
567
+ Cow :: Borrowed ( Path :: new ( json_source) )
564
568
} ;
565
569
570
+ let file = fs_err:: File :: open ( json_source. as_ref ( ) ) ?;
571
+
566
572
serde_json:: from_reader ( file)
567
- . map_err ( |e| Error :: InvalidPythonDownloadsJSON ( json_source. to_string ( ) , e) ) ?
573
+ . map_err ( |e| Error :: InvalidPythonDownloadsJSON ( json_source. to_path_buf ( ) , e) ) ?
568
574
} else {
569
575
serde_json:: from_str ( BUILTIN_PYTHON_DOWNLOADS_JSON ) . map_err ( |e| {
570
- Error :: InvalidPythonDownloadsJSON ( "EMBEDDED IN THE BINARY" . to_string ( ) , e)
576
+ Error :: InvalidPythonDownloadsJSON ( PathBuf :: from ( "EMBEDDED IN THE BINARY" ) , e)
571
577
} ) ?
572
578
} ;
573
579
0 commit comments