Rename InstalledDist methods to reflect read operation (#15290)

## Summary

I found it surprising that these don't "just" return fields from the
struct.
This commit is contained in:
Charlie Marsh 2025-08-14 22:39:40 +01:00 committed by GitHub
parent f892276ac8
commit bcfa8443da
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 12 additions and 12 deletions

View file

@ -136,9 +136,9 @@ impl InstalledDist {
let name = PackageName::from_str(name)?; let name = PackageName::from_str(name)?;
let version = Version::from_str(version)?; let version = Version::from_str(version)?;
let cache_info = Self::cache_info(path)?; let cache_info = Self::read_cache_info(path)?;
return if let Some(direct_url) = Self::direct_url(path)? { return if let Some(direct_url) = Self::read_direct_url(path)? {
match Url::try_from(&direct_url) { match Url::try_from(&direct_url) {
Ok(url) => Ok(Some(Self::Url(InstalledDirectUrlDist { Ok(url) => Ok(Some(Self::Url(InstalledDirectUrlDist {
name, name,
@ -304,7 +304,7 @@ impl InstalledDist {
} }
/// Read the `direct_url.json` file from a `.dist-info` directory. /// Read the `direct_url.json` file from a `.dist-info` directory.
pub fn direct_url(path: &Path) -> Result<Option<DirectUrl>, InstalledDistError> { pub fn read_direct_url(path: &Path) -> Result<Option<DirectUrl>, InstalledDistError> {
let path = path.join("direct_url.json"); let path = path.join("direct_url.json");
let file = match fs_err::File::open(&path) { let file = match fs_err::File::open(&path) {
Ok(file) => file, Ok(file) => file,
@ -317,7 +317,7 @@ impl InstalledDist {
} }
/// Read the `uv_cache.json` file from a `.dist-info` directory. /// Read the `uv_cache.json` file from a `.dist-info` directory.
pub fn cache_info(path: &Path) -> Result<Option<CacheInfo>, InstalledDistError> { pub fn read_cache_info(path: &Path) -> Result<Option<CacheInfo>, InstalledDistError> {
let path = path.join("uv_cache.json"); let path = path.join("uv_cache.json");
let file = match fs_err::File::open(&path) { let file = match fs_err::File::open(&path) {
Ok(file) => file, Ok(file) => file,
@ -330,7 +330,7 @@ impl InstalledDist {
} }
/// Read the `METADATA` file from a `.dist-info` directory. /// Read the `METADATA` file from a `.dist-info` directory.
pub fn metadata(&self) -> Result<uv_pypi_types::ResolutionMetadata, InstalledDistError> { pub fn read_metadata(&self) -> Result<uv_pypi_types::ResolutionMetadata, InstalledDistError> {
match self { match self {
Self::Registry(_) | Self::Url(_) => { Self::Registry(_) | Self::Url(_) => {
let path = self.install_path().join("METADATA"); let path = self.install_path().join("METADATA");
@ -362,7 +362,7 @@ impl InstalledDist {
} }
/// Return the `INSTALLER` of the distribution. /// Return the `INSTALLER` of the distribution.
pub fn installer(&self) -> Result<Option<String>, InstalledDistError> { pub fn read_installer(&self) -> Result<Option<String>, InstalledDistError> {
let path = self.install_path().join("INSTALLER"); let path = self.install_path().join("INSTALLER");
match fs::read_to_string(path) { match fs::read_to_string(path) {
Ok(installer) => Ok(Some(installer.trim().to_owned())), Ok(installer) => Ok(Some(installer.trim().to_owned())),

View file

@ -140,7 +140,7 @@ impl<'a, Context: BuildContext> DistributionDatabase<'a, Context> {
} }
let metadata = dist let metadata = dist
.metadata() .read_metadata()
.map_err(|err| Error::ReadInstalled(Box::new(dist.clone()), err))?; .map_err(|err| Error::ReadInstalled(Box::new(dist.clone()), err))?;
Ok(ArchiveMetadata::from_metadata23(metadata)) Ok(ArchiveMetadata::from_metadata23(metadata))

View file

@ -222,7 +222,7 @@ impl SitePackages {
}; };
// Determine the dependencies for the given package. // Determine the dependencies for the given package.
let Ok(metadata) = distribution.metadata() else { let Ok(metadata) = distribution.read_metadata() else {
diagnostics.push(SitePackagesDiagnostic::MetadataUnavailable { diagnostics.push(SitePackagesDiagnostic::MetadataUnavailable {
package: package.clone(), package: package.clone(),
path: distribution.install_path().to_owned(), path: distribution.install_path().to_owned(),
@ -471,7 +471,7 @@ impl SitePackages {
// Recurse into the dependencies. // Recurse into the dependencies.
let metadata = distribution let metadata = distribution
.metadata() .read_metadata()
.with_context(|| format!("Failed to read metadata for: {distribution}"))?; .with_context(|| format!("Failed to read metadata for: {distribution}"))?;
// Add the dependencies to the queue. // Add the dependencies to the queue.

View file

@ -98,7 +98,7 @@ pub(crate) fn pip_show(
let mut requires_map = FxHashMap::default(); let mut requires_map = FxHashMap::default();
// For Requires field // For Requires field
for dist in &distributions { for dist in &distributions {
if let Ok(metadata) = dist.metadata() { if let Ok(metadata) = dist.read_metadata() {
requires_map.insert( requires_map.insert(
dist.name(), dist.name(),
Box::into_iter(metadata.requires_dist) Box::into_iter(metadata.requires_dist)
@ -116,7 +116,7 @@ pub(crate) fn pip_show(
if requires_map.contains_key(installed.name()) { if requires_map.contains_key(installed.name()) {
continue; continue;
} }
if let Ok(metadata) = installed.metadata() { if let Ok(metadata) = installed.read_metadata() {
let requires = Box::into_iter(metadata.requires_dist) let requires = Box::into_iter(metadata.requires_dist)
.filter(|req| req.evaluate_markers(&markers, &[])) .filter(|req| req.evaluate_markers(&markers, &[]))
.map(|req| req.name) .map(|req| req.name)

View file

@ -74,7 +74,7 @@ pub(crate) async fn pip_tree(
packages packages
.entry(package.name()) .entry(package.name())
.or_default() .or_default()
.push(package.metadata()?); .push(package.read_metadata()?);
} }
packages packages
}; };