Add an editable index to the site-packages registry (#671)

This PR modifies `SitePackages` to store all distributions in a flat
vector, and maintain two indexes (hash maps) from "per-element data for
an element in the vector" to "index of that element". This enables us to
maintain a map on both package name and editable URL.
This commit is contained in:
Charlie Marsh
2023-12-16 22:44:36 -05:00
committed by GitHub
parent 08edd173db
commit 00e1c33af4
5 changed files with 129 additions and 54 deletions
+6 -1
View File
@@ -1,4 +1,6 @@
use anyhow::Result;
use distribution_types::Metadata;
use itertools::Itertools;
use tracing::debug;
use platform_host::Platform;
@@ -21,7 +23,10 @@ pub(crate) fn freeze(cache: &Cache, _printer: Printer) -> Result<ExitStatus> {
// Build the installed index.
let site_packages = SitePackages::from_executable(&python)?;
for dist in site_packages.distributions() {
for dist in site_packages
.iter()
.sorted_unstable_by(|a, b| a.name().cmp(b.name()))
{
#[allow(clippy::print_stdout)]
{
println!("{dist}");
@@ -78,11 +78,7 @@ pub(crate) async fn pip_uninstall(
// Identify all editables that are installed.
for editable in &editables {
if let Some(distribution) = site_packages
.editables()
.find(|(_dist, url, _dir_info)| url == editable)
.map(|(dist, _url, _dir_info)| dist)
{
if let Some(distribution) = site_packages.get_editable(editable) {
distributions.push(distribution);
} else {
writeln!(