@@ -680,17 +680,32 @@ def _create_venv_symlinks(ctx, venv_dir_map):
680680 return venv_files
681681
682682def _build_link_map (entries ):
683- # dict[str kind, dict[str key or rel_path, tuple[ str rel_path, str link_to_path] ]]
683+ # dict[str kind, dict[str rel_path, str link_to_path]]
684684 link_map = {}
685+
686+ # Here we store venv paths by package
687+ # dict[str package, dict[str kind, list[str venv_path]]]
688+ pkg_map = {}
685689 for entry in entries :
686690 kind = entry .kind
687691 kind_map = link_map .setdefault (kind , {})
688692
693+ # If we detect that we are adding a dist-info for an already existing package
694+ # we need to pop all of the previous symlinks from the link_map
695+ if entry .venv_path .endswith (".dist-info" ) and entry .src in pkg_map :
696+ # dist-info will come always first
697+ for kind , dir_paths in pkg_map .pop (entry .src ).items ():
698+ for dir_path in dir_paths :
699+ link_map [kind ].pop (dir_path )
700+
701+ pkg_venv_paths = pkg_map .setdefault (entry .src , {}).setdefault (entry .kind , [])
702+ pkg_venv_paths .append (entry .venv_path )
703+
689704 # We overwrite duplicates by design. The dependency closer to the
690705 # binary gets precedence due to the topological ordering.
691706 #
692707 # This allows us to store only one version of the dist-info that is needed
693- kind_map [entry .key or entry . venv_path ] = ( entry .venv_path , entry . link_to_path )
708+ kind_map [entry .venv_path ] = entry .link_to_path
694709
695710 # An empty link_to value means to not create the site package symlink.
696711 # Because of the topological ordering, this allows binaries to remove
@@ -710,7 +725,7 @@ def _build_link_map(entries):
710725 for _ in range (len (kind_map )):
711726 if not kind_map :
712727 break
713- _ , ( dirname , value ) = kind_map .popitem ()
728+ dirname , value = kind_map .popitem ()
714729 keep_kind_map [dirname ] = value
715730 prefix = dirname + "/" # Add slash to prevent /X matching /XY
716731 for maybe_suffix in kind_map .keys ():
0 commit comments