From fc3ef19cf40c3371e94d36f828ee2da778954332 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Wed, 25 Dec 2024 13:56:44 -0500 Subject: [PATCH] Remove unnecessary prefixes --- crates/uv-auth/src/credentials.rs | 8 +- crates/uv-build-frontend/src/error.rs | 8 +- crates/uv-client/src/cached_client.rs | 4 +- crates/uv-client/src/httpcache/control.rs | 9 +- crates/uv-client/src/registry_client.rs | 2 +- crates/uv-client/src/rkyvutil.rs | 6 +- crates/uv-configuration/src/authentication.rs | 2 +- crates/uv-configuration/src/trusted_host.rs | 2 +- crates/uv-distribution-types/src/file.rs | 2 +- crates/uv-distribution-types/src/lib.rs | 16 +-- crates/uv-install-wheel/src/linker.rs | 4 +- crates/uv-macros/src/options_metadata.rs | 6 +- crates/uv-normalize/src/lib.rs | 2 +- crates/uv-pep440/src/version_ranges.rs | 2 +- crates/uv-pep440/src/version_specifier.rs | 2 +- crates/uv-pep508/src/lib.rs | 13 +- crates/uv-pep508/src/marker/tree.rs | 22 ++-- crates/uv-python/src/discovery.rs | 114 +++++++----------- crates/uv-python/src/environment.rs | 8 +- crates/uv-python/src/managed.rs | 4 +- crates/uv-resolver/src/lock/mod.rs | 22 ++-- crates/uv-resolver/src/pubgrub/priority.rs | 2 +- crates/uv-resolver/src/resolver/mod.rs | 4 +- crates/uv-workspace/src/pyproject_mut.rs | 4 +- crates/uv/src/commands/build_frontend.rs | 4 +- crates/uv/src/commands/help.rs | 2 +- crates/uv/src/commands/python/list.rs | 2 +- crates/uv/src/settings.rs | 2 +- crates/uv/tests/it/common/mod.rs | 20 ++- crates/uv/tests/it/pip_compile.rs | 2 +- crates/uv/tests/it/python_find.rs | 3 +- crates/uv/tests/it/python_pin.rs | 4 +- 32 files changed, 128 insertions(+), 179 deletions(-) diff --git a/crates/uv-auth/src/credentials.rs b/crates/uv-auth/src/credentials.rs index bb8f28d4a5d9..66ec4cbb5929 100644 --- a/crates/uv-auth/src/credentials.rs +++ b/crates/uv-auth/src/credentials.rs @@ -237,7 +237,7 @@ impl Credentials { /// /// Any existing credentials will be overridden. #[must_use] - pub(crate) fn authenticate(&self, mut request: reqwest::Request) -> reqwest::Request { + pub(crate) fn authenticate(&self, mut request: Request) -> Request { request .headers_mut() .insert(reqwest::header::AUTHORIZATION, Self::to_header_value(self)); @@ -296,7 +296,7 @@ mod tests { auth_url.set_password(Some("password")).unwrap(); let credentials = Credentials::from_url(&auth_url).unwrap(); - let mut request = reqwest::Request::new(reqwest::Method::GET, url); + let mut request = Request::new(reqwest::Method::GET, url); request = credentials.authenticate(request); let mut header = request @@ -318,7 +318,7 @@ mod tests { auth_url.set_password(Some("password")).unwrap(); let credentials = Credentials::from_url(&auth_url).unwrap(); - let mut request = reqwest::Request::new(reqwest::Method::GET, url); + let mut request = Request::new(reqwest::Method::GET, url); request = credentials.authenticate(request); let mut header = request @@ -340,7 +340,7 @@ mod tests { auth_url.set_password(Some("password==")).unwrap(); let credentials = Credentials::from_url(&auth_url).unwrap(); - let mut request = reqwest::Request::new(reqwest::Method::GET, url); + let mut request = Request::new(reqwest::Method::GET, url); request = credentials.authenticate(request); let mut header = request diff --git a/crates/uv-build-frontend/src/error.rs b/crates/uv-build-frontend/src/error.rs index 81fda9d877b5..e9f5ab9e711d 100644 --- a/crates/uv-build-frontend/src/error.rs +++ b/crates/uv-build-frontend/src/error.rs @@ -452,7 +452,7 @@ mod test { assert!(matches!(err, Error::MissingHeader { .. })); // Unix uses exit status, Windows uses exit code. - let formatted = std::error::Error::source(&err) + let formatted = Error::source(&err) .unwrap() .to_string() .replace("exit status: ", "exit code: "); @@ -510,7 +510,7 @@ mod test { ); assert!(matches!(err, Error::MissingHeader { .. })); // Unix uses exit status, Windows uses exit code. - let formatted = std::error::Error::source(&err) + let formatted = Error::source(&err) .unwrap() .to_string() .replace("exit status: ", "exit code: "); @@ -558,7 +558,7 @@ mod test { ); assert!(matches!(err, Error::MissingHeader { .. })); // Unix uses exit status, Windows uses exit code. - let formatted = std::error::Error::source(&err) + let formatted = Error::source(&err) .unwrap() .to_string() .replace("exit status: ", "exit code: "); @@ -604,7 +604,7 @@ mod test { ); assert!(matches!(err, Error::MissingHeader { .. })); // Unix uses exit status, Windows uses exit code. - let formatted = std::error::Error::source(&err) + let formatted = Error::source(&err) .unwrap() .to_string() .replace("exit status: ", "exit code: "); diff --git a/crates/uv-client/src/cached_client.rs b/crates/uv-client/src/cached_client.rs index b52b68add1d9..dc521f5cf3db 100644 --- a/crates/uv-client/src/cached_client.rs +++ b/crates/uv-client/src/cached_client.rs @@ -45,7 +45,7 @@ pub trait Cacheable: Sized { /// Deserialize a value from bytes aligned to a 16-byte boundary. fn from_aligned_bytes(bytes: AlignedVec) -> Result; /// Serialize bytes to a possibly owned byte buffer. - fn to_bytes(&self) -> Result, crate::Error>; + fn to_bytes(&self) -> Result, Error>; /// Convert this type into its final form. fn into_target(self) -> Self::Target; } @@ -814,7 +814,7 @@ impl DataWithCachePolicy { /// If the given byte buffer is not in a valid format or if the reader /// fails, then this returns an error. pub fn from_reader(mut rdr: impl std::io::Read) -> Result { - let mut aligned_bytes = rkyv::util::AlignedVec::new(); + let mut aligned_bytes = AlignedVec::new(); aligned_bytes .extend_from_reader(&mut rdr) .map_err(ErrorKind::Io)?; diff --git a/crates/uv-client/src/httpcache/control.rs b/crates/uv-client/src/httpcache/control.rs index 6860386bff25..accd11e86f78 100644 --- a/crates/uv-client/src/httpcache/control.rs +++ b/crates/uv-client/src/httpcache/control.rs @@ -182,10 +182,7 @@ impl<'b, B: 'b + ?Sized + AsRef<[u8]>, I: Iterator> CacheControlPa /// given iterator should yield elements that satisfy `AsRef<[u8]>`. fn new>(headers: II) -> CacheControlParser<'b, I> { let mut directives = headers.into_iter(); - let cur = directives - .next() - .map(std::convert::AsRef::as_ref) - .unwrap_or(b""); + let cur = directives.next().map(AsRef::as_ref).unwrap_or(b""); CacheControlParser { cur, directives, @@ -265,7 +262,7 @@ impl<'b, B: 'b + ?Sized + AsRef<[u8]>, I: Iterator> CacheControlPa self.cur = &self.cur[1..]; self.parse_quoted_string() } else { - self.parse_token().map(std::string::String::into_bytes) + self.parse_token().map(String::into_bytes) } } @@ -371,7 +368,7 @@ impl<'b, B: 'b + ?Sized + AsRef<[u8]>, I: Iterator> Iterator fn next(&mut self) -> Option { loop { if self.cur.is_empty() { - self.cur = self.directives.next().map(std::convert::AsRef::as_ref)?; + self.cur = self.directives.next().map(AsRef::as_ref)?; } while !self.cur.is_empty() { self.skip_whitespace(); diff --git a/crates/uv-client/src/registry_client.rs b/crates/uv-client/src/registry_client.rs index 6cbb0d8c1b6a..0510b42c0386 100644 --- a/crates/uv-client/src/registry_client.rs +++ b/crates/uv-client/src/registry_client.rs @@ -1039,7 +1039,7 @@ mod tests { .iter() .map(|file| uv_pypi_types::base_url_join_relative(base.as_url().as_str(), &file.url)) .collect::, JoinRelativeError>>()?; - let urls = urls.iter().map(reqwest::Url::as_str).collect::>(); + let urls = urls.iter().map(Url::as_str).collect::>(); insta::assert_debug_snapshot!(urls, @r###" [ "https://account.d.codeartifact.us-west-2.amazonaws.com/pypi/shared-packages-pypi/simple/0.1/Flask-0.1.tar.gz#sha256=9da884457e910bf0847d396cb4b778ad9f3c3d17db1c5997cb861937bd284237", diff --git a/crates/uv-client/src/rkyvutil.rs b/crates/uv-client/src/rkyvutil.rs index 0131260676bb..37ef9f5ffc4e 100644 --- a/crates/uv-client/src/rkyvutil.rs +++ b/crates/uv-client/src/rkyvutil.rs @@ -77,11 +77,11 @@ where /// /// If the bytes fail validation (e.g., contains unaligned pointers or /// strings aren't valid UTF-8), then this returns an error. - pub fn new(raw: rkyv::util::AlignedVec) -> Result { + pub fn new(raw: AlignedVec) -> Result { // We convert the error to a simple string because... the error type // does not implement Send. And I don't think we really need to keep // the error type around anyway. - let _ = rkyv::access::(&raw) + let _ = rkyv::access::(&raw) .map_err(|e| ErrorKind::ArchiveRead(e.to_string()))?; Ok(Self { raw, @@ -98,7 +98,7 @@ where /// If the bytes fail validation (e.g., contains unaligned pointers or /// strings aren't valid UTF-8), then this returns an error. pub fn from_reader(mut rdr: R) -> Result { - let mut buf = rkyv::util::AlignedVec::with_capacity(1024); + let mut buf = AlignedVec::with_capacity(1024); buf.extend_from_reader(&mut rdr).map_err(ErrorKind::Io)?; Self::new(buf) } diff --git a/crates/uv-configuration/src/authentication.rs b/crates/uv-configuration/src/authentication.rs index ce22e5749d32..a6773c81fa55 100644 --- a/crates/uv-configuration/src/authentication.rs +++ b/crates/uv-configuration/src/authentication.rs @@ -19,7 +19,7 @@ pub enum KeyringProviderType { // See for details. impl KeyringProviderType { - pub fn to_provider(&self) -> Option { + pub fn to_provider(&self) -> Option { match self { Self::Disabled => None, Self::Subprocess => Some(KeyringProvider::subprocess()), diff --git a/crates/uv-configuration/src/trusted_host.rs b/crates/uv-configuration/src/trusted_host.rs index 9901b42cd95d..2faed69255dd 100644 --- a/crates/uv-configuration/src/trusted_host.rs +++ b/crates/uv-configuration/src/trusted_host.rs @@ -81,7 +81,7 @@ pub enum TrustedHostError { InvalidPort(String), } -impl std::str::FromStr for TrustedHost { +impl FromStr for TrustedHost { type Err = TrustedHostError; fn from_str(s: &str) -> Result { diff --git a/crates/uv-distribution-types/src/file.rs b/crates/uv-distribution-types/src/file.rs index fd5efe150473..bfbbbf7e49b5 100644 --- a/crates/uv-distribution-types/src/file.rs +++ b/crates/uv-distribution-types/src/file.rs @@ -118,7 +118,7 @@ impl FileLocation { } impl Display for FileLocation { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match self { Self::RelativeUrl(_base, url) => Display::fmt(&url, f), Self::AbsoluteUrl(url) => Display::fmt(&url.0, f), diff --git a/crates/uv-distribution-types/src/lib.rs b/crates/uv-distribution-types/src/lib.rs index 2407a2532095..9aba9e5c5f14 100644 --- a/crates/uv-distribution-types/src/lib.rs +++ b/crates/uv-distribution-types/src/lib.rs @@ -1341,20 +1341,12 @@ mod test { /// Ensure that we don't accidentally grow the `Dist` sizes. #[test] fn dist_size() { + assert!(size_of::() <= 336, "{}", size_of::()); + assert!(size_of::() <= 336, "{}", size_of::()); assert!( - std::mem::size_of::() <= 336, + size_of::() <= 264, "{}", - std::mem::size_of::() - ); - assert!( - std::mem::size_of::() <= 336, - "{}", - std::mem::size_of::() - ); - assert!( - std::mem::size_of::() <= 264, - "{}", - std::mem::size_of::() + size_of::() ); } diff --git a/crates/uv-install-wheel/src/linker.rs b/crates/uv-install-wheel/src/linker.rs index 593ad39c2188..d09913c377de 100644 --- a/crates/uv-install-wheel/src/linker.rs +++ b/crates/uv-install-wheel/src/linker.rs @@ -469,7 +469,7 @@ fn copy_wheel_files( let mut count = 0usize; // Walk over the directory. - for entry in walkdir::WalkDir::new(&wheel) { + for entry in WalkDir::new(&wheel) { let entry = entry?; let path = entry.path(); @@ -499,7 +499,7 @@ fn hardlink_wheel_files( let mut count = 0usize; // Walk over the directory. - for entry in walkdir::WalkDir::new(&wheel) { + for entry in WalkDir::new(&wheel) { let entry = entry?; let path = entry.path(); diff --git a/crates/uv-macros/src/options_metadata.rs b/crates/uv-macros/src/options_metadata.rs index a060ac90004e..6865ba397580 100644 --- a/crates/uv-macros/src/options_metadata.rs +++ b/crates/uv-macros/src/options_metadata.rs @@ -110,7 +110,7 @@ pub(crate) fn derive_impl(input: DeriveInput) -> syn::Result { /// For a field with type `Option` where `Foobar` itself is a struct /// deriving `ConfigurationOptions`, create code that calls retrieves options /// from that group: `Foobar::get_available_options()` -fn handle_option_group(field: &Field) -> syn::Result { +fn handle_option_group(field: &Field) -> syn::Result { let ident = field .ident .as_ref() @@ -145,7 +145,7 @@ fn handle_option_group(field: &Field) -> syn::Result { /// Parse a `doc` attribute into it a string literal. fn parse_doc(doc: &Attribute) -> syn::Result { match &doc.meta { - syn::Meta::NameValue(syn::MetaNameValue { + Meta::NameValue(syn::MetaNameValue { value: syn::Expr::Lit(ExprLit { lit: Lit::Str(lit_str), @@ -159,7 +159,7 @@ fn parse_doc(doc: &Attribute) -> syn::Result { /// Parse an `#[option(doc="...", default="...", value_type="...", /// example="...")]` attribute and return data in the form of an `OptionField`. -fn handle_option(field: &Field, attr: &Attribute) -> syn::Result { +fn handle_option(field: &Field, attr: &Attribute) -> syn::Result { let docs: Vec<&Attribute> = field .attrs .iter() diff --git a/crates/uv-normalize/src/lib.rs b/crates/uv-normalize/src/lib.rs index 0360a5a1a161..583b17bcc6af 100644 --- a/crates/uv-normalize/src/lib.rs +++ b/crates/uv-normalize/src/lib.rs @@ -95,7 +95,7 @@ fn is_normalized(name: impl AsRef) -> Result { Ok(true) } -/// Invalid [`crate::PackageName`] or [`crate::ExtraName`]. +/// Invalid [`PackageName`] or [`ExtraName`]. #[derive(Clone, Debug, Eq, PartialEq)] pub struct InvalidNameError(String); diff --git a/crates/uv-pep440/src/version_ranges.rs b/crates/uv-pep440/src/version_ranges.rs index a05d7be039a2..7a9a4b055eed 100644 --- a/crates/uv-pep440/src/version_ranges.rs +++ b/crates/uv-pep440/src/version_ranges.rs @@ -1,4 +1,4 @@ -//! Convert [`VersionSpecifiers`] to [`version_ranges::Ranges`]. +//! Convert [`VersionSpecifiers`] to [`Ranges`]. use version_ranges::Ranges; diff --git a/crates/uv-pep440/src/version_specifier.rs b/crates/uv-pep440/src/version_specifier.rs index 122f7a3e3699..30cdc76243b8 100644 --- a/crates/uv-pep440/src/version_specifier.rs +++ b/crates/uv-pep440/src/version_specifier.rs @@ -491,7 +491,7 @@ impl VersionSpecifier { Operator::ExactEqual => { #[cfg(feature = "tracing")] { - tracing::warn!("Using arbitrary equality (`===`) is discouraged"); + warn!("Using arbitrary equality (`===`) is discouraged"); } self.version.to_string() == version.to_string() } diff --git a/crates/uv-pep508/src/lib.rs b/crates/uv-pep508/src/lib.rs index 8981410b3ee6..95f4a4774c4e 100644 --- a/crates/uv-pep508/src/lib.rs +++ b/crates/uv-pep508/src/lib.rs @@ -232,12 +232,12 @@ impl Requirement { } } -/// Type to parse URLs from `name @ ` into. Defaults to [`url::Url`]. +/// Type to parse URLs from `name @ ` into. Defaults to [`Url`]. pub trait Pep508Url: Display + Debug + Sized { /// String to URL parsing error type Err: Error + Debug; - /// Parse a url from `name @ `. Defaults to [`url::Url::parse_url`]. + /// Parse a url from `name @ `. Defaults to [`Url::parse_url`]. fn parse_url(url: &str, working_dir: Option<&Path>) -> Result; } @@ -1069,7 +1069,7 @@ mod tests { marker: MarkerTree::expression(MarkerExpression::Version { key: MarkerValueVersion::PythonFullVersion, specifier: VersionSpecifier::from_pattern( - uv_pep440::Operator::LessThan, + Operator::LessThan, "2.7".parse().unwrap(), ) .unwrap(), @@ -1333,11 +1333,8 @@ mod tests { let mut a = MarkerTree::expression(MarkerExpression::Version { key: MarkerValueVersion::PythonVersion, - specifier: VersionSpecifier::from_pattern( - uv_pep440::Operator::Equal, - "2.7".parse().unwrap(), - ) - .unwrap(), + specifier: VersionSpecifier::from_pattern(Operator::Equal, "2.7".parse().unwrap()) + .unwrap(), }); let mut b = MarkerTree::expression(MarkerExpression::String { key: MarkerValueString::SysPlatform, diff --git a/crates/uv-pep508/src/marker/tree.rs b/crates/uv-pep508/src/marker/tree.rs index 1c006418d589..55e8b5d7d06c 100644 --- a/crates/uv-pep508/src/marker/tree.rs +++ b/crates/uv-pep508/src/marker/tree.rs @@ -53,7 +53,7 @@ pub enum MarkerValueVersion { } impl Display for MarkerValueVersion { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match self { Self::ImplementationVersion => f.write_str("implementation_version"), Self::PythonFullVersion => f.write_str("python_full_version"), @@ -97,7 +97,7 @@ pub enum MarkerValueString { impl Display for MarkerValueString { /// Normalizes deprecated names to the proper ones - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match self { Self::ImplementationName => f.write_str("implementation_name"), Self::OsName | Self::OsNameDeprecated => f.write_str("os_name"), @@ -175,7 +175,7 @@ impl FromStr for MarkerValue { } impl Display for MarkerValue { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match self { Self::MarkerEnvVersion(marker_value_version) => marker_value_version.fmt(f), Self::MarkerEnvString(marker_value_string) => marker_value_string.fmt(f), @@ -341,7 +341,7 @@ impl FromStr for MarkerOperator { } impl Display for MarkerOperator { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { f.write_str(match self { Self::Equal => "==", Self::NotEqual => "!=", @@ -386,7 +386,7 @@ impl FromStr for StringVersion { } impl Display for StringVersion { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { self.string.fmt(f) } } @@ -446,7 +446,7 @@ impl MarkerValueExtra { } impl Display for MarkerValueExtra { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match self { Self::Extra(extra) => extra.fmt(f), Self::Arbitrary(string) => string.fmt(f), @@ -538,7 +538,7 @@ impl ExtraOperator { } impl Display for ExtraOperator { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { f.write_str(match self { Self::Equal => "==", Self::NotEqual => "!=", @@ -590,7 +590,7 @@ impl MarkerExpression { } impl Display for MarkerExpression { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match self { MarkerExpression::Version { key, specifier } => { let (op, version) = (specifier.operator(), specifier.version()); @@ -1198,7 +1198,7 @@ impl MarkerTree { MarkerTreeDebugRaw { marker: self } } - fn fmt_graph(self, f: &mut fmt::Formatter<'_>, level: usize) -> fmt::Result { + fn fmt_graph(self, f: &mut Formatter<'_>, level: usize) -> fmt::Result { match self.kind() { MarkerTreeKind::True => return write!(f, "true"), MarkerTreeKind::False => return write!(f, "false"), @@ -1296,7 +1296,7 @@ pub struct MarkerTreeDebugGraph<'a> { } impl fmt::Debug for MarkerTreeDebugGraph<'_> { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { self.marker.fmt_graph(f, 0) } } @@ -1313,7 +1313,7 @@ pub struct MarkerTreeDebugRaw<'a> { } impl fmt::Debug for MarkerTreeDebugRaw<'_> { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { let node = INTERNER.shared.node(self.marker.0); f.debug_tuple("MarkerTreeDebugRaw").field(node).finish() } diff --git a/crates/uv-python/src/discovery.rs b/crates/uv-python/src/discovery.rs index 9b7ce4581052..d7210ab4d4bc 100644 --- a/crates/uv-python/src/discovery.rs +++ b/crates/uv-python/src/discovery.rs @@ -246,7 +246,7 @@ pub enum Error { /// Notably, "system" environments are excluded. See [`python_executables_from_installed`]. fn python_executables_from_virtual_environments<'a>( ) -> impl Iterator> + 'a { - let from_active_environment = std::iter::once_with(|| { + let from_active_environment = iter::once_with(|| { virtualenv_from_env() .into_iter() .map(virtualenv_python_executable) @@ -255,7 +255,7 @@ fn python_executables_from_virtual_environments<'a>( .flatten(); // N.B. we prefer the conda environment over discovered virtual environments - let from_conda_environment = std::iter::once_with(|| { + let from_conda_environment = iter::once_with(|| { conda_environment_from_env(CondaEnvironmentKind::Child) .into_iter() .map(virtualenv_python_executable) @@ -263,7 +263,7 @@ fn python_executables_from_virtual_environments<'a>( }) .flatten(); - let from_discovered_environment = std::iter::once_with(|| { + let from_discovered_environment = iter::once_with(|| { virtualenv_from_working_dir() .map(|path| { path.map(virtualenv_python_executable) @@ -302,7 +302,7 @@ fn python_executables_from_installed<'a>( implementation: Option<&'a ImplementationName>, preference: PythonPreference, ) -> Box> + 'a> { - let from_managed_installations = std::iter::once_with(move || { + let from_managed_installations = iter::once_with(move || { ManagedPythonInstallations::from_settings(None) .map_err(Error::from) .and_then(|installed_installations| { @@ -328,13 +328,13 @@ fn python_executables_from_installed<'a>( }) .flatten_ok(); - let from_search_path = std::iter::once_with(move || { + let from_search_path = iter::once_with(move || { python_executables_from_search_path(version, implementation) .map(|path| Ok((PythonSource::SearchPath, path))) }) .flatten(); - let from_windows_registry = std::iter::once_with(move || { + let from_windows_registry = iter::once_with(move || { #[cfg(windows)] { // Skip interpreter probing if we already know the version doesn't match. @@ -407,15 +407,15 @@ fn python_executables<'a>( preference: PythonPreference, ) -> Box> + 'a> { // Always read from `UV_INTERNAL__PARENT_INTERPRETER` — it could be a system interpreter - let from_parent_interpreter = std::iter::once_with(|| { - std::env::var_os(EnvVars::UV_INTERNAL__PARENT_INTERPRETER) + let from_parent_interpreter = iter::once_with(|| { + env::var_os(EnvVars::UV_INTERNAL__PARENT_INTERPRETER) .into_iter() .map(|path| Ok((PythonSource::ParentInterpreter, PathBuf::from(path)))) }) .flatten(); // Check if the the base conda environment is active - let from_base_conda_environment = std::iter::once_with(|| { + let from_base_conda_environment = iter::once_with(|| { conda_environment_from_env(CondaEnvironmentKind::Base) .into_iter() .map(virtualenv_python_executable) @@ -803,18 +803,16 @@ pub fn find_python_installations<'a>( .sources(request); match request { - PythonRequest::File(path) => Box::new(std::iter::once({ + PythonRequest::File(path) => Box::new(iter::once({ if preference.allows(PythonSource::ProvidedPath) { debug!("Checking for Python interpreter at {request}"); match python_installation_from_executable(path, cache) { - Ok(installation) => Ok(FindPythonResult::Ok(installation)), - Err(InterpreterError::NotFound(_)) => { - Ok(FindPythonResult::Err(PythonNotFound { - request: request.clone(), - python_preference: preference, - environment_preference: environments, - })) - } + Ok(installation) => Ok(Ok(installation)), + Err(InterpreterError::NotFound(_)) => Ok(Err(PythonNotFound { + request: request.clone(), + python_preference: preference, + environment_preference: environments, + })), Err(err) => Err(Error::Query( Box::new(err), path.clone(), @@ -829,18 +827,16 @@ pub fn find_python_installations<'a>( )) } })), - PythonRequest::Directory(path) => Box::new(std::iter::once({ + PythonRequest::Directory(path) => Box::new(iter::once({ if preference.allows(PythonSource::ProvidedPath) { debug!("Checking for Python interpreter in {request}"); match python_installation_from_directory(path, cache) { - Ok(installation) => Ok(FindPythonResult::Ok(installation)), - Err(InterpreterError::NotFound(_)) => { - Ok(FindPythonResult::Err(PythonNotFound { - request: request.clone(), - python_preference: preference, - environment_preference: environments, - })) - } + Ok(installation) => Ok(Ok(installation)), + Err(InterpreterError::NotFound(_)) => Ok(Err(PythonNotFound { + request: request.clone(), + python_preference: preference, + environment_preference: environments, + })), Err(err) => Err(Error::Query( Box::new(err), path.clone(), @@ -863,14 +859,10 @@ pub fn find_python_installations<'a>( .filter(move |result| { result_satisfies_environment_preference(result, environments) }) - .map(|result| { - result - .map(PythonInstallation::from_tuple) - .map(FindPythonResult::Ok) - }), + .map(|result| result.map(PythonInstallation::from_tuple).map(Ok)), ) } else { - Box::new(std::iter::once(Err(Error::SourceNotAllowed( + Box::new(iter::once(Err(Error::SourceNotAllowed( request.clone(), PythonSource::SearchPath, preference, @@ -879,13 +871,8 @@ pub fn find_python_installations<'a>( } PythonRequest::Any => Box::new({ debug!("Searching for any Python interpreter in {sources}"); - python_interpreters(&VersionRequest::Any, None, environments, preference, cache).map( - |result| { - result - .map(PythonInstallation::from_tuple) - .map(FindPythonResult::Ok) - }, - ) + python_interpreters(&VersionRequest::Any, None, environments, preference, cache) + .map(|result| result.map(PythonInstallation::from_tuple).map(Ok)) }), PythonRequest::Default => Box::new({ debug!("Searching for default Python interpreter in {sources}"); @@ -896,23 +883,16 @@ pub fn find_python_installations<'a>( preference, cache, ) - .map(|result| { - result - .map(PythonInstallation::from_tuple) - .map(FindPythonResult::Ok) - }) + .map(|result| result.map(PythonInstallation::from_tuple).map(Ok)) }), PythonRequest::Version(version) => { if let Err(err) = version.check_supported() { - return Box::new(std::iter::once(Err(Error::InvalidVersionRequest(err)))); + return Box::new(iter::once(Err(Error::InvalidVersionRequest(err)))); }; Box::new({ debug!("Searching for {request} in {sources}"); - python_interpreters(version, None, environments, preference, cache).map(|result| { - result - .map(PythonInstallation::from_tuple) - .map(FindPythonResult::Ok) - }) + python_interpreters(version, None, environments, preference, cache) + .map(|result| result.map(PythonInstallation::from_tuple).map(Ok)) }) } PythonRequest::Implementation(implementation) => Box::new({ @@ -930,15 +910,11 @@ pub fn find_python_installations<'a>( .implementation_name() .eq_ignore_ascii_case(implementation.into()), }) - .map(|result| { - result - .map(PythonInstallation::from_tuple) - .map(FindPythonResult::Ok) - }) + .map(|result| result.map(PythonInstallation::from_tuple).map(Ok)) }), PythonRequest::ImplementationVersion(implementation, version) => { if let Err(err) = version.check_supported() { - return Box::new(std::iter::once(Err(Error::InvalidVersionRequest(err)))); + return Box::new(iter::once(Err(Error::InvalidVersionRequest(err)))); }; Box::new({ debug!("Searching for {request} in {sources}"); @@ -955,17 +931,13 @@ pub fn find_python_installations<'a>( .implementation_name() .eq_ignore_ascii_case(implementation.into()), }) - .map(|result| { - result - .map(PythonInstallation::from_tuple) - .map(FindPythonResult::Ok) - }) + .map(|result| result.map(PythonInstallation::from_tuple).map(Ok)) }) } PythonRequest::Key(request) => { if let Some(version) = request.version() { if let Err(err) = version.check_supported() { - return Box::new(std::iter::once(Err(Error::InvalidVersionRequest(err)))); + return Box::new(iter::once(Err(Error::InvalidVersionRequest(err)))); }; }; Box::new({ @@ -981,11 +953,7 @@ pub fn find_python_installations<'a>( Err(_) => true, Ok((_source, interpreter)) => request.satisfied_by_interpreter(interpreter), }) - .map(|result| { - result - .map(PythonInstallation::from_tuple) - .map(FindPythonResult::Ok) - }) + .map(|result| result.map(PythonInstallation::from_tuple).map(Ok)) }) } } @@ -1058,7 +1026,7 @@ pub(crate) fn find_python_installation( return Ok(Ok(installation)); } - Ok(FindPythonResult::Err(PythonNotFound { + Ok(Err(PythonNotFound { request: request.clone(), environment_preference: environments, python_preference: preference, @@ -1768,8 +1736,8 @@ impl ExecutableName { } } -impl std::fmt::Display for ExecutableName { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl fmt::Display for ExecutableName { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { if let Some(implementation) = self.implementation { write!(f, "{implementation}")?; } else { @@ -1788,7 +1756,7 @@ impl std::fmt::Display for ExecutableName { write!(f, "{prerelease}")?; } f.write_str(self.variant.suffix())?; - f.write_str(std::env::consts::EXE_SUFFIX)?; + f.write_str(EXE_SUFFIX)?; Ok(()) } } @@ -2307,7 +2275,7 @@ impl FromStr for PythonVariant { } } -impl std::fmt::Display for PythonVariant { +impl fmt::Display for PythonVariant { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match self { Self::Default => f.write_str("default"), diff --git a/crates/uv-python/src/environment.rs b/crates/uv-python/src/environment.rs index d02c2fe352ba..e7a5b7b9dfad 100644 --- a/crates/uv-python/src/environment.rs +++ b/crates/uv-python/src/environment.rs @@ -111,8 +111,8 @@ impl fmt::Display for EnvironmentNotFound { } } -impl std::fmt::Display for InvalidEnvironment { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl fmt::Display for InvalidEnvironment { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!( f, "Invalid environment at `{}`: {}", @@ -122,8 +122,8 @@ impl std::fmt::Display for InvalidEnvironment { } } -impl std::fmt::Display for InvalidEnvironmentKind { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl fmt::Display for InvalidEnvironmentKind { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { Self::NotDirectory => write!(f, "expected directory but found a file"), Self::MissingExecutable(path) => { diff --git a/crates/uv-python/src/managed.rs b/crates/uv-python/src/managed.rs index 5cc45d020bf1..1b35e8c2cad6 100644 --- a/crates/uv-python/src/managed.rs +++ b/crates/uv-python/src/managed.rs @@ -83,7 +83,7 @@ pub enum Error { #[error("Failed to read managed Python directory name: {0}")] NameError(String), #[error("Failed to construct absolute path to managed Python directory: {}", _0.user_display())] - AbsolutePath(PathBuf, #[source] std::io::Error), + AbsolutePath(PathBuf, #[source] io::Error), #[error(transparent)] NameParseError(#[from] installation::PythonInstallationKeyError), #[error(transparent)] @@ -443,7 +443,7 @@ impl ManagedPythonInstallation { continue; } - match uv_fs::symlink_or_copy_file(&python, &executable) { + match symlink_or_copy_file(&python, &executable) { Ok(()) => { debug!( "Created link {} -> {}", diff --git a/crates/uv-resolver/src/lock/mod.rs b/crates/uv-resolver/src/lock/mod.rs index 2283e6776365..f70a50ebeb0e 100644 --- a/crates/uv-resolver/src/lock/mod.rs +++ b/crates/uv-resolver/src/lock/mod.rs @@ -2432,7 +2432,7 @@ impl PackageId { } } -impl std::fmt::Display for PackageId { +impl Display for PackageId { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}=={} @ {}", self.name, self.version, self.source) } @@ -2736,7 +2736,7 @@ impl Source { } } -impl std::fmt::Display for Source { +impl Display for Source { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { match self { Source::Registry(RegistrySource::Url(url)) @@ -2866,7 +2866,7 @@ enum RegistrySource { Path(PathBuf), } -impl std::fmt::Display for RegistrySource { +impl Display for RegistrySource { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { match self { RegistrySource::Url(url) => write!(f, "{url}"), @@ -3765,7 +3765,7 @@ impl Dependency { } } -impl std::fmt::Display for Dependency { +impl Display for Dependency { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { if self.extra.is_empty() { write!( @@ -3826,7 +3826,7 @@ impl From for Hash { } } -impl std::str::FromStr for Hash { +impl FromStr for Hash { type Err = HashParseError; fn from_str(s: &str) -> Result { @@ -3843,7 +3843,7 @@ impl std::str::FromStr for Hash { } } -impl std::fmt::Display for Hash { +impl Display for Hash { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}:{}", self.0.algorithm, self.0.digest) } @@ -4249,21 +4249,21 @@ enum LockErrorKind { DistributionRelativePath( /// The inner error we forward. #[source] - std::io::Error, + io::Error, ), /// An error that occurs when converting an index URL to a relative path #[error("Could not compute relative path between workspace and index")] IndexRelativePath( /// The inner error we forward. #[source] - std::io::Error, + io::Error, ), /// An error that occurs when converting a lockfile path from relative to absolute. #[error("Could not compute absolute path from workspace root and lockfile path")] AbsolutePath( /// The inner error we forward. #[source] - std::io::Error, + io::Error, ), /// An error that occurs when an ambiguous `package.dependency` is /// missing a `version` field. @@ -4290,7 +4290,7 @@ enum LockErrorKind { RequirementRelativePath( /// The inner error we forward. #[source] - std::io::Error, + io::Error, ), /// An error that occurs when parsing an existing requirement. #[error("Could not convert between URL and path")] @@ -4368,7 +4368,7 @@ struct HashParseError(&'static str); impl std::error::Error for HashParseError {} -impl std::fmt::Display for HashParseError { +impl Display for HashParseError { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { Display::fmt(self.0, f) } diff --git a/crates/uv-resolver/src/pubgrub/priority.rs b/crates/uv-resolver/src/pubgrub/priority.rs index 3fbd4b2a9b34..588b8f6bcc67 100644 --- a/crates/uv-resolver/src/pubgrub/priority.rs +++ b/crates/uv-resolver/src/pubgrub/priority.rs @@ -221,7 +221,7 @@ pub(crate) enum PubGrubPriority { /// /// N.B.: URLs need to have priority over registry distributions for correctly matching registry /// distributions to URLs, see [`PubGrubPackage::from_package`] an - /// [`crate::fork_urls::ForkUrls`]. + /// [`ForkUrls`]. DirectUrl(Reverse), /// The package is the root package. diff --git a/crates/uv-resolver/src/resolver/mod.rs b/crates/uv-resolver/src/resolver/mod.rs index aeeebb8d9ebc..915fadbcdb29 100644 --- a/crates/uv-resolver/src/resolver/mod.rs +++ b/crates/uv-resolver/src/resolver/mod.rs @@ -1908,7 +1908,7 @@ impl ResolverState ResolverState { if !constraint.evaluate_markers( env.marker_environment(), - std::slice::from_ref(source_extra), + slice::from_ref(source_extra), ) { return None; } diff --git a/crates/uv-workspace/src/pyproject_mut.rs b/crates/uv-workspace/src/pyproject_mut.rs index 25544cc05884..cae147295100 100644 --- a/crates/uv-workspace/src/pyproject_mut.rs +++ b/crates/uv-workspace/src/pyproject_mut.rs @@ -319,7 +319,7 @@ impl PyProjectTomlMut { if index.default { if !table .get("default") - .and_then(toml_edit::Item::as_bool) + .and_then(Item::as_bool) .is_some_and(|default| default) { let mut formatted = Formatted::new(true); @@ -371,7 +371,7 @@ impl PyProjectTomlMut { }); // Set the position to the minimum, if it's not already the first element. - if let Some(min) = existing.iter().filter_map(toml_edit::Table::position).min() { + if let Some(min) = existing.iter().filter_map(Table::position).min() { table.set_position(min); // Increment the position of all existing elements. diff --git a/crates/uv/src/commands/build_frontend.rs b/crates/uv/src/commands/build_frontend.rs index f764617a92cb..0ec665e386c7 100644 --- a/crates/uv/src/commands/build_frontend.rs +++ b/crates/uv/src/commands/build_frontend.rs @@ -1092,8 +1092,8 @@ impl<'a> From> for AnnotatedSource<'a> { } } -impl std::fmt::Display for AnnotatedSource<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl fmt::Display for AnnotatedSource<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { if let Some(package) = &self.package { write!(f, "{} @ {}", package, self.path().simplified_display()) } else { diff --git a/crates/uv/src/commands/help.rs b/crates/uv/src/commands/help.rs index 954f36a420ae..e67c8239f475 100644 --- a/crates/uv/src/commands/help.rs +++ b/crates/uv/src/commands/help.rs @@ -140,7 +140,7 @@ impl PagerKind { } } -impl std::fmt::Display for PagerKind { +impl Display for PagerKind { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { Self::Less => write!(f, "less"), diff --git a/crates/uv/src/commands/python/list.rs b/crates/uv/src/commands/python/list.rs index 8c49ef8ebe29..899028801d4a 100644 --- a/crates/uv/src/commands/python/list.rs +++ b/crates/uv/src/commands/python/list.rs @@ -66,7 +66,7 @@ pub(crate) async fn list( let downloads = download_request .as_ref() - .map(uv_python::downloads::PythonDownloadRequest::iter_downloads) + .map(PythonDownloadRequest::iter_downloads) .into_iter() .flatten(); diff --git a/crates/uv/src/settings.rs b/crates/uv/src/settings.rs index 2e677eeabf4a..80ac58595436 100644 --- a/crates/uv/src/settings.rs +++ b/crates/uv/src/settings.rs @@ -790,7 +790,7 @@ impl PythonInstallSettings { /// Resolve the [`PythonInstallSettings`] from the CLI and filesystem configuration. #[allow(clippy::needless_pass_by_value)] pub(crate) fn resolve(args: PythonInstallArgs, filesystem: Option) -> Self { - let options = filesystem.map(uv_settings::FilesystemOptions::into_options); + let options = filesystem.map(FilesystemOptions::into_options); let (python_mirror, pypy_mirror) = match options { Some(options) => ( options.install_mirrors.python_install_mirror, diff --git a/crates/uv/tests/it/common/mod.rs b/crates/uv/tests/it/common/mod.rs index 7d653a1ab38c..b34a6faaf585 100644 --- a/crates/uv/tests/it/common/mod.rs +++ b/crates/uv/tests/it/common/mod.rs @@ -291,7 +291,7 @@ impl TestContext { // The workspace root directory is not available without walking up the tree // https://github.com/rust-lang/cargo/issues/3946 - let workspace_root = Path::new(&std::env::var(EnvVars::CARGO_MANIFEST_DIR).unwrap()) + let workspace_root = Path::new(&env::var(EnvVars::CARGO_MANIFEST_DIR).unwrap()) .parent() .expect("CARGO_MANIFEST_DIR should be nested in workspace") .parent() @@ -672,7 +672,7 @@ impl TestContext { .env(EnvVars::UV_PYTHON_BIN_DIR, bin.as_os_str()) .env( EnvVars::PATH, - std::env::join_paths(std::iter::once(bin).chain(std::env::split_paths( + env::join_paths(std::iter::once(bin).chain(env::split_paths( &env::var(EnvVars::PATH).unwrap_or_default(), ))) .unwrap(), @@ -892,7 +892,7 @@ impl TestContext { pub fn python_path(&self) -> OsString { if cfg!(unix) { // On Unix, we needed to normalize the Python executable names to `python3` for the tests - std::env::join_paths( + env::join_paths( self.python_versions .iter() .map(|(version, _)| self.python_dir.join(version.to_string())), @@ -900,7 +900,7 @@ impl TestContext { .unwrap() } else { // On Windows, just join the parent directories of the executables - std::env::join_paths( + env::join_paths( self.python_versions .iter() .map(|(_, executable)| executable.parent().unwrap().to_path_buf()), @@ -988,7 +988,7 @@ impl TestContext { change(self), self.filters(), "diff_lock", - Some(crate::common::WindowsFilters::Platform), + Some(WindowsFilters::Platform), ); assert!(status.success(), "{snapshot}"); let new_lock = fs_err::read_to_string(&lock_path).unwrap(); @@ -1097,11 +1097,7 @@ pub fn get_python(version: &PythonVersion) -> PathBuf { } /// Create a virtual environment at the given path. -pub fn create_venv_from_executable>( - path: P, - cache_dir: &ChildPath, - python: &Path, -) { +pub fn create_venv_from_executable>(path: P, cache_dir: &ChildPath, python: &Path) { assert_cmd::Command::new(get_bin()) .arg("venv") .arg(path.as_ref().as_os_str()) @@ -1129,7 +1125,7 @@ pub fn python_path_with_versions( temp_dir: &ChildPath, python_versions: &[&str], ) -> anyhow::Result { - Ok(std::env::join_paths( + Ok(env::join_paths( python_installations_for_versions(temp_dir, python_versions)? .into_iter() .map(|path| path.parent().unwrap().to_path_buf()), @@ -1371,7 +1367,7 @@ pub fn decode_token(content: &[&str]) -> String { /// certificate verification, passing through the `BaseClient` #[tokio::main(flavor = "current_thread")] pub async fn download_to_disk(url: &str, path: &Path) { - let trusted_hosts: Vec<_> = std::env::var(EnvVars::UV_INSECURE_HOST) + let trusted_hosts: Vec<_> = env::var(EnvVars::UV_INSECURE_HOST) .unwrap_or_default() .split(' ') .map(|h| uv_configuration::TrustedHost::from_str(h).unwrap()) diff --git a/crates/uv/tests/it/pip_compile.rs b/crates/uv/tests/it/pip_compile.rs index 7b4739882b03..1a6de326ad07 100644 --- a/crates/uv/tests/it/pip_compile.rs +++ b/crates/uv/tests/it/pip_compile.rs @@ -12686,7 +12686,7 @@ fn tool_uv_sources() -> Result<()> { poetry_editable = { path = "../poetry_editable", editable = true } "#})?; - let project_root = fs_err::canonicalize(std::env::current_dir()?.join("../.."))?; + let project_root = fs_err::canonicalize(current_dir()?.join("../.."))?; fs_err::create_dir_all(context.temp_dir.join("poetry_editable/poetry_editable"))?; fs_err::copy( project_root.join("scripts/packages/poetry_editable/pyproject.toml"), diff --git a/crates/uv/tests/it/python_find.rs b/crates/uv/tests/it/python_find.rs index 5a194dfc21ab..4eeb73be704e 100644 --- a/crates/uv/tests/it/python_find.rs +++ b/crates/uv/tests/it/python_find.rs @@ -1,6 +1,5 @@ use assert_fs::prelude::PathChild; use assert_fs::{fixture::FileWriteStr, prelude::PathCreateDir}; -use fs_err::remove_dir_all; use indoc::indoc; use uv_python::platform::{Arch, Os}; @@ -450,7 +449,7 @@ fn python_find_venv() { "###); // But if we delete the parent virtual environment - remove_dir_all(context.temp_dir.child(".venv")).unwrap(); + fs_err::remove_dir_all(context.temp_dir.child(".venv")).unwrap(); // And query from there... we should not find the child virtual environment uv_snapshot!(context.filters(), context.python_find(), @r###" diff --git a/crates/uv/tests/it/python_pin.rs b/crates/uv/tests/it/python_pin.rs index 67a5ff255cf3..c814b83d4d09 100644 --- a/crates/uv/tests/it/python_pin.rs +++ b/crates/uv/tests/it/python_pin.rs @@ -217,7 +217,7 @@ fn python_pin_no_python() { } #[test] -fn python_pin_compatible_with_requires_python() -> anyhow::Result<()> { +fn python_pin_compatible_with_requires_python() -> Result<()> { let context: TestContext = TestContext::new_with_versions(&["3.10", "3.11"]).with_filtered_python_sources(); let pyproject_toml = context.temp_dir.child("pyproject.toml"); @@ -388,7 +388,7 @@ fn python_pin_compatible_with_requires_python() -> anyhow::Result<()> { } #[test] -fn warning_pinned_python_version_not_installed() -> anyhow::Result<()> { +fn warning_pinned_python_version_not_installed() -> Result<()> { let context: TestContext = TestContext::new_with_versions(&["3.10", "3.11"]); let pyproject_toml = context.temp_dir.child("pyproject.toml"); pyproject_toml.write_str(