@@ -2,7 +2,7 @@ use std::collections::BTreeMap;
22use std:: fmt:: { Display , Formatter } ;
33
44use distribution_types:: {
5- Dist , DistributionMetadata , Name , ResolutionDiagnostic , ResolvedDist , VersionId ,
5+ Dist , DistributionMetadata , IndexUrl , Name , ResolutionDiagnostic , ResolvedDist , VersionId ,
66 VersionOrUrlRef ,
77} ;
88use indexmap:: IndexSet ;
@@ -88,6 +88,7 @@ struct PackageRef<'a> {
8888 package_name : & ' a PackageName ,
8989 version : & ' a Version ,
9090 url : Option < & ' a VerbatimParsedUrl > ,
91+ index : Option < & ' a IndexUrl > ,
9192 extra : Option < & ' a ExtraName > ,
9293 group : Option < & ' a GroupName > ,
9394}
@@ -284,6 +285,7 @@ impl ResolutionGraph {
284285 package_name : from,
285286 version : & edge. from_version ,
286287 url : edge. from_url . as_ref ( ) ,
288+ index : edge. from_index . as_ref ( ) ,
287289 extra : edge. from_extra . as_ref ( ) ,
288290 group : edge. from_dev . as_ref ( ) ,
289291 } ]
@@ -292,6 +294,7 @@ impl ResolutionGraph {
292294 package_name : & edge. to ,
293295 version : & edge. to_version ,
294296 url : edge. to_url . as_ref ( ) ,
297+ index : edge. to_index . as_ref ( ) ,
295298 extra : edge. to_extra . as_ref ( ) ,
296299 group : edge. to_dev . as_ref ( ) ,
297300 } ] ;
@@ -320,7 +323,7 @@ impl ResolutionGraph {
320323 diagnostics : & mut Vec < ResolutionDiagnostic > ,
321324 preferences : & Preferences ,
322325 pins : & FilePins ,
323- index : & InMemoryIndex ,
326+ in_memory : & InMemoryIndex ,
324327 git : & GitResolver ,
325328 package : & ' a ResolutionPackage ,
326329 version : & ' a Version ,
@@ -330,16 +333,18 @@ impl ResolutionGraph {
330333 extra,
331334 dev,
332335 url,
336+ index,
333337 } = & package;
334338 // Map the package to a distribution.
335339 let ( dist, hashes, metadata) = Self :: parse_dist (
336340 name,
341+ index. as_ref ( ) ,
337342 url. as_ref ( ) ,
338343 version,
339344 pins,
340345 diagnostics,
341346 preferences,
342- index ,
347+ in_memory ,
343348 git,
344349 ) ?;
345350
@@ -366,7 +371,7 @@ impl ResolutionGraph {
366371 }
367372
368373 // Add the distribution to the graph.
369- let index = petgraph. add_node ( ResolutionGraphNode :: Dist ( AnnotatedDist {
374+ let node = petgraph. add_node ( ResolutionGraphNode :: Dist ( AnnotatedDist {
370375 dist,
371376 name : name. clone ( ) ,
372377 version : version. clone ( ) ,
@@ -381,22 +386,24 @@ impl ResolutionGraph {
381386 package_name : name,
382387 version,
383388 url : url. as_ref ( ) ,
389+ index : index. as_ref ( ) ,
384390 extra : extra. as_ref ( ) ,
385391 group : dev. as_ref ( ) ,
386392 } ,
387- index ,
393+ node ,
388394 ) ;
389395 Ok ( ( ) )
390396 }
391397
392398 fn parse_dist (
393399 name : & PackageName ,
400+ index : Option < & IndexUrl > ,
394401 url : Option < & VerbatimParsedUrl > ,
395402 version : & Version ,
396403 pins : & FilePins ,
397404 diagnostics : & mut Vec < ResolutionDiagnostic > ,
398405 preferences : & Preferences ,
399- index : & InMemoryIndex ,
406+ in_memory : & InMemoryIndex ,
400407 git : & GitResolver ,
401408 ) -> Result < ( ResolvedDist , Vec < HashDigest > , Option < Metadata > ) , ResolveError > {
402409 Ok ( if let Some ( url) = url {
@@ -406,14 +413,24 @@ impl ResolutionGraph {
406413 let version_id = VersionId :: from_url ( & url. verbatim ) ;
407414
408415 // Extract the hashes.
409- let hashes =
410- Self :: get_hashes ( name, Some ( url) , & version_id, version, preferences, index) ;
416+ let hashes = Self :: get_hashes (
417+ name,
418+ index,
419+ Some ( url) ,
420+ & version_id,
421+ version,
422+ preferences,
423+ in_memory,
424+ ) ;
411425
412426 // Extract the metadata.
413427 let metadata = {
414- let response = index. distributions ( ) . get ( & version_id) . unwrap_or_else ( || {
415- panic ! ( "Every URL distribution should have metadata: {version_id:?}" )
416- } ) ;
428+ let response = in_memory
429+ . distributions ( )
430+ . get ( & version_id)
431+ . unwrap_or_else ( || {
432+ panic ! ( "Every URL distribution should have metadata: {version_id:?}" )
433+ } ) ;
417434
418435 let MetadataResponse :: Found ( archive) = & * response else {
419436 panic ! ( "Every URL distribution should have metadata: {version_id:?}" )
@@ -449,17 +466,28 @@ impl ResolutionGraph {
449466 }
450467
451468 // Extract the hashes.
452- let hashes = Self :: get_hashes ( name, None , & version_id, version, preferences, index) ;
469+ let hashes = Self :: get_hashes (
470+ name,
471+ index,
472+ None ,
473+ & version_id,
474+ version,
475+ preferences,
476+ in_memory,
477+ ) ;
453478
454479 // Extract the metadata.
455480 let metadata = {
456- index. distributions ( ) . get ( & version_id) . and_then ( |response| {
457- if let MetadataResponse :: Found ( archive) = & * response {
458- Some ( archive. metadata . clone ( ) )
459- } else {
460- None
461- }
462- } )
481+ in_memory
482+ . distributions ( )
483+ . get ( & version_id)
484+ . and_then ( |response| {
485+ if let MetadataResponse :: Found ( archive) = & * response {
486+ Some ( archive. metadata . clone ( ) )
487+ } else {
488+ None
489+ }
490+ } )
463491 } ;
464492
465493 ( dist, hashes, metadata)
@@ -470,11 +498,12 @@ impl ResolutionGraph {
470498 /// lockfile.
471499 fn get_hashes (
472500 name : & PackageName ,
501+ index : Option < & IndexUrl > ,
473502 url : Option < & VerbatimParsedUrl > ,
474503 version_id : & VersionId ,
475504 version : & Version ,
476505 preferences : & Preferences ,
477- index : & InMemoryIndex ,
506+ in_memory : & InMemoryIndex ,
478507 ) -> Vec < HashDigest > {
479508 // 1. Look for hashes from the lockfile.
480509 if let Some ( digests) = preferences. match_hashes ( name, version) {
@@ -484,7 +513,7 @@ impl ResolutionGraph {
484513 }
485514
486515 // 2. Look for hashes for the distribution (i.e., the specific wheel or source distribution).
487- if let Some ( metadata_response) = index . distributions ( ) . get ( version_id) {
516+ if let Some ( metadata_response) = in_memory . distributions ( ) . get ( version_id) {
488517 if let MetadataResponse :: Found ( ref archive) = * metadata_response {
489518 let mut digests = archive. hashes . clone ( ) ;
490519 digests. sort_unstable ( ) ;
@@ -496,7 +525,13 @@ impl ResolutionGraph {
496525
497526 // 3. Look for hashes from the registry, which are served at the package level.
498527 if url. is_none ( ) {
499- if let Some ( versions_response) = index. packages ( ) . get ( name) {
528+ let versions_response = if let Some ( index) = index {
529+ in_memory. explicit ( ) . get ( & ( name. clone ( ) , index. clone ( ) ) )
530+ } else {
531+ in_memory. implicit ( ) . get ( name)
532+ } ;
533+
534+ if let Some ( versions_response) = versions_response {
500535 if let VersionsResponse :: Found ( ref version_maps) = * versions_response {
501536 if let Some ( digests) = version_maps
502537 . iter ( )
0 commit comments