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:
@@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user