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
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 129 additions and 54 deletions

View file

@ -3,6 +3,7 @@ use std::str::FromStr;
use anyhow::{anyhow, Context, Result};
use fs_err as fs;
use url::Url;
use pep440_rs::Version;
use puffin_normalize::PackageName;
@ -140,4 +141,15 @@ impl InstalledDist {
Metadata21::parse(&contents)
.with_context(|| format!("Failed to parse METADATA file at: {}", path.display()))
}
/// Return the [`Url`] of the distribution, if it is editable.
pub fn editable(&self) -> Option<&Url> {
match self {
Self::Url(InstalledDirectUrlDist {
url: DirectUrl::LocalDirectory { url, dir_info },
..
}) if dir_info.editable == Some(true) => Some(url),
_ => None,
}
}
}