mirror of
https://github.com/astral-sh/uv.git
synced 2025-07-07 21:35:00 +00:00
Remove some unused pub
functions (#3872)
## Summary I wrote a bad Python script to find these.
This commit is contained in:
parent
1fc6a59707
commit
cedd18e4c6
12 changed files with 3 additions and 174 deletions
|
@ -361,23 +361,6 @@ impl PyRequirement {
|
|||
}
|
||||
|
||||
impl<T: Pep508Url> Requirement<T> {
|
||||
/// Returns `true` if the [`Version`] satisfies the [`Requirement`].
|
||||
pub fn is_satisfied_by(&self, version: &Version) -> bool {
|
||||
let Some(version_or_url) = self.version_or_url.as_ref() else {
|
||||
return true;
|
||||
};
|
||||
|
||||
let specifiers = match version_or_url {
|
||||
VersionOrUrl::VersionSpecifier(specifiers) => specifiers,
|
||||
// TODO(charlie): Support URL dependencies.
|
||||
VersionOrUrl::Url(_) => return false,
|
||||
};
|
||||
|
||||
specifiers
|
||||
.iter()
|
||||
.all(|specifier| specifier.contains(version))
|
||||
}
|
||||
|
||||
/// Returns whether the markers apply for the given environment
|
||||
pub fn evaluate_markers(&self, env: &MarkerEnvironment, extras: &[ExtraName]) -> bool {
|
||||
if let Some(marker) = &self.marker {
|
||||
|
@ -528,32 +511,6 @@ impl<T: Pep508Url> Requirement<T> {
|
|||
reporter,
|
||||
)
|
||||
}
|
||||
|
||||
/// Convert a requirement with one URL type into one with another URL type.
|
||||
///
|
||||
/// Example: `Requirement<Url>` to `Requirement<VerbatimUrl>`.
|
||||
pub fn convert_url<U: Pep508Url + From<T>>(self) -> Requirement<U> {
|
||||
let Requirement {
|
||||
name,
|
||||
extras,
|
||||
version_or_url,
|
||||
marker,
|
||||
origin,
|
||||
} = self;
|
||||
Requirement {
|
||||
name,
|
||||
extras,
|
||||
version_or_url: match version_or_url {
|
||||
None => None,
|
||||
Some(VersionOrUrl::VersionSpecifier(specifier)) => {
|
||||
Some(VersionOrUrl::VersionSpecifier(specifier))
|
||||
}
|
||||
Some(VersionOrUrl::Url(url)) => Some(VersionOrUrl::Url(U::from(url))),
|
||||
},
|
||||
marker,
|
||||
origin,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A list of [`ExtraName`] that can be attached to a [`Requirement`].
|
||||
|
|
|
@ -1602,7 +1602,7 @@ impl MarkerTree {
|
|||
/// the marker will be simplified to `sys_platform == 'linux'`.
|
||||
pub fn simplify_extras(self, extras: &[ExtraName]) -> Option<MarkerTree> {
|
||||
/// Returns `true` if the given expression is always `true` given the set of extras.
|
||||
pub fn is_true(expression: &MarkerExpression, extras: &[ExtraName]) -> bool {
|
||||
fn is_true(expression: &MarkerExpression, extras: &[ExtraName]) -> bool {
|
||||
match expression {
|
||||
MarkerExpression::Extra {
|
||||
operator: ExtraOperator::Equal,
|
||||
|
|
|
@ -155,14 +155,6 @@ impl VerbatimUrl {
|
|||
pub fn to_url(&self) -> Url {
|
||||
self.url.clone()
|
||||
}
|
||||
|
||||
/// Create a [`VerbatimUrl`] from a [`Url`].
|
||||
///
|
||||
/// This method should be used sparingly (ideally, not at all), as it represents a loss of the
|
||||
/// verbatim representation.
|
||||
pub fn unknown(url: Url) -> Self {
|
||||
Self { given: None, url }
|
||||
}
|
||||
}
|
||||
|
||||
// This impl is written out because the `derive` doesn't seem to get it right.
|
||||
|
|
|
@ -43,12 +43,6 @@ impl BaseUrl {
|
|||
pub fn as_url(&self) -> &Url {
|
||||
&self.0
|
||||
}
|
||||
|
||||
/// Convert to the underlying [`Url`].
|
||||
#[must_use]
|
||||
pub fn into_url(self) -> Url {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Url> for BaseUrl {
|
||||
|
|
|
@ -5,7 +5,7 @@ use thiserror::Error;
|
|||
use url::{ParseError, Url};
|
||||
|
||||
use pep508_rs::{Pep508Url, UnnamedRequirementUrl, VerbatimUrl, VerbatimUrlError};
|
||||
use uv_git::{GitSha, GitUrl};
|
||||
use uv_git::GitUrl;
|
||||
|
||||
use crate::{ArchiveInfo, DirInfo, DirectUrl, VcsInfo, VcsKind};
|
||||
|
||||
|
@ -240,12 +240,6 @@ fn get_subdirectory(url: &Url) -> Option<PathBuf> {
|
|||
Some(PathBuf::from(subdirectory))
|
||||
}
|
||||
|
||||
/// Return the Git reference of the given URL, if it exists.
|
||||
pub fn git_reference(url: Url) -> Result<Option<GitSha>, Box<ParsedUrlError>> {
|
||||
let ParsedGitUrl { url, .. } = ParsedGitUrl::try_from(url)?;
|
||||
Ok(url.precise())
|
||||
}
|
||||
|
||||
impl TryFrom<Url> for ParsedUrl {
|
||||
type Error = ParsedUrlError;
|
||||
|
||||
|
|
|
@ -203,12 +203,6 @@ impl RegistryClient {
|
|||
self.timeout
|
||||
}
|
||||
|
||||
/// Set the index URLs to use for fetching packages.
|
||||
#[must_use]
|
||||
pub fn with_index_url(self, index_urls: IndexUrls) -> Self {
|
||||
Self { index_urls, ..self }
|
||||
}
|
||||
|
||||
/// Fetch a package from the `PyPI` simple API.
|
||||
///
|
||||
/// "simple" here refers to [PEP 503 – Simple Repository API](https://peps.python.org/pep-0503/)
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
//! [installer][`uv_installer`] and [build][`uv_build`] through [`BuildDispatch`]
|
||||
//! implementing [`BuildContext`].
|
||||
|
||||
use std::ffi::OsStr;
|
||||
use std::ffi::OsString;
|
||||
use std::path::Path;
|
||||
|
||||
|
@ -90,21 +89,6 @@ impl<'a> BuildDispatch<'a> {
|
|||
self.options = options;
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the environment variables to be used when building a source distribution.
|
||||
#[must_use]
|
||||
pub fn with_build_extra_env_vars<I, K, V>(mut self, sdist_build_env_variables: I) -> Self
|
||||
where
|
||||
I: IntoIterator<Item = (K, V)>,
|
||||
K: AsRef<OsStr>,
|
||||
V: AsRef<OsStr>,
|
||||
{
|
||||
self.build_extra_env_vars = sdist_build_env_variables
|
||||
.into_iter()
|
||||
.map(|(key, value)| (key.as_ref().to_owned(), value.as_ref().to_owned()))
|
||||
.collect();
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> BuildContext for BuildDispatch<'a> {
|
||||
|
|
|
@ -2,7 +2,6 @@ use std::fmt::Display;
|
|||
use std::path::{Path, PathBuf};
|
||||
|
||||
use fs2::FileExt;
|
||||
use fs_err as fs;
|
||||
use tempfile::NamedTempFile;
|
||||
use tracing::{debug, error, trace, warn};
|
||||
|
||||
|
@ -150,25 +149,6 @@ pub fn write_atomic_sync(path: impl AsRef<Path>, data: impl AsRef<[u8]>) -> std:
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Remove the file or directory at `path`, if it exists.
|
||||
///
|
||||
/// Returns `true` if the file or directory was removed, and `false` if the path did not exist.
|
||||
pub fn force_remove_all(path: impl AsRef<Path>) -> Result<bool, std::io::Error> {
|
||||
let path = path.as_ref();
|
||||
|
||||
let Some(metadata) = metadata_if_exists(path)? else {
|
||||
return Ok(false);
|
||||
};
|
||||
|
||||
if metadata.is_dir() {
|
||||
fs::remove_dir_all(path)?;
|
||||
} else {
|
||||
fs::remove_file(path)?;
|
||||
}
|
||||
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
/// Rename a file, retrying (on Windows) if it fails due to transient operating system errors.
|
||||
#[cfg(feature = "tokio")]
|
||||
pub async fn rename_with_retry(
|
||||
|
@ -327,14 +307,3 @@ impl Drop for LockedFile {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Given a path, return its metadata if the file exists, or `None` if it does not.
|
||||
///
|
||||
/// If the file exists but cannot be read, returns an error.
|
||||
pub fn metadata_if_exists(path: impl AsRef<Path>) -> std::io::Result<Option<std::fs::Metadata>> {
|
||||
match fs::metadata(path) {
|
||||
Ok(metadata) => Ok(Some(metadata)),
|
||||
Err(err) if err.kind() == std::io::ErrorKind::NotFound => Ok(None),
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,11 +48,6 @@ impl GitUrl {
|
|||
&self.reference
|
||||
}
|
||||
|
||||
/// Returns `true` if the reference is a full commit.
|
||||
pub fn is_full_commit(&self) -> bool {
|
||||
matches!(self.reference, GitReference::FullCommit(_))
|
||||
}
|
||||
|
||||
/// Return the precise commit, if known.
|
||||
pub fn precise(&self) -> Option<GitSha> {
|
||||
self.precise
|
||||
|
|
|
@ -151,36 +151,6 @@ impl SitePackages {
|
|||
.collect()
|
||||
}
|
||||
|
||||
/// Returns the editable distribution installed from the given URL, if any.
|
||||
pub fn get_editables(&self, url: &Url) -> Vec<&InstalledDist> {
|
||||
let Some(indexes) = self.by_url.get(url) else {
|
||||
return Vec::new();
|
||||
};
|
||||
indexes
|
||||
.iter()
|
||||
.flat_map(|&index| &self.distributions[index])
|
||||
.filter(|dist| dist.is_editable())
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Remove the editable distribution installed from the given URL, if any.
|
||||
pub fn remove_editables(&mut self, url: &Url) -> Vec<InstalledDist> {
|
||||
let Some(indexes) = self.by_url.get(url) else {
|
||||
return Vec::new();
|
||||
};
|
||||
indexes
|
||||
.iter()
|
||||
.filter_map(|index| {
|
||||
let dist = &mut self.distributions[*index];
|
||||
if dist.as_ref().is_some_and(InstalledDist::is_editable) {
|
||||
std::mem::take(dist)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Returns `true` if there are any installed packages.
|
||||
pub fn any(&self) -> bool {
|
||||
self.distributions.iter().any(Option::is_some)
|
||||
|
@ -501,8 +471,4 @@ impl InstalledPackagesProvider for SitePackages {
|
|||
fn get_packages(&self, name: &PackageName) -> Vec<&InstalledDist> {
|
||||
self.get_packages(name)
|
||||
}
|
||||
|
||||
fn get_editables(&self, url: &Url) -> Vec<&InstalledDist> {
|
||||
self.get_editables(url)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,8 +7,7 @@ use pubgrub::type_aliases::SelectedDependencies;
|
|||
use rustc_hash::{FxHashMap, FxHashSet};
|
||||
|
||||
use distribution_types::{
|
||||
Dist, DistributionMetadata, Name, Requirement, ResolutionDiagnostic, ResolvedDist, VersionId,
|
||||
VersionOrUrlRef,
|
||||
Dist, DistributionMetadata, Name, Requirement, ResolutionDiagnostic, VersionId, VersionOrUrlRef,
|
||||
};
|
||||
use pep440_rs::{Version, VersionSpecifier};
|
||||
use pep508_rs::MarkerEnvironment;
|
||||
|
@ -366,15 +365,6 @@ impl ResolutionGraph {
|
|||
.any(|index| self.petgraph[index].name() == name)
|
||||
}
|
||||
|
||||
/// Iterate over the [`ResolvedDist`] entities in this resolution.
|
||||
pub fn into_distributions(self) -> impl Iterator<Item = ResolvedDist> {
|
||||
self.petgraph
|
||||
.into_nodes_edges()
|
||||
.0
|
||||
.into_iter()
|
||||
.map(|node| node.weight.dist)
|
||||
}
|
||||
|
||||
/// Return the [`ResolutionDiagnostic`]s that were encountered while building the graph.
|
||||
pub fn diagnostics(&self) -> &[ResolutionDiagnostic] {
|
||||
&self.diagnostics
|
||||
|
|
|
@ -2,7 +2,6 @@ use std::future::Future;
|
|||
use std::path::{Path, PathBuf};
|
||||
|
||||
use anyhow::Result;
|
||||
use url::Url;
|
||||
|
||||
use distribution_types::{
|
||||
CachedDist, IndexLocations, InstalledDist, Requirement, Resolution, SourceDist,
|
||||
|
@ -134,7 +133,6 @@ pub trait SourceBuildTrait {
|
|||
pub trait InstalledPackagesProvider: Clone + Send + Sync + 'static {
|
||||
fn iter(&self) -> impl Iterator<Item = &InstalledDist>;
|
||||
fn get_packages(&self, name: &PackageName) -> Vec<&InstalledDist>;
|
||||
fn get_editables(&self, url: &Url) -> Vec<&InstalledDist>;
|
||||
}
|
||||
|
||||
/// An [`InstalledPackagesProvider`] with no packages in it.
|
||||
|
@ -149,8 +147,4 @@ impl InstalledPackagesProvider for EmptyInstalledPackages {
|
|||
fn iter(&self) -> impl Iterator<Item = &InstalledDist> {
|
||||
std::iter::empty()
|
||||
}
|
||||
|
||||
fn get_editables(&self, _url: &Url) -> Vec<&InstalledDist> {
|
||||
Vec::new()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue