From 0be5c8020247b8716e2d93a8f140841557af56ca Mon Sep 17 00:00:00 2001 From: Tom Dyas Date: Fri, 28 Feb 2025 09:08:02 -0500 Subject: [PATCH] `cargo fmt` with 2024 rustfmt edition (#22019) As of Rust 2024 Edition, `rustfmt` can be bumped to the new edition's formatting rules before moving the crates' code to the new edition. This PR does just that by adding a `rustfmt.toml` with the applicable configuration. This should help minimize `fmt`-related churn when porting crates to 2024 Edition. --- src/rust/engine/client/src/main.rs | 2 +- .../src/javascript/import_pattern.rs | 2 +- .../dep_inference/src/javascript/mod.rs | 6 +- .../dep_inference/src/javascript/tests.rs | 6 +- .../engine/dep_inference/src/python/tests.rs | 2 +- src/rust/engine/fs/brfs/src/main.rs | 6 +- src/rust/engine/fs/brfs/src/tests.rs | 12 ++- src/rust/engine/fs/fs_util/src/main.rs | 4 +- src/rust/engine/fs/src/directory.rs | 16 ++- src/rust/engine/fs/src/directory_tests.rs | 2 +- src/rust/engine/fs/src/glob_matching.rs | 10 +- src/rust/engine/fs/src/lib.rs | 42 ++++---- src/rust/engine/fs/store/benches/store.rs | 2 +- .../engine/fs/store/src/immutable_inputs.rs | 4 +- src/rust/engine/fs/store/src/lib.rs | 34 +++---- src/rust/engine/fs/store/src/local.rs | 12 +-- src/rust/engine/fs/store/src/remote.rs | 4 +- src/rust/engine/fs/store/src/remote_tests.rs | 2 +- src/rust/engine/fs/store/src/snapshot.rs | 6 +- src/rust/engine/fs/store/src/snapshot_ops.rs | 4 +- .../engine/fs/store/src/snapshot_ops_tests.rs | 2 +- .../engine/fs/store/src/snapshot_tests.rs | 2 +- src/rust/engine/fs/store/src/tests.rs | 12 +-- src/rust/engine/graph/src/context.rs | 4 +- src/rust/engine/graph/src/entry.rs | 2 +- src/rust/engine/graph/src/lib.rs | 2 +- src/rust/engine/graph/src/tests.rs | 20 ++-- src/rust/engine/grpc_util/src/channel.rs | 6 +- src/rust/engine/grpc_util/src/headers.rs | 2 +- src/rust/engine/grpc_util/src/lib.rs | 8 +- src/rust/engine/grpc_util/src/metrics.rs | 4 +- src/rust/engine/grpc_util/src/retry.rs | 2 +- src/rust/engine/grpc_util/src/tls.rs | 8 +- src/rust/engine/hashing/src/digest_tests.rs | 2 +- .../engine/hashing/src/fingerprint_tests.rs | 2 +- src/rust/engine/logging/src/logger.rs | 2 +- src/rust/engine/nailgun/src/client.rs | 8 +- src/rust/engine/nailgun/src/lib.rs | 2 +- src/rust/engine/nailgun/src/server.rs | 6 +- src/rust/engine/nailgun/src/tests.rs | 4 +- src/rust/engine/options/src/arg_splitter.rs | 10 +- .../engine/options/src/arg_splitter_tests.rs | 4 +- src/rust/engine/options/src/cli_alias.rs | 3 +- .../engine/options/src/cli_alias_tests.rs | 22 +++-- src/rust/engine/options/src/config.rs | 2 +- src/rust/engine/options/src/config_tests.rs | 6 +- src/rust/engine/options/src/env.rs | 2 +- src/rust/engine/options/src/env_tests.rs | 13 +-- src/rust/engine/options/src/flags.rs | 10 +- src/rust/engine/options/src/flags_tests.rs | 30 +++--- src/rust/engine/options/src/fromfile.rs | 4 +- src/rust/engine/options/src/fromfile_tests.rs | 7 +- src/rust/engine/options/src/tests.rs | 4 +- src/rust/engine/pantsd/src/lib.rs | 2 +- .../process_execution/docker/src/docker.rs | 61 ++++++------ .../docker/src/docker_tests.rs | 6 +- .../process_execution/pe_nailgun/src/lib.rs | 6 +- .../pe_nailgun/src/nailgun_pool.rs | 2 +- .../process_execution/remote/src/remote.rs | 49 +++++----- .../remote/src/remote_cache.rs | 20 ++-- .../remote/src/remote_cache_tests.rs | 46 +++++---- .../remote/src/remote_tests.rs | 12 ++- .../engine/process_execution/src/bounded.rs | 6 +- .../process_execution/src/bounded_tests.rs | 2 +- .../engine/process_execution/src/cache.rs | 8 +- .../process_execution/src/cache_tests.rs | 28 +++--- .../engine/process_execution/src/children.rs | 11 ++- .../engine/process_execution/src/fork_exec.rs | 10 +- src/rust/engine/process_execution/src/lib.rs | 21 ++-- .../engine/process_execution/src/local.rs | 10 +- .../process_execution/src/local_tests.rs | 13 +-- .../process_execution/src/named_caches.rs | 12 +-- .../engine/process_execution/src/switched.rs | 2 +- .../engine/process_execution/src/tests.rs | 6 +- .../engine/process_execution/src/workspace.rs | 6 +- .../process_execution/src/workspace_tests.rs | 5 +- src/rust/engine/process_executor/src/main.rs | 10 +- src/rust/engine/protos/src/hashing.rs | 2 +- src/rust/engine/protos/src/lib.rs | 10 +- src/rust/engine/protos/src/verification.rs | 4 +- .../src/byte_store_tests.rs | 24 +++-- .../remote_provider_opendal/src/lib.rs | 2 +- .../remote_provider_reapi/src/action_cache.rs | 4 +- .../remote_provider_reapi/src/byte_store.rs | 7 +- .../remote_provider_reapi/src/lib.rs | 2 +- src/rust/engine/rule_graph/src/builder.rs | 97 ++++++++++--------- src/rust/engine/rule_graph/src/lib.rs | 10 +- src/rust/engine/rule_graph/src/rules.rs | 14 +-- src/rust/engine/rule_graph/src/tests.rs | 74 ++++++++------ src/rust/engine/rustfmt.toml | 1 + src/rust/engine/sharded_lmdb/src/lib.rs | 6 +- src/rust/engine/sharded_lmdb/src/tests.rs | 2 +- src/rust/engine/src/context.rs | 12 +-- src/rust/engine/src/downloads.rs | 14 +-- src/rust/engine/src/externs/address.rs | 18 ++-- src/rust/engine/src/externs/dep_inference.rs | 2 +- src/rust/engine/src/externs/engine_aware.rs | 2 +- src/rust/engine/src/externs/fs.rs | 8 +- src/rust/engine/src/externs/interface.rs | 18 ++-- src/rust/engine/src/externs/mod.rs | 14 +-- src/rust/engine/src/externs/options.rs | 10 +- .../engine/src/intrinsics/dep_inference.rs | 12 +-- src/rust/engine/src/intrinsics/digests.rs | 12 +-- src/rust/engine/src/intrinsics/docker.rs | 6 +- .../src/intrinsics/interactive_process.rs | 10 +- src/rust/engine/src/intrinsics/process.rs | 4 +- src/rust/engine/src/intrinsics/values.rs | 4 +- src/rust/engine/src/nodes/downloaded_file.rs | 2 +- src/rust/engine/src/nodes/execute_process.rs | 6 +- src/rust/engine/src/nodes/mod.rs | 17 ++-- src/rust/engine/src/nodes/snapshot.rs | 6 +- src/rust/engine/src/nodes/task.rs | 8 +- src/rust/engine/src/python.rs | 26 ++--- src/rust/engine/src/scheduler.rs | 2 +- src/rust/engine/src/session.rs | 4 +- src/rust/engine/stdio/src/lib.rs | 2 +- .../testutil/mock/src/action_cache_service.rs | 4 +- src/rust/engine/testutil/mock/src/cas.rs | 2 +- .../engine/testutil/mock/src/cas_service.rs | 18 ++-- .../testutil/mock/src/execution_server.rs | 49 +++++----- src/rust/engine/tryfuture/src/lib.rs | 2 +- src/rust/engine/ui/src/instance.rs | 2 +- src/rust/engine/ui/src/instance/indicatif.rs | 4 +- src/rust/engine/ui/src/instance/prodash.rs | 8 +- src/rust/engine/watch/src/lib.rs | 6 +- src/rust/engine/watch/src/tests.rs | 8 +- src/rust/engine/workunit_store/src/lib.rs | 12 +-- 127 files changed, 695 insertions(+), 647 deletions(-) create mode 100644 src/rust/engine/rustfmt.toml diff --git a/src/rust/engine/client/src/main.rs b/src/rust/engine/client/src/main.rs index 9767be503b5..c97637fa51c 100644 --- a/src/rust/engine/client/src/main.rs +++ b/src/rust/engine/client/src/main.rs @@ -13,7 +13,7 @@ use nix::unistd::execv; use strum::VariantNames; use strum_macros::{AsRefStr, EnumString, VariantNames}; -use options::{option_id, render_choice, Args, BuildRoot, Env, OptionParser}; +use options::{Args, BuildRoot, Env, OptionParser, option_id, render_choice}; use pantsd::find_pantsd; // TODO(John Sirois): Maybe consolidate with PythonLogLevel in src/rust/engine/logging/src/lib.rs. diff --git a/src/rust/engine/dep_inference/src/javascript/import_pattern.rs b/src/rust/engine/dep_inference/src/javascript/import_pattern.rs index 709906bffec..ecbf351d19f 100644 --- a/src/rust/engine/dep_inference/src/javascript/import_pattern.rs +++ b/src/rust/engine/dep_inference/src/javascript/import_pattern.rs @@ -1,6 +1,6 @@ // Copyright 2023 Pants project contributors (see CONTRIBUTORS.md). // Licensed under the Apache License, Version 2.0 (see LICENSE). -use std::iter::{once, Once}; +use std::iter::{Once, once}; use std::ops::Deref; use std::option::Option; use std::path::Path; diff --git a/src/rust/engine/dep_inference/src/javascript/mod.rs b/src/rust/engine/dep_inference/src/javascript/mod.rs index 53b00f9e178..4094aff4cc9 100644 --- a/src/rust/engine/dep_inference/src/javascript/mod.rs +++ b/src/rust/engine/dep_inference/src/javascript/mod.rs @@ -1,6 +1,6 @@ // Copyright 2023 Pants project contributors (see CONTRIBUTORS.md). // Licensed under the Apache License, Version 2.0 (see LICENSE). -use std::iter::{once, Once}; +use std::iter::{Once, once}; use std::path::{Path, PathBuf}; use fnv::{FnvBuildHasher, FnvHashMap as HashMap, FnvHashSet as HashSet}; @@ -10,10 +10,10 @@ use tree_sitter::{Node, Parser}; use crate::code; use protos::gen::pants::cache::{ - javascript_inference_metadata::ImportPattern, JavascriptInferenceMetadata, + JavascriptInferenceMetadata, javascript_inference_metadata::ImportPattern, }; -use crate::javascript::import_pattern::{imports_from_patterns, Import}; +use crate::javascript::import_pattern::{Import, imports_from_patterns}; use crate::javascript::util::normalize_path; mod import_pattern; diff --git a/src/rust/engine/dep_inference/src/javascript/tests.rs b/src/rust/engine/dep_inference/src/javascript/tests.rs index 21a649b5390..b4eb73ef6ac 100644 --- a/src/rust/engine/dep_inference/src/javascript/tests.rs +++ b/src/rust/engine/dep_inference/src/javascript/tests.rs @@ -4,10 +4,10 @@ use std::collections::{HashMap, HashSet}; use std::path::{Path, PathBuf}; -use crate::javascript::import_pattern::{imports_from_patterns, Import, Pattern, StarMatch}; -use crate::javascript::{get_dependencies, ImportCollector, JavascriptImportInfo}; +use crate::javascript::import_pattern::{Import, Pattern, StarMatch, imports_from_patterns}; +use crate::javascript::{ImportCollector, JavascriptImportInfo, get_dependencies}; use javascript_inference_metadata::ImportPattern; -use protos::gen::pants::cache::{javascript_inference_metadata, JavascriptInferenceMetadata}; +use protos::gen::pants::cache::{JavascriptInferenceMetadata, javascript_inference_metadata}; fn assert_imports(code: &str, imports: &[&str]) { let mut collector = ImportCollector::new(code); diff --git a/src/rust/engine/dep_inference/src/python/tests.rs b/src/rust/engine/dep_inference/src/python/tests.rs index 07da43bb2e4..39b2b7c1aef 100644 --- a/src/rust/engine/dep_inference/src/python/tests.rs +++ b/src/rust/engine/dep_inference/src/python/tests.rs @@ -1,6 +1,6 @@ // Copyright 2023 Pants project contributors (see CONTRIBUTORS.md). // Licensed under the Apache License, Version 2.0 (see LICENSE). -use crate::python::{get_dependencies, ImportCollector}; +use crate::python::{ImportCollector, get_dependencies}; use std::collections::{HashMap, HashSet}; use std::path::PathBuf; diff --git a/src/rust/engine/fs/brfs/src/main.rs b/src/rust/engine/fs/brfs/src/main.rs index a9a0eca50d6..c691dad5ab3 100644 --- a/src/rust/engine/fs/brfs/src/main.rs +++ b/src/rust/engine/fs/brfs/src/main.rs @@ -7,8 +7,8 @@ use std::collections::hash_map::Entry::{Occupied, Vacant}; use std::collections::{BTreeMap, HashMap}; use std::ffi::{OsStr, OsString}; use std::path::Path; -use std::sync::mpsc::{channel, Receiver, Sender}; use std::sync::Arc; +use std::sync::mpsc::{Receiver, Sender, channel}; use std::time; use clap::{Arg, Command}; @@ -20,10 +20,10 @@ use parking_lot::Mutex; use protos::gen::build::bazel::remote::execution::v2 as remexec; use protos::require_digest; use store::{RemoteProvider, RemoteStoreOptions, Store, StoreError}; -use tokio::signal::unix::{signal, SignalKind}; +use tokio::signal::unix::{SignalKind, signal}; use tokio::task; -use tokio_stream::wrappers::SignalStream; use tokio_stream::StreamExt; +use tokio_stream::wrappers::SignalStream; const TTL: time::Duration = time::Duration::from_secs(0); diff --git a/src/rust/engine/fs/brfs/src/tests.rs b/src/rust/engine/fs/brfs/src/tests.rs index 30e58f48911..37c82f45dcc 100644 --- a/src/rust/engine/fs/brfs/src/tests.rs +++ b/src/rust/engine/fs/brfs/src/tests.rs @@ -21,11 +21,13 @@ async fn missing_digest() { Store::local_only(runtime.clone(), store_dir.path()).expect("Error creating local store"); let _fs = mount(mount_dir.path(), store, runtime).expect("Mounting"); - assert!(!&mount_dir - .path() - .join("digest") - .join(digest_to_filepath(&TestData::roland().digest())) - .exists()); + assert!( + !&mount_dir + .path() + .join("digest") + .join(digest_to_filepath(&TestData::roland().digest())) + .exists() + ); } #[tokio::test] diff --git a/src/rust/engine/fs/fs_util/src/main.rs b/src/rust/engine/fs/fs_util/src/main.rs index 3ef04c8a127..cc28bba48f3 100644 --- a/src/rust/engine/fs/fs_util/src/main.rs +++ b/src/rust/engine/fs/fs_util/src/main.rs @@ -15,8 +15,8 @@ use fs::{ DirectoryDigest, GlobExpansionConjunction, GlobMatching, Permissions, PreparedPathGlobs, RelativePath, StrictGlobMatching, SymlinkBehavior, }; -use futures::future::{self, BoxFuture}; use futures::FutureExt; +use futures::future::{self, BoxFuture}; use grpc_util::prost::MessageExt; use grpc_util::tls::CertificateCheck; use hashing::{Digest, Fingerprint}; @@ -650,7 +650,7 @@ async fn execute(top_match: &clap::ArgMatches) -> Result<(), ExitError> { format => { return Err( format!("Unexpected value of --output-format arg: {format}").into() - ) + ); } }; diff --git a/src/rust/engine/fs/src/directory.rs b/src/rust/engine/fs/src/directory.rs index f76d6de1f04..e642b47973a 100644 --- a/src/rust/engine/fs/src/directory.rs +++ b/src/rust/engine/fs/src/directory.rs @@ -10,7 +10,7 @@ use std::path::{Component, Path, PathBuf}; use std::sync::Arc; use std::sync::LazyLock; -use deepsize::{known_deep_size, DeepSizeOf}; +use deepsize::{DeepSizeOf, known_deep_size}; use internment::Intern; use itertools::Itertools; use log::warn; @@ -22,7 +22,7 @@ use hashing::{Digest, EMPTY_DIGEST}; use protos::gen::build::bazel::remote::execution::v2 as remexec; use protos::require_digest; -use crate::{LinkDepth, PathStat, RelativePath, MAX_LINK_DEPTH}; +use crate::{LinkDepth, MAX_LINK_DEPTH, PathStat, RelativePath}; pub static EMPTY_DIGEST_TREE: LazyLock = LazyLock::new(|| DigestTrie(vec![].into())); pub static EMPTY_DIRECTORY_DIGEST: LazyLock = LazyLock::new(|| DirectoryDigest { @@ -656,7 +656,10 @@ impl DigestTrie { break; } } - warn!("Exceeded the maximum link depth while traversing link {:#?} to path {:#?}. Stopping traversal.", logical_path, s.target); + warn!( + "Exceeded the maximum link depth while traversing link {:#?} to path {:#?}. Stopping traversal.", + logical_path, s.target + ); return; } self.walk_helper(root, path.clone(), symlink_behavior, link_depth, f); @@ -885,7 +888,7 @@ impl DigestTrie { String::new() }, format_entries(&extra_directories, &files, &symlinks), - )) + )); } (Some(d), true) => { already_stripped = already_stripped.join(component_to_strip); @@ -964,7 +967,10 @@ impl DigestTrie { if let Some(Entry::Symlink(s)) = maybe_matching_entry { if link_depth >= MAX_LINK_DEPTH { - warn!("Exceeded the maximum link depth while traversing link {:#?} to path {:#?}. Stopping traversal.", logical_path, s.target); + warn!( + "Exceeded the maximum link depth while traversing link {:#?} to path {:#?}. Stopping traversal.", + logical_path, s.target + ); return Ok(None); } diff --git a/src/rust/engine/fs/src/directory_tests.rs b/src/rust/engine/fs/src/directory_tests.rs index 8a9acdb41cc..db87a9f02b8 100644 --- a/src/rust/engine/fs/src/directory_tests.rs +++ b/src/rust/engine/fs/src/directory_tests.rs @@ -3,8 +3,8 @@ use std::collections::HashMap; -use crate::directory::{DigestTrie, Entry, Name, TypedPath}; use crate::MAX_LINK_DEPTH; +use crate::directory::{DigestTrie, Entry, Name, TypedPath}; use hashing::EMPTY_DIGEST; use std::path::{Path, PathBuf}; diff --git a/src/rust/engine/fs/src/glob_matching.rs b/src/rust/engine/fs/src/glob_matching.rs index c3967c41740..4d9652f5be1 100644 --- a/src/rust/engine/fs/src/glob_matching.rs +++ b/src/rust/engine/fs/src/glob_matching.rs @@ -17,8 +17,8 @@ use log::warn; use parking_lot::Mutex; use crate::{ - Dir, GitignoreStyleExcludes, GlobExpansionConjunction, Link, LinkDepth, PathStat, Stat, - StrictGlobMatching, SymlinkBehavior, Vfs, MAX_LINK_DEPTH, + Dir, GitignoreStyleExcludes, GlobExpansionConjunction, Link, LinkDepth, MAX_LINK_DEPTH, + PathStat, Stat, StrictGlobMatching, SymlinkBehavior, Vfs, }; static DOUBLE_STAR: &str = "**"; @@ -532,11 +532,7 @@ trait GlobMatchingImplementation: Vfs { .zip(matched) .filter_map( |(source, matched)| { - if matched { - Some(source.clone()) - } else { - None - } + if matched { Some(source.clone()) } else { None } }, ) .collect::>(); diff --git a/src/rust/engine/fs/src/lib.rs b/src/rust/engine/fs/src/lib.rs index 69d581dfdbb..b4896ea0c78 100644 --- a/src/rust/engine/fs/src/lib.rs +++ b/src/rust/engine/fs/src/lib.rs @@ -14,12 +14,12 @@ mod posixfs_tests; mod testutil; pub use crate::directory::{ - DigestTrie, DirectoryDigest, Entry, SymlinkBehavior, TypedPath, EMPTY_DIGEST_TREE, - EMPTY_DIRECTORY_DIGEST, + DigestTrie, DirectoryDigest, EMPTY_DIGEST_TREE, EMPTY_DIRECTORY_DIGEST, Entry, SymlinkBehavior, + TypedPath, }; pub use crate::gitignore::GitignoreStyleExcludes; pub use crate::glob_matching::{ - FilespecMatcher, GlobMatching, PathGlob, PreparedPathGlobs, DOUBLE_STAR_GLOB, SINGLE_STAR_GLOB, + DOUBLE_STAR_GLOB, FilespecMatcher, GlobMatching, PathGlob, PreparedPathGlobs, SINGLE_STAR_GLOB, }; use std::cmp::min; @@ -81,10 +81,10 @@ impl RelativePath { for component in candidate.components() { match component { Component::Prefix(_) => { - return Err(format!("Windows paths are not allowed: {candidate:?}")) + return Err(format!("Windows paths are not allowed: {candidate:?}")); } Component::RootDir => { - return Err(format!("Absolute paths are not allowed: {candidate:?}")) + return Err(format!("Absolute paths are not allowed: {candidate:?}")); } Component::CurDir => continue, Component::ParentDir => { @@ -544,11 +544,11 @@ impl PosixFS { }; if cfg!(debug_assertions) && !path_to_stat.is_absolute() { return Err(io::Error::new( - io::ErrorKind::InvalidInput, - format!( - "Argument path_to_stat to PosixFS::stat_internal must be absolute path, got {path_to_stat:?}" - ), - )); + io::ErrorKind::InvalidInput, + format!( + "Argument path_to_stat to PosixFS::stat_internal must be absolute path, got {path_to_stat:?}" + ), + )); } let path = file_name.to_owned().into(); if file_type.is_symlink() { @@ -579,11 +579,11 @@ impl PosixFS { pub fn stat_sync(&self, relative_path: &Path) -> Result, io::Error> { if cfg!(debug_assertions) && relative_path.is_absolute() { return Err(io::Error::new( - io::ErrorKind::InvalidInput, - format!( - "Argument relative_path to PosixFS::stat_sync must be relative path, got {relative_path:?}" - ), - )); + io::ErrorKind::InvalidInput, + format!( + "Argument relative_path to PosixFS::stat_sync must be relative path, got {relative_path:?}" + ), + )); } let abs_path = self.root.0.join(relative_path); let metadata = match self.symlink_behavior { @@ -672,14 +672,14 @@ impl Vfs for DigestTrie { return Err(format!( "Path `{}` was a file rather than a symlink.", link.path.display() - )) + )); } directory::Entry::Symlink(s) => s.target(), directory::Entry::Directory(_) => { return Err(format!( "Path `{}` was a directory rather than a symlink.", link.path.display() - )) + )); } }; Ok(target.to_path_buf()) @@ -699,13 +699,13 @@ impl Vfs for DigestTrie { return Err(format!( "Path `{}` was a file rather than a directory.", dir.0.display() - )) + )); } directory::Entry::Symlink(_) => { return Err(format!( "Path `{}` was a symlink rather than a directory.", dir.0.display() - )) + )); } directory::Entry::Directory(d) => d.tree().entries(), } @@ -861,10 +861,10 @@ pub fn increase_limits() -> Result { // If the limit is less than our target. if cur < TARGET_NOFILE_LIMIT { let err_suffix = format!( - "To avoid 'too many open file handle' errors, we recommend a limit of at least {TARGET_NOFILE_LIMIT}: \ + "To avoid 'too many open file handle' errors, we recommend a limit of at least {TARGET_NOFILE_LIMIT}: \ please see https://www.pantsbuild.org/docs/troubleshooting#too-many-open-files-error \ for more information." - ); + ); // If we might be able to increase the soft limit, try to. if cur < max { let target_soft_limit = std::cmp::min(max, TARGET_NOFILE_LIMIT); diff --git a/src/rust/engine/fs/store/benches/store.rs b/src/rust/engine/fs/store/benches/store.rs index aa3b18eaec8..de98379e1f9 100644 --- a/src/rust/engine/fs/store/benches/store.rs +++ b/src/rust/engine/fs/store/benches/store.rs @@ -1,7 +1,7 @@ // Copyright 2020 Pants project contributors (see CONTRIBUTORS.md). // Licensed under the Apache License, Version 2.0 (see LICENSE). -use criterion::{criterion_group, criterion_main, Criterion}; +use criterion::{Criterion, criterion_group, criterion_main}; use std::collections::{BTreeSet, HashSet}; use std::io::{BufRead, BufReader, BufWriter, Write}; diff --git a/src/rust/engine/fs/store/src/immutable_inputs.rs b/src/rust/engine/fs/store/src/immutable_inputs.rs index 1b7740f0040..efa6c60c5df 100644 --- a/src/rust/engine/fs/store/src/immutable_inputs.rs +++ b/src/rust/engine/fs/store/src/immutable_inputs.rs @@ -96,9 +96,9 @@ impl ImmutableInputs { cell.get_or_try_init(async { let chroot = TempDir::new_in(self.0.workdir.path()).map_err(|e| { format!( - "Failed to create a temporary directory for materialization of immutable input \ + "Failed to create a temporary directory for materialization of immutable input \ digest {digest:?}: {e}" - ) + ) })?; let dest = chroot.path().join(digest.hash.to_hex()); diff --git a/src/rust/engine/fs/store/src/lib.rs b/src/rust/engine/fs/store/src/lib.rs index d3631c91a15..4643ca076e8 100644 --- a/src/rust/engine/fs/store/src/lib.rs +++ b/src/rust/engine/fs/store/src/lib.rs @@ -29,9 +29,9 @@ use async_oncecell::OnceCell; use async_trait::async_trait; use bytes::Bytes; use fs::{ - default_cache_path, directory, DigestEntry, DigestTrie, Dir, DirectoryDigest, File, - FileContent, FileEntry, Link, PathStat, Permissions, RelativePath, SymlinkBehavior, - SymlinkEntry, EMPTY_DIRECTORY_DIGEST, + DigestEntry, DigestTrie, Dir, DirectoryDigest, EMPTY_DIRECTORY_DIGEST, File, FileContent, + FileEntry, Link, PathStat, Permissions, RelativePath, SymlinkBehavior, SymlinkEntry, + default_cache_path, directory, }; use futures::future::{self, BoxFuture, Either, FutureExt, TryFutureExt}; use grpc_util::prost::MessageExt; @@ -50,7 +50,7 @@ use tokio::fs::copy; use tokio::fs::hard_link; use tokio::fs::symlink; use tryfuture::try_future; -use workunit_store::{in_workunit, Level, Metric}; +use workunit_store::{Level, Metric, in_workunit}; const KILOBYTES: usize = 1024; const MEGABYTES: usize = 1024 * KILOBYTES; @@ -717,15 +717,15 @@ impl Store { .download_digest_to_local(self.local.clone(), digest, entry_type, f_remote) .await?; - Ok( - self - .local - .load_bytes_with(entry_type, digest, f_local) - .await? - .ok_or_else(|| { - format!("After downloading {digest:?}, the local store claimed that it was not present.") - })??, - ) + Ok(self + .local + .load_bytes_with(entry_type, digest, f_local) + .await? + .ok_or_else(|| { + format!( + "After downloading {digest:?}, the local store claimed that it was not present." + ) + })??) } /// @@ -1043,11 +1043,11 @@ impl Store { Ok(size) => { if size > target_size_bytes { log::warn!( - "Garbage collection attempted to shrink the store to {} bytes but {} bytes \ + "Garbage collection attempted to shrink the store to {} bytes but {} bytes \ are currently in use.", - target_size_bytes, - size - ) + target_size_bytes, + size + ) } Ok(()) } diff --git a/src/rust/engine/fs/store/src/local.rs b/src/rust/engine/fs/store/src/local.rs index 925d94a4dcf..d57a9222938 100644 --- a/src/rust/engine/fs/store/src/local.rs +++ b/src/rust/engine/fs/store/src/local.rs @@ -13,7 +13,7 @@ use async_trait::async_trait; use bytes::Bytes; use futures::future::{self, join_all, try_join, try_join_all}; use hashing::{ - async_copy_and_hash, async_verified_copy, AgedFingerprint, Digest, Fingerprint, EMPTY_DIGEST, + AgedFingerprint, Digest, EMPTY_DIGEST, Fingerprint, async_copy_and_hash, async_verified_copy, }; use parking_lot::Mutex; use sharded_lmdb::ShardedLmdb; @@ -950,13 +950,13 @@ impl ByteStore { Ok(f(bytes)) } else { Err(format!( - "Got hash collision reading from store - digest {:?} was requested, but retrieved \ + "Got hash collision reading from store - digest {:?} was requested, but retrieved \ bytes with that fingerprint had length {}. Congratulations, you may have broken \ sha256! Underlying bytes: {:?}", - digest, - bytes.len(), - bytes - )) + digest, + bytes.len(), + bytes + )) } }; diff --git a/src/rust/engine/fs/store/src/remote.rs b/src/rust/engine/fs/store/src/remote.rs index c70aab97cae..8d5cc092517 100644 --- a/src/rust/engine/fs/store/src/remote.rs +++ b/src/rust/engine/fs/store/src/remote.rs @@ -10,10 +10,10 @@ use futures::Future; use hashing::Digest; use log::Level; use remote_provider::{ - choose_byte_store_provider, ByteStoreProvider, LoadDestination, RemoteStoreOptions, + ByteStoreProvider, LoadDestination, RemoteStoreOptions, choose_byte_store_provider, }; use tokio::fs::File; -use workunit_store::{in_workunit, Metric, ObservationMetric}; +use workunit_store::{Metric, ObservationMetric, in_workunit}; #[derive(Clone)] pub struct ByteStore { diff --git a/src/rust/engine/fs/store/src/remote_tests.rs b/src/rust/engine/fs/store/src/remote_tests.rs index 730a90badfc..fbbf3596a3c 100644 --- a/src/rust/engine/fs/store/src/remote_tests.rs +++ b/src/rust/engine/fs/store/src/remote_tests.rs @@ -16,9 +16,9 @@ use tokio::fs::File; use tokio::io::{AsyncReadExt, AsyncSeekExt, AsyncWriteExt}; use workunit_store::WorkunitStore; +use crate::MEGABYTES; use crate::remote::ByteStore; use crate::tests::new_cas; -use crate::MEGABYTES; #[tokio::test] async fn smoke_test_from_options_reapi_provider() { diff --git a/src/rust/engine/fs/store/src/snapshot.rs b/src/rust/engine/fs/store/src/snapshot.rs index d487c037dcd..1462ab79948 100644 --- a/src/rust/engine/fs/store/src/snapshot.rs +++ b/src/rust/engine/fs/store/src/snapshot.rs @@ -9,12 +9,12 @@ use std::path::{Path, PathBuf}; use std::sync::Arc; use deepsize::DeepSizeOf; -use futures::future; use futures::FutureExt; +use futures::future; use fs::{ - DigestTrie, Dir, DirectoryDigest, Entry, File, GitignoreStyleExcludes, GlobMatching, PathStat, - PosixFS, PreparedPathGlobs, SymlinkBehavior, EMPTY_DIGEST_TREE, + DigestTrie, Dir, DirectoryDigest, EMPTY_DIGEST_TREE, Entry, File, GitignoreStyleExcludes, + GlobMatching, PathStat, PosixFS, PreparedPathGlobs, SymlinkBehavior, }; use hashing::{Digest, EMPTY_DIGEST}; diff --git a/src/rust/engine/fs/store/src/snapshot_ops.rs b/src/rust/engine/fs/store/src/snapshot_ops.rs index b040534f1e8..24badcec544 100644 --- a/src/rust/engine/fs/store/src/snapshot_ops.rs +++ b/src/rust/engine/fs/store/src/snapshot_ops.rs @@ -9,8 +9,8 @@ use std::iter::Iterator; use async_trait::async_trait; use bytes::BytesMut; use fs::{ - directory, DigestTrie, DirectoryDigest, GlobMatching, PreparedPathGlobs, RelativePath, - SymlinkBehavior, EMPTY_DIRECTORY_DIGEST, + DigestTrie, DirectoryDigest, EMPTY_DIRECTORY_DIGEST, GlobMatching, PreparedPathGlobs, + RelativePath, SymlinkBehavior, directory, }; use futures::future::{self, FutureExt}; use hashing::Digest; diff --git a/src/rust/engine/fs/store/src/snapshot_ops_tests.rs b/src/rust/engine/fs/store/src/snapshot_ops_tests.rs index 7b55fc4a5d8..5713d07f793 100644 --- a/src/rust/engine/fs/store/src/snapshot_ops_tests.rs +++ b/src/rust/engine/fs/store/src/snapshot_ops_tests.rs @@ -11,8 +11,8 @@ use fs::{ use testutil::make_file; use crate::{ - snapshot_tests::{expand_all_sorted, setup, STR, STR2}, OneOffStoreFileByDigest, Snapshot, SnapshotOps, SubsetParams, + snapshot_tests::{STR, STR2, expand_all_sorted, setup}, }; async fn get_duplicate_rolands( diff --git a/src/rust/engine/fs/store/src/snapshot_tests.rs b/src/rust/engine/fs/store/src/snapshot_tests.rs index 525697bcab5..9d04be0082e 100644 --- a/src/rust/engine/fs/store/src/snapshot_tests.rs +++ b/src/rust/engine/fs/store/src/snapshot_tests.rs @@ -4,7 +4,7 @@ use std::convert::TryInto; use std::path::{Path, PathBuf}; use std::sync::Arc; -use hashing::{Digest, Fingerprint, EMPTY_DIGEST}; +use hashing::{Digest, EMPTY_DIGEST, Fingerprint}; use testutil::data::TestDirectory; use testutil::make_file; diff --git a/src/rust/engine/fs/store/src/tests.rs b/src/rust/engine/fs/store/src/tests.rs index 65c73fe986f..0da45002d4c 100644 --- a/src/rust/engine/fs/store/src/tests.rs +++ b/src/rust/engine/fs/store/src/tests.rs @@ -10,8 +10,8 @@ use testutil::data::{TestData, TestDirectory}; use bytes::Bytes; use fs::{ - DigestEntry, DirectoryDigest, FileEntry, Link, PathStat, Permissions, RelativePath, - EMPTY_DIRECTORY_DIGEST, + DigestEntry, DirectoryDigest, EMPTY_DIRECTORY_DIGEST, FileEntry, Link, PathStat, Permissions, + RelativePath, }; use grpc_util::prost::MessageExt; use grpc_util::tls; @@ -22,8 +22,8 @@ use workunit_store::WorkunitStore; use crate::local::ByteStore; use crate::{ - EntryType, FileContent, RemoteProvider, RemoteStoreOptions, Snapshot, Store, StoreError, - StoreFileByDigest, UploadSummary, MEGABYTES, + EntryType, FileContent, MEGABYTES, RemoteProvider, RemoteStoreOptions, Snapshot, Store, + StoreError, StoreFileByDigest, UploadSummary, }; pub(crate) const STORE_BATCH_API_SIZE_LIMIT: usize = 4 * 1024 * 1024; @@ -1450,8 +1450,8 @@ fn assert_same_digest_entries(left: Vec, right: Vec) { if path_left != path_right { success = false; eprintln!( - "Paths did not match for empty directory at index {index}: {path_left:?}, {path_right:?}" - ); + "Paths did not match for empty directory at index {index}: {path_left:?}, {path_right:?}" + ); } } (l, r) => { diff --git a/src/rust/engine/graph/src/context.rs b/src/rust/engine/graph/src/context.rs index 3b71b314902..1f287ad4f7e 100644 --- a/src/rust/engine/graph/src/context.rs +++ b/src/rust/engine/graph/src/context.rs @@ -2,15 +2,15 @@ // Licensed under the Apache License, Version 2.0 (see LICENSE). use std::ops::Deref; -use std::sync::atomic::{self, AtomicU32, AtomicUsize}; use std::sync::Arc; +use std::sync::atomic::{self, AtomicU32, AtomicUsize}; use parking_lot::Mutex; use workunit_store::RunId; +use crate::Graph; use crate::entry::Generation; use crate::node::{CompoundNode, EntryId, Node, NodeError}; -use crate::Graph; struct InnerContext { context: N::Context, diff --git a/src/rust/engine/graph/src/entry.rs b/src/rust/engine/graph/src/entry.rs index ec58d8ac672..0c707e4c125 100644 --- a/src/rust/engine/graph/src/entry.rs +++ b/src/rust/engine/graph/src/entry.rs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0 (see LICENSE). use std::mem; use std::pin::pin; -use std::sync::{atomic, Arc}; +use std::sync::{Arc, atomic}; use crate::context::{Context, DepState}; use crate::node::{EntryId, Node, NodeError}; diff --git a/src/rust/engine/graph/src/lib.rs b/src/rust/engine/graph/src/lib.rs index 70f86c48316..090089b9101 100644 --- a/src/rust/engine/graph/src/lib.rs +++ b/src/rust/engine/graph/src/lib.rs @@ -19,10 +19,10 @@ use fnv::{FnvHashMap as HashMap, FnvHashSet as HashSet}; use futures::future; use log::info; use parking_lot::Mutex; +use petgraph::Direction; use petgraph::dot; use petgraph::graph::DiGraph; use petgraph::visit::{EdgeRef, VisitMap, Visitable}; -use petgraph::Direction; use task_executor::Executor; use tokio::time::sleep; use workunit_store::RunId; diff --git a/src/rust/engine/graph/src/tests.rs b/src/rust/engine/graph/src/tests.rs index cb7598238f8..fecd24fe147 100644 --- a/src/rust/engine/graph/src/tests.rs +++ b/src/rust/engine/graph/src/tests.rs @@ -4,7 +4,7 @@ use std::cmp; use std::collections::{HashMap, HashSet}; use std::hash::{Hash, Hasher}; use std::sync::atomic::{self, AtomicUsize}; -use std::sync::{mpsc, Arc}; +use std::sync::{Arc, mpsc}; use std::thread; use std::time::{Duration, Instant}; @@ -251,9 +251,9 @@ async fn invalidate_randomly() { } assert!( - max_distinct_context_values > 1, - "In {iterations} iterations, observed a maximum of {max_distinct_context_values} distinct context values." - ); + max_distinct_context_values > 1, + "In {iterations} iterations, observed a maximum of {max_distinct_context_values} distinct context values." + ); } #[tokio::test] @@ -533,11 +533,13 @@ async fn retries() { let sleep_per_invalidation = Duration::from_millis(10); let invalidation_deadline = Instant::now() + Duration::from_secs(1); let graph2 = graph.clone(); - let join_handle = thread::spawn(move || loop { - thread::sleep(sleep_per_invalidation); - graph2.invalidate_from_roots(true, |n| n.id == 0); - if Instant::now() > invalidation_deadline { - break; + let join_handle = thread::spawn(move || { + loop { + thread::sleep(sleep_per_invalidation); + graph2.invalidate_from_roots(true, |n| n.id == 0); + if Instant::now() > invalidation_deadline { + break; + } } }); diff --git a/src/rust/engine/grpc_util/src/channel.rs b/src/rust/engine/grpc_util/src/channel.rs index 8e94e5e953d..cee4d6653e9 100644 --- a/src/rust/engine/grpc_util/src/channel.rs +++ b/src/rust/engine/grpc_util/src/channel.rs @@ -8,7 +8,7 @@ use http::Uri; use hyper::body::Incoming; use hyper_rustls::HttpsConnector; use hyper_util::client::legacy::{ - connect::HttpConnector, Client as HyperClient, Error as HyperClientError, + Client as HyperClient, Error as HyperClientError, connect::HttpConnector, }; use hyper_util::rt::TokioExecutor; use rustls::ClientConfig; @@ -116,14 +116,14 @@ mod tests { use std::path::PathBuf; use std::sync::Arc; - use axum::{routing::get, Router}; + use axum::{Router, routing::get}; use axum_server::tls_rustls::RustlsConfig; use http::{Request, Uri}; use http_body_util::BodyExt; use rustls::{ + ClientConfig, DigitallySignedStruct, RootCertStore, SignatureScheme, client::danger::HandshakeSignatureValid, crypto::{verify_tls12_signature, verify_tls13_signature}, - ClientConfig, DigitallySignedStruct, RootCertStore, SignatureScheme, }; use rustls_pki_types::{CertificateDer, UnixTime}; use tower::ServiceExt; diff --git a/src/rust/engine/grpc_util/src/headers.rs b/src/rust/engine/grpc_util/src/headers.rs index ec009b35be1..410a991e557 100644 --- a/src/rust/engine/grpc_util/src/headers.rs +++ b/src/rust/engine/grpc_util/src/headers.rs @@ -4,8 +4,8 @@ use std::fmt; use std::task::{Context, Poll}; -use http::header::HeaderMap; use http::Request; +use http::header::HeaderMap; use tower_layer::Layer; use tower_service::Service; diff --git a/src/rust/engine/grpc_util/src/lib.rs b/src/rust/engine/grpc_util/src/lib.rs index e1175cc039e..675b1d09c38 100644 --- a/src/rust/engine/grpc_util/src/lib.rs +++ b/src/rust/engine/grpc_util/src/lib.rs @@ -16,11 +16,11 @@ use http::{HeaderMap, HeaderValue}; use hyper::Uri; use itertools::Itertools; use tokio_rustls::rustls::ClientConfig; +use tower::ServiceBuilder; use tower::limit::ConcurrencyLimit; use tower::timeout::{Timeout, TimeoutLayer}; -use tower::ServiceBuilder; use tower_service::Service; -use workunit_store::{increment_counter_if_in_workunit, Metric, ObservationMetric}; +use workunit_store::{Metric, ObservationMetric, increment_counter_if_in_workunit}; use crate::channel::Channel; use crate::headers::{SetRequestHeaders, SetRequestHeadersLayer}; @@ -199,8 +199,8 @@ mod tests { Ok(Response::new(gen::Output {})) } else { Err(Status::invalid_argument(format!( - "user-agent header did not contain expected value: actual={user_agent}" - ))) + "user-agent header did not contain expected value: actual={user_agent}" + ))) } } None => Err(Status::invalid_argument("user-agent header was not set")), diff --git a/src/rust/engine/grpc_util/src/metrics.rs b/src/rust/engine/grpc_util/src/metrics.rs index 6fce1a92947..0aa2e0b00bc 100644 --- a/src/rust/engine/grpc_util/src/metrics.rs +++ b/src/rust/engine/grpc_util/src/metrics.rs @@ -8,13 +8,13 @@ use std::sync::Arc; use std::task::{Context, Poll}; use std::time::Instant; -use futures::ready; use futures::Future; +use futures::ready; use http::{Request, Response}; use pin_project::pin_project; use tower_layer::Layer; use tower_service::Service; -use workunit_store::{record_observation_if_in_workunit, ObservationMetric}; +use workunit_store::{ObservationMetric, record_observation_if_in_workunit}; #[derive(Clone, Debug)] pub struct NetworkMetricsLayer { diff --git a/src/rust/engine/grpc_util/src/retry.rs b/src/rust/engine/grpc_util/src/retry.rs index 9a13f311017..8c3255a3c4b 100644 --- a/src/rust/engine/grpc_util/src/retry.rs +++ b/src/rust/engine/grpc_util/src/retry.rs @@ -4,7 +4,7 @@ use std::time::Duration; use futures::Future; -use rand::{thread_rng, Rng}; +use rand::{Rng, thread_rng}; use tonic::{Code, Status}; pub fn status_is_retryable(status: &Status) -> bool { diff --git a/src/rust/engine/grpc_util/src/tls.rs b/src/rust/engine/grpc_util/src/tls.rs index c7ba4b292c4..e8139e800bc 100644 --- a/src/rust/engine/grpc_util/src/tls.rs +++ b/src/rust/engine/grpc_util/src/tls.rs @@ -5,9 +5,9 @@ use std::io; use std::sync::Arc; use rustls::{ + DigitallySignedStruct, client::danger::{HandshakeSignatureValid, ServerCertVerified, ServerCertVerifier}, crypto::{verify_tls12_signature, verify_tls13_signature}, - DigitallySignedStruct, }; use rustls_pki_types::{CertificateDer, PrivateKeyDer, ServerName, UnixTime}; use tokio_rustls::rustls::{ClientConfig, RootCertStore}; @@ -91,9 +91,11 @@ impl TryFrom for ClientConfig { None => { let native_root_certs_result = rustls_native_certs::load_native_certs(); if !native_root_certs_result.errors.is_empty() { - let mut msg = String::from("Could not discover root CA cert files to use TLS with remote caching and remote \ + let mut msg = String::from( + "Could not discover root CA cert files to use TLS with remote caching and remote \ execution. Consider setting `--remote-ca-certs-path` instead to explicitly point to \ - the correct PEM file. Error(s):\n\n"); + the correct PEM file. Error(s):\n\n", + ); for error in &native_root_certs_result.errors { write!(&mut msg, "{}\n\n", &error) .expect("write into mutable string"); diff --git a/src/rust/engine/hashing/src/digest_tests.rs b/src/rust/engine/hashing/src/digest_tests.rs index 9e528d2ddc1..6fca6aa19e3 100644 --- a/src/rust/engine/hashing/src/digest_tests.rs +++ b/src/rust/engine/hashing/src/digest_tests.rs @@ -1,6 +1,6 @@ // Copyright 2022 Pants project contributors (see CONTRIBUTORS.md). // Licensed under the Apache License, Version 2.0 (see LICENSE). -use self::serde_test::{assert_tokens, Token}; +use self::serde_test::{Token, assert_tokens}; use super::Digest; use super::Fingerprint; use serde_test; diff --git a/src/rust/engine/hashing/src/fingerprint_tests.rs b/src/rust/engine/hashing/src/fingerprint_tests.rs index b3a74262074..b23a42944b8 100644 --- a/src/rust/engine/hashing/src/fingerprint_tests.rs +++ b/src/rust/engine/hashing/src/fingerprint_tests.rs @@ -1,7 +1,7 @@ // Copyright 2022 Pants project contributors (see CONTRIBUTORS.md). // Licensed under the Apache License, Version 2.0 (see LICENSE). use crate::Fingerprint; -use serde_test::{assert_ser_tokens, Token}; +use serde_test::{Token, assert_ser_tokens}; #[test] fn from_bytes_unsafe() { diff --git a/src/rust/engine/logging/src/logger.rs b/src/rust/engine/logging/src/logger.rs index 59a4e72220b..e48e44fae11 100644 --- a/src/rust/engine/logging/src/logger.rs +++ b/src/rust/engine/logging/src/logger.rs @@ -13,7 +13,7 @@ use std::sync::{Arc, LazyLock}; use arc_swap::ArcSwap; use chrono::Timelike; use colored::*; -use log::{debug, log, set_logger, set_max_level, Level, LevelFilter, Log, Metadata, Record}; +use log::{Level, LevelFilter, Log, Metadata, Record, debug, log, set_logger, set_max_level}; use parking_lot::Mutex; use regex::Regex; diff --git a/src/rust/engine/nailgun/src/client.rs b/src/rust/engine/nailgun/src/client.rs index a8b7c551a4e..48585cfce57 100644 --- a/src/rust/engine/nailgun/src/client.rs +++ b/src/rust/engine/nailgun/src/client.rs @@ -5,12 +5,12 @@ use std::io; use std::net::Ipv4Addr; use futures::channel::mpsc; -use futures::{try_join, SinkExt, Stream, StreamExt}; -use nails::execution::{stream_for, ChildInput, ChildOutput, ExitCode}; +use futures::{SinkExt, Stream, StreamExt, try_join}; use nails::Config; +use nails::execution::{ChildInput, ChildOutput, ExitCode, stream_for}; use tokio::io::AsyncWriteExt; use tokio::net::TcpStream; -use tokio::signal::unix::{signal, Signal, SignalKind}; +use tokio::signal::unix::{Signal, SignalKind, signal}; pub enum NailgunClientError { PreConnect(String), @@ -98,7 +98,7 @@ pub async fn client_execute( args: Vec, env: Vec<(String, String)>, ) -> Result { - use nails::execution::{child_channel, Command}; + use nails::execution::{Command, child_channel}; let working_dir = std::env::current_dir().map_err(|e| NailgunClientError::PreConnect(e.to_string()))?; diff --git a/src/rust/engine/nailgun/src/lib.rs b/src/rust/engine/nailgun/src/lib.rs index d7e3969bae7..782b007ba1e 100644 --- a/src/rust/engine/nailgun/src/lib.rs +++ b/src/rust/engine/nailgun/src/lib.rs @@ -7,6 +7,6 @@ mod tests; mod client; mod server; -pub use client::{client_execute, NailgunClientError}; +pub use client::{NailgunClientError, client_execute}; pub use nails::execution::ExitCode; pub use server::{RawFdExecution, Server}; diff --git a/src/rust/engine/nailgun/src/server.rs b/src/rust/engine/nailgun/src/server.rs index c417155d63a..d36d5e16007 100644 --- a/src/rust/engine/nailgun/src/server.rs +++ b/src/rust/engine/nailgun/src/server.rs @@ -13,14 +13,14 @@ use std::sync::Arc; use async_latch::AsyncLatch; use bytes::Bytes; use futures::channel::oneshot; -use futures::{future, sink, stream, FutureExt, SinkExt, StreamExt, TryStreamExt}; +use futures::{FutureExt, SinkExt, StreamExt, TryStreamExt, future, sink, stream}; use log::{debug, info}; -use nails::execution::{self, child_channel, sink_for, ChildInput, ChildOutput, ExitCode}; use nails::Nail; +use nails::execution::{self, ChildInput, ChildOutput, ExitCode, child_channel, sink_for}; use task_executor::Executor; use tokio::fs::File; use tokio::net::TcpListener; -use tokio::sync::{mpsc, Notify, RwLock}; +use tokio::sync::{Notify, RwLock, mpsc}; use tokio_stream::wrappers::UnboundedReceiverStream; pub struct Server { diff --git a/src/rust/engine/nailgun/src/tests.rs b/src/rust/engine/nailgun/src/tests.rs index 91182377805..96c8ed9da6c 100644 --- a/src/rust/engine/nailgun/src/tests.rs +++ b/src/rust/engine/nailgun/src/tests.rs @@ -6,9 +6,9 @@ use std::path::PathBuf; use std::sync::Arc; use std::time::Duration; -use futures::{future, FutureExt}; -use nails::execution::{child_channel, ChildInput, Command, ExitCode}; +use futures::{FutureExt, future}; use nails::Config; +use nails::execution::{ChildInput, Command, ExitCode, child_channel}; use task_executor::Executor; use tokio::net::TcpStream; use tokio::sync::Notify; diff --git a/src/rust/engine/options/src/arg_splitter.rs b/src/rust/engine/options/src/arg_splitter.rs index 20e25e75392..17e5f7e6a1d 100644 --- a/src/rust/engine/options/src/arg_splitter.rs +++ b/src/rust/engine/options/src/arg_splitter.rs @@ -41,11 +41,11 @@ impl Args { pub fn argv() -> Self { let mut args = env::args().collect::>().into_iter(); args.next(); // Consume the process name (argv[0]). - // TODO: In Pants's own integration tests we may invoke Pants in a subprocess via - // `python -m pants` or `python path/to/__main__.py` or similar. So - // skipping argv[0] may not be sufficient to get just the set of args to split. - // In practice our tests pass despite these extra args being interpreted as specs - // or goals, but that is skating on thin ice. + // TODO: In Pants's own integration tests we may invoke Pants in a subprocess via + // `python -m pants` or `python path/to/__main__.py` or similar. So + // skipping argv[0] may not be sufficient to get just the set of args to split. + // In practice our tests pass despite these extra args being interpreted as specs + // or goals, but that is skating on thin ice. Self::new(args.collect::>()) } } diff --git a/src/rust/engine/options/src/arg_splitter_tests.rs b/src/rust/engine/options/src/arg_splitter_tests.rs index b5e0c6e5b35..00608e5451f 100644 --- a/src/rust/engine/options/src/arg_splitter_tests.rs +++ b/src/rust/engine/options/src/arg_splitter_tests.rs @@ -1,10 +1,10 @@ // Copyright 2025 Pants project contributors (see CONTRIBUTORS.md). // Licensed under the Apache License, Version 2.0 (see LICENSE). -use crate::arg_splitter::{ArgSplitter, Args, PantsCommand, NO_GOAL_NAME, UNKNOWN_GOAL_NAME}; +use crate::Scope; +use crate::arg_splitter::{ArgSplitter, Args, NO_GOAL_NAME, PantsCommand, UNKNOWN_GOAL_NAME}; use crate::flags::Flag; use crate::scope::GoalInfo; -use crate::Scope; use shlex; use std::fs::File; use std::path::Path; diff --git a/src/rust/engine/options/src/cli_alias.rs b/src/rust/engine/options/src/cli_alias.rs index b319dea8f01..47c791cafaf 100644 --- a/src/rust/engine/options/src/cli_alias.rs +++ b/src/rust/engine/options/src/cli_alias.rs @@ -34,7 +34,8 @@ fn validate_alias( if args.contains(alias) { return Err(format!( "Invalid alias in `[cli].alias` option: {}. This is already a registered flag in the {} scope.", - alias, Scope::named(scope).name() + alias, + Scope::named(scope).name() )); } } diff --git a/src/rust/engine/options/src/cli_alias_tests.rs b/src/rust/engine/options/src/cli_alias_tests.rs index f0dd8f3ba3e..434803391d6 100644 --- a/src/rust/engine/options/src/cli_alias_tests.rs +++ b/src/rust/engine/options/src/cli_alias_tests.rs @@ -219,25 +219,27 @@ fn test_banned_alias_names() { assert_eq!( "Invalid alias in `[cli].alias` option: fmt. This is already a registered goal or subsytem.", cli_alias::create_alias_map( - Some(&hashmap!{"fmt".to_string() => hashset!{}}), - &owned_map(hashmap!{"fmt" => ""}), - ).unwrap_err() + Some(&hashmap! {"fmt".to_string() => hashset!{}}), + &owned_map(hashmap! {"fmt" => ""}), + ) + .unwrap_err() ); assert_eq!( "Invalid alias in `[cli].alias` option: --keep-sandboxes. This is already a registered flag in the GLOBAL scope.", cli_alias::create_alias_map( - Some(&hashmap!{"".to_string() => hashset!{"--keep-sandboxes".to_string()}}), - &owned_map(hashmap!{"--keep-sandboxes" => ""}, + Some(&hashmap! {"".to_string() => hashset!{"--keep-sandboxes".to_string()}}), + &owned_map(hashmap! {"--keep-sandboxes" => ""},) ) - ).unwrap_err() - ); + .unwrap_err() + ); assert_eq!( "Invalid alias in `[cli].alias` option: --changed-since. This is already a registered flag in the changed scope.", cli_alias::create_alias_map( - Some(&hashmap!{"changed".to_string() => hashset!{"--changed-since".to_string()}}), - &owned_map(hashmap!{"--changed-since" => ""}) - ).unwrap_err() + Some(&hashmap! {"changed".to_string() => hashset!{"--changed-since".to_string()}}), + &owned_map(hashmap! {"--changed-since" => ""}) + ) + .unwrap_err() ); } diff --git a/src/rust/engine/options/src/config.rs b/src/rust/engine/options/src/config.rs index f175700ec96..4e16cd1a176 100644 --- a/src/rust/engine/options/src/config.rs +++ b/src/rust/engine/options/src/config.rs @@ -8,8 +8,8 @@ use std::path::{Path, PathBuf}; use std::sync::LazyLock; use regex::Regex; -use toml::value::Table; use toml::Value; +use toml::value::Table; use super::{DictEdit, DictEditAction, ListEdit, ListEditAction, OptionsSource, Val}; use crate::fromfile::FromfileExpander; diff --git a/src/rust/engine/options/src/config_tests.rs b/src/rust/engine/options/src/config_tests.rs index bc442469ec7..53447701a52 100644 --- a/src/rust/engine/options/src/config_tests.rs +++ b/src/rust/engine/options/src/config_tests.rs @@ -8,14 +8,14 @@ use std::fmt::Debug; use std::fs::File; use std::io::Write; -use crate::config::{interpolate_string, ConfigSource}; +use crate::config::{ConfigSource, interpolate_string}; use crate::{ - option_id, DictEdit, DictEditAction, ListEdit, ListEditAction, OptionId, OptionsSource, Val, + DictEdit, DictEditAction, ListEdit, ListEditAction, OptionId, OptionsSource, Val, option_id, }; use crate::config::{Config, ConfigReader}; -use crate::fromfile::test_util::write_fromfile; use crate::fromfile::FromfileExpander; +use crate::fromfile::test_util::write_fromfile; use tempfile::TempDir; fn maybe_config(file_content: &str) -> Result { diff --git a/src/rust/engine/options/src/env.rs b/src/rust/engine/options/src/env.rs index e2362e6407d..2957a85eb3f 100644 --- a/src/rust/engine/options/src/env.rs +++ b/src/rust/engine/options/src/env.rs @@ -8,10 +8,10 @@ use std::ffi::OsString; use super::id::{NameTransform, OptionId}; use super::{DictEdit, OptionsSource}; +use crate::ListEdit; use crate::fromfile::FromfileExpander; use crate::parse::Parseable; use crate::scope::Scope; -use crate::ListEdit; #[derive(Debug)] pub struct Env { diff --git a/src/rust/engine/options/src/env_tests.rs b/src/rust/engine/options/src/env_tests.rs index 038894347a1..74279c613ed 100644 --- a/src/rust/engine/options/src/env_tests.rs +++ b/src/rust/engine/options/src/env_tests.rs @@ -2,9 +2,9 @@ // Licensed under the Apache License, Version 2.0 (see LICENSE). use crate::env::{Env, EnvReader}; -use crate::fromfile::test_util::write_fromfile; use crate::fromfile::FromfileExpander; -use crate::{option_id, DictEdit, DictEditAction}; +use crate::fromfile::test_util::write_fromfile; +use crate::{DictEdit, DictEditAction, option_id}; use crate::{ListEdit, ListEditAction, OptionId, OptionsSource, Val}; use maplit::hashmap; use std::collections::HashMap; @@ -72,10 +72,11 @@ fn test_display() { #[test] fn test_scope() { let env = env([("PANTS_FOO_BAR_EXAMPLE", "true")]); - assert!(env - .get_bool(&option_id!(["foo.bar"], "example")) - .unwrap() - .unwrap()); + assert!( + env.get_bool(&option_id!(["foo.bar"], "example")) + .unwrap() + .unwrap() + ); } #[test] diff --git a/src/rust/engine/options/src/flags.rs b/src/rust/engine/options/src/flags.rs index f71b4e429a3..063ca97aa26 100644 --- a/src/rust/engine/options/src/flags.rs +++ b/src/rust/engine/options/src/flags.rs @@ -4,10 +4,10 @@ use super::id::{NameTransform, OptionId}; use super::scope::Scope; use super::{DictEdit, OptionsSource}; +use crate::ListEdit; use crate::fromfile::FromfileExpander; use crate::parse::{ParseError, Parseable}; -use crate::ListEdit; -use itertools::{chain, Itertools}; +use itertools::{Itertools, chain}; use parking_lot::Mutex; use std::any::Any; use std::collections::{HashMap, HashSet}; @@ -42,11 +42,7 @@ impl Flag { } fn _prefix<'a>(negate: bool) -> impl Iterator { - if negate { - once("--no") - } else { - once("-") - } + if negate { once("--no") } else { once("-") } } // Check if --scope-flag matches. diff --git a/src/rust/engine/options/src/flags_tests.rs b/src/rust/engine/options/src/flags_tests.rs index 507eda55a32..377a96fb1f1 100644 --- a/src/rust/engine/options/src/flags_tests.rs +++ b/src/rust/engine/options/src/flags_tests.rs @@ -4,9 +4,9 @@ use crate::arg_splitter::ArgSplitter; use crate::arg_splitter::Args; use crate::flags::FlagsReader; -use crate::fromfile::test_util::write_fromfile; use crate::fromfile::FromfileExpander; -use crate::{option_id, DictEdit, DictEditAction, GoalInfo, Scope, Val}; +use crate::fromfile::test_util::write_fromfile; +use crate::{DictEdit, DictEditAction, GoalInfo, Scope, Val, option_id}; use crate::{ListEdit, ListEditAction, OptionId, OptionsSource}; use core::fmt::Debug; use maplit::hashmap; @@ -216,12 +216,14 @@ fn test_scalar_fromfile() { negate: bool, ) { let (_tmpdir, fromfile_path) = write_fromfile("fromfile.txt", content); - let args = mk_args(vec![format!( - "--{}foo=@{}", - if negate { "no-" } else { "" }, - fromfile_path.display() - ) - .as_str()]); + let args = mk_args(vec![ + format!( + "--{}foo=@{}", + if negate { "no-" } else { "" }, + fromfile_path.display() + ) + .as_str(), + ]); let actual = getter(&args, &option_id!("foo")).unwrap().unwrap(); assert_eq!(expected, actual) } @@ -252,7 +254,9 @@ fn test_scalar_fromfile() { fn test_list_fromfile() { fn do_test(content: &str, expected: &[ListEdit], filename: &str) { let (_tmpdir, fromfile_path) = write_fromfile(filename, content); - let args = mk_args(vec![format!("--foo=@{}", &fromfile_path.display()).as_str()]); + let args = mk_args(vec![ + format!("--foo=@{}", &fromfile_path.display()).as_str(), + ]); let actual = args.get_int_list(&option_id!("foo")).unwrap().unwrap(); assert_eq!(expected.to_vec(), actual) } @@ -359,7 +363,9 @@ fn test_dict_fromfile() { }]; let (_tmpdir, fromfile_path) = write_fromfile("fromfile.txt", "+{'FOO':42}"); - let args = mk_args(vec![format!("--foo=@{}", &fromfile_path.display()).as_str()]); + let args = mk_args(vec![ + format!("--foo=@{}", &fromfile_path.display()).as_str(), + ]); assert_eq!( expected_add, args.get_dict(&option_id!("foo")).unwrap().unwrap() @@ -370,7 +376,9 @@ fn test_dict_fromfile() { fn test_nonexistent_required_fromfile() { let args = mk_args(vec!["--foo=@/does/not/exist"]); let err = args.get_string(&option_id!("foo")).unwrap_err(); - assert!(err.starts_with("Problem reading /does/not/exist for --foo: No such file or directory")); + assert!( + err.starts_with("Problem reading /does/not/exist for --foo: No such file or directory") + ); } #[test] diff --git a/src/rust/engine/options/src/fromfile.rs b/src/rust/engine/options/src/fromfile.rs index d940e3c4cd0..e3afbb49f81 100644 --- a/src/rust/engine/options/src/fromfile.rs +++ b/src/rust/engine/options/src/fromfile.rs @@ -3,7 +3,7 @@ use super::{BuildRoot, DictEdit, DictEditAction, ListEdit, ListEditAction}; -use crate::parse::{mk_parse_err, parse_dict, ParseError, Parseable}; +use crate::parse::{ParseError, Parseable, mk_parse_err, parse_dict}; use log::warn; use serde::de::Deserialize; use std::path::{Path, PathBuf}; @@ -154,7 +154,7 @@ pub(crate) mod test_util { use std::fs::File; use std::io::Write; use std::path::PathBuf; - use tempfile::{tempdir, TempDir}; + use tempfile::{TempDir, tempdir}; pub(crate) fn write_fromfile(filename: &str, content: &str) -> (TempDir, PathBuf) { let tmpdir = tempdir().unwrap(); diff --git a/src/rust/engine/options/src/fromfile_tests.rs b/src/rust/engine/options/src/fromfile_tests.rs index 15ddcc78330..e8d5ce9827a 100644 --- a/src/rust/engine/options/src/fromfile_tests.rs +++ b/src/rust/engine/options/src/fromfile_tests.rs @@ -47,9 +47,10 @@ fn test_expand_fromfile() { ); assert_eq!(Ok(None), expand("@?/does/not/exist".to_string())); let err = expand("@/does/not/exist".to_string()).unwrap_err(); - assert!(err - .render("XXX") - .starts_with("Problem reading /does/not/exist for XXX: No such file or directory")) + assert!( + err.render("XXX") + .starts_with("Problem reading /does/not/exist for XXX: No such file or directory") + ) } #[test] diff --git a/src/rust/engine/options/src/tests.rs b/src/rust/engine/options/src/tests.rs index f7d155a5c12..e335d293ecb 100644 --- a/src/rust/engine/options/src/tests.rs +++ b/src/rust/engine/options/src/tests.rs @@ -4,8 +4,8 @@ use crate::config::ConfigSource; use crate::flags::Flag; use crate::{ - munge_bin_name, option_id, Args, BuildRoot, DictEdit, DictEditAction, Env, GoalInfo, ListEdit, - ListEditAction, OptionParser, Scope, Source, Val, + Args, BuildRoot, DictEdit, DictEditAction, Env, GoalInfo, ListEdit, ListEditAction, + OptionParser, Scope, Source, Val, munge_bin_name, option_id, }; use itertools::Itertools; use maplit::{hashmap, hashset}; diff --git a/src/rust/engine/pantsd/src/lib.rs b/src/rust/engine/pantsd/src/lib.rs index 1d24be1f05c..c7154a30437 100644 --- a/src/rust/engine/pantsd/src/lib.rs +++ b/src/rust/engine/pantsd/src/lib.rs @@ -10,7 +10,7 @@ use std::path::{Path, PathBuf}; use libc::pid_t; use log::debug; -use options::{option_id, BuildRoot, OptionId, OptionParser, OptionType}; +use options::{BuildRoot, OptionId, OptionParser, OptionType, option_id}; use sha2::digest::Update; use sha2::{Digest, Sha256}; use sysinfo::{ProcessExt, ProcessStatus, System, SystemExt}; diff --git a/src/rust/engine/process_execution/docker/src/docker.rs b/src/rust/engine/process_execution/docker/src/docker.rs index 0e662f85f34..5c31a59c3a7 100644 --- a/src/rust/engine/process_execution/docker/src/docker.rs +++ b/src/rust/engine/process_execution/docker/src/docker.rs @@ -15,7 +15,7 @@ use bollard::exec::StartExecResults; use bollard::image::CreateImageOptions; use bollard::service::CreateImageInfo; use bollard::volume::CreateVolumeOptions; -use bollard::{errors::Error as DockerError, Docker}; +use bollard::{Docker, errors::Error as DockerError}; use bytes::{Bytes, BytesMut}; use futures::stream::BoxStream; use futures::{FutureExt, StreamExt, TryFutureExt}; @@ -26,11 +26,11 @@ use once_cell::sync::Lazy; use parking_lot::Mutex; use store::{ImmutableInputs, Store}; use task_executor::Executor; -use workunit_store::{in_workunit, Metric, RunningWorkunit}; +use workunit_store::{Metric, RunningWorkunit, in_workunit}; use process_execution::local::{ - apply_chroot, collect_child_outputs, create_sandbox, prepare_workdir, setup_run_sh_script, - CapturedWorkdir, ChildOutput, KeepSandboxes, + CapturedWorkdir, ChildOutput, KeepSandboxes, apply_chroot, collect_child_outputs, + create_sandbox, prepare_workdir, setup_run_sh_script, }; use process_execution::{ Context, FallibleProcessResultWithPlatform, NamedCaches, Platform, Process, ProcessError, @@ -281,25 +281,20 @@ async fn pull_image( }; let (do_pull, pull_reason) = match (policy, image_exists) { - (ImagePullPolicy::Always, _) => { - (true, "the image pull policy is set to \"always\"") - }, - (ImagePullPolicy::IfMissing, false) => { - (true, "the image is missing locally") - }, - (ImagePullPolicy::OnlyIfLatestOrMissing, false) => { - (true, "the image is missing locally") - }, - (ImagePullPolicy::OnlyIfLatestOrMissing, true) if has_latest_tag => { - (true, "the image is present but the image tag is 'latest' and the image pull policy is set to pull images in this case") - }, - (ImagePullPolicy::Never, false) => { - return Err(format!( - "Image `{image}` was not found locally and Pants is configured to not attempt to pull" - )); - } - _ => (false, "") - }; + (ImagePullPolicy::Always, _) => (true, "the image pull policy is set to \"always\""), + (ImagePullPolicy::IfMissing, false) => (true, "the image is missing locally"), + (ImagePullPolicy::OnlyIfLatestOrMissing, false) => (true, "the image is missing locally"), + (ImagePullPolicy::OnlyIfLatestOrMissing, true) if has_latest_tag => ( + true, + "the image is present but the image tag is 'latest' and the image pull policy is set to pull images in this case", + ), + (ImagePullPolicy::Never, false) => { + return Err(format!( + "Image `{image}` was not found locally and Pants is configured to not attempt to pull" + )); + } + _ => (false, ""), + }; if do_pull { in_workunit!( @@ -342,7 +337,7 @@ async fn pull_image( _ => (), }, Err(err) => { - return Err(format!("Failed to pull Docker image `{image}`: {err:?}")) + return Err(format!("Failed to pull Docker image `{image}`: {err:?}")); } } } @@ -778,13 +773,15 @@ impl<'a> ContainerCache<'a> { })?; let immutable_inputs_base_dir = immutable_inputs - .workdir() - .to_path_buf() - .into_os_string() - .into_string() - .map_err(|s| { - format!("Unable to convert immutable_inputs base dir due to non UTF-8 characters: {s:?}") - })?; + .workdir() + .to_path_buf() + .into_os_string() + .into_string() + .map_err(|s| { + format!( + "Unable to convert immutable_inputs base dir due to non UTF-8 characters: {s:?}" + ) + })?; Ok(Self { docker, @@ -1013,7 +1010,7 @@ impl<'a> ContainerCache<'a> { Err(err) => { return Err(format!( "Failed to get Docker connection during container removal: {err}" - )) + )); } }; diff --git a/src/rust/engine/process_execution/docker/src/docker_tests.rs b/src/rust/engine/process_execution/docker/src/docker_tests.rs index ccfa634e435..be5030720d7 100644 --- a/src/rust/engine/process_execution/docker/src/docker_tests.rs +++ b/src/rust/engine/process_execution/docker/src/docker_tests.rs @@ -6,7 +6,7 @@ use std::path::PathBuf; use std::time::Duration; use bollard::Docker; -use fs::{RelativePath, EMPTY_DIRECTORY_DIGEST}; +use fs::{EMPTY_DIRECTORY_DIGEST, RelativePath}; use maplit::hashset; use store::{ImmutableInputs, Store}; use tempfile::TempDir; @@ -17,8 +17,8 @@ use workunit_store::{RunningWorkunit, WorkunitStore}; use crate::docker::{DockerOnceCell, ImagePullCache, SANDBOX_BASE_PATH_IN_CONTAINER}; use process_execution::local::KeepSandboxes; use process_execution::{ - local, CacheName, CommandRunner, Context, FallibleProcessResultWithPlatform, InputDigests, - Platform, Process, ProcessError, + CacheName, CommandRunner, Context, FallibleProcessResultWithPlatform, InputDigests, Platform, + Process, ProcessError, local, }; /// Docker image to use for most tests in this file. diff --git a/src/rust/engine/process_execution/pe_nailgun/src/lib.rs b/src/rust/engine/process_execution/pe_nailgun/src/lib.rs index cf1a250e9c4..ac27fbbba86 100644 --- a/src/rust/engine/process_execution/pe_nailgun/src/lib.rs +++ b/src/rust/engine/process_execution/pe_nailgun/src/lib.rs @@ -10,13 +10,13 @@ use async_trait::async_trait; use futures::future::{FutureExt, TryFutureExt}; use futures::stream::{BoxStream, StreamExt}; use log::{debug, trace}; -use nails::execution::{self, child_channel, ChildInput, Command}; +use nails::execution::{self, ChildInput, Command, child_channel}; use store::{ImmutableInputs, Store}; use task_executor::Executor; use tokio::net::TcpStream; -use workunit_store::{in_workunit, Metric, RunningWorkunit}; +use workunit_store::{Metric, RunningWorkunit, in_workunit}; -use process_execution::local::{prepare_workdir, CapturedWorkdir, ChildOutput}; +use process_execution::local::{CapturedWorkdir, ChildOutput, prepare_workdir}; use process_execution::{ Context, FallibleProcessResultWithPlatform, InputDigests, NamedCaches, Process, ProcessError, }; diff --git a/src/rust/engine/process_execution/pe_nailgun/src/nailgun_pool.rs b/src/rust/engine/process_execution/pe_nailgun/src/nailgun_pool.rs index bd5da2020f8..d5fe8ab788d 100644 --- a/src/rust/engine/process_execution/pe_nailgun/src/nailgun_pool.rs +++ b/src/rust/engine/process_execution/pe_nailgun/src/nailgun_pool.rs @@ -22,7 +22,7 @@ use tokio::sync::{OwnedSemaphorePermit, Semaphore}; use hashing::Fingerprint; use store::{ImmutableInputs, Store}; use task_executor::Executor; -use workunit_store::{in_workunit, Level}; +use workunit_store::{Level, in_workunit}; use process_execution::local::prepare_workdir; use process_execution::{NamedCaches, Process, ProcessError}; diff --git a/src/rust/engine/process_execution/remote/src/remote.rs b/src/rust/engine/process_execution/remote/src/remote.rs index ba4c6d8705d..32539600157 100644 --- a/src/rust/engine/process_execution/remote/src/remote.rs +++ b/src/rust/engine/process_execution/remote/src/remote.rs @@ -12,18 +12,18 @@ use async_trait::async_trait; use bytes::Bytes; use futures::future; use futures::{Stream, StreamExt}; -use log::{debug, trace, warn, Level}; +use log::{Level, debug, trace, warn}; use prost::Message; use protos::gen::build::bazel::remote::execution::v2 as remexec; use protos::gen::google::longrunning::{ - operations_client::OperationsClient, CancelOperationRequest, Operation, + CancelOperationRequest, Operation, operations_client::OperationsClient, }; use protos::gen::google::rpc::{PreconditionFailure, Status as StatusProto}; -use rand::{thread_rng, Rng}; +use rand::{Rng, thread_rng}; use remexec::{ - capabilities_client::CapabilitiesClient, execution_client::ExecutionClient, - execution_stage::Value as ExecutionStageValue, Action, Command, ExecuteRequest, - ExecuteResponse, ExecutedActionMetadata, ServerCapabilities, WaitExecutionRequest, + Action, Command, ExecuteRequest, ExecuteResponse, ExecutedActionMetadata, ServerCapabilities, + WaitExecutionRequest, capabilities_client::CapabilitiesClient, + execution_client::ExecutionClient, execution_stage::Value as ExecutionStageValue, }; use tonic::{Code, Request, Status}; @@ -31,20 +31,20 @@ use concrete_time::TimeSpan; use fs::{self, DirectoryDigest, EMPTY_DIRECTORY_DIGEST}; use grpc_util::headers_to_http_header_map; use grpc_util::prost::MessageExt; -use grpc_util::{layered_service, status_to_str, LayeredService}; +use grpc_util::{LayeredService, layered_service, status_to_str}; use hashing::{Digest, Fingerprint}; use remote_provider_reapi::apply_headers; use store::{Store, StoreError}; use task_executor::Executor; use workunit_store::{ - in_workunit, Metric, ObservationMetric, RunId, RunningWorkunit, SpanId, UserMetadataItem, - WorkunitMetadata, WorkunitStore, + Metric, ObservationMetric, RunId, RunningWorkunit, SpanId, UserMetadataItem, WorkunitMetadata, + WorkunitStore, in_workunit, }; use process_execution::{ - make_execute_request, populate_fallible_execution_result, Context, EntireExecuteRequest, - FallibleProcessResultWithPlatform, Process, ProcessError, ProcessExecutionEnvironment, - ProcessResultMetadata, ProcessResultSource, + Context, EntireExecuteRequest, FallibleProcessResultWithPlatform, Process, ProcessError, + ProcessExecutionEnvironment, ProcessResultMetadata, ProcessResultSource, make_execute_request, + populate_fallible_execution_result, }; #[derive(Debug)] @@ -257,8 +257,7 @@ impl CommandRunner { Some(Ok(operation)) => { trace!( "wait_on_operation_stream (build_id={}): got operation: {:?}", - &context.build_id, - &operation + &context.build_id, &operation ); // Extract the operation name. @@ -522,7 +521,7 @@ impl CommandRunner { Err(e) => { return ExecutionError::Fatal( format!("Bad digest in missing blob: {}: {}", parts[1], e).into(), - ) + ); } }; @@ -531,7 +530,7 @@ impl CommandRunner { Err(e) => { return ExecutionError::Fatal( format!("Missing blob had bad size: {}: {}", parts[2], e).into(), - ) + ); } }; @@ -743,9 +742,9 @@ impl CommandRunner { // The request has not been submitted yet. Submit the request using the REv2 // Execute method. debug!( - "no current operation: submitting execute request: build_id={}; execute_request={:?}", - context.build_id, &execute_request - ); + "no current operation: submitting execute request: build_id={}; execute_request={:?}", + context.build_id, &execute_request + ); workunit.increment_counter(Metric::RemoteExecutionRPCExecute, 1); let mut client = self.execution_client.as_ref().clone(); let request = @@ -757,9 +756,9 @@ impl CommandRunner { // The request has been submitted already. Reconnect to the status stream // using the REv2 WaitExecution method. debug!( - "existing operation: reconnecting to operation stream: build_id={}; operation_name={}", - context.build_id, operation_name - ); + "existing operation: reconnecting to operation stream: build_id={}; operation_name={}", + context.build_id, operation_name + ); workunit.increment_counter(Metric::RemoteExecutionRPCWaitExecution, 1); let wait_execution_request = WaitExecutionRequest { name: operation_name.to_owned(), @@ -789,8 +788,7 @@ impl CommandRunner { StreamOutcome::Complete(status) => { trace!( "wait_on_operation_stream (build_id={}) returned completion={:?}", - context.build_id, - status + context.build_id, status ); // We completed this operation. running_operation.completed(); @@ -800,8 +798,7 @@ impl CommandRunner { trace!( "wait_on_operation_stream (build_id={}) returned stream close, \ will retry operation_name={:?}", - context.build_id, - running_operation.name + context.build_id, running_operation.name ); // Check if the number of request attempts sent thus far have exceeded the number diff --git a/src/rust/engine/process_execution/remote/src/remote_cache.rs b/src/rust/engine/process_execution/remote/src/remote_cache.rs index dfe8bd90510..d57ff480006 100644 --- a/src/rust/engine/process_execution/remote/src/remote_cache.rs +++ b/src/rust/engine/process_execution/remote/src/remote_cache.rs @@ -6,26 +6,26 @@ use std::sync::Arc; use std::time::Instant; use async_trait::async_trait; -use fs::{directory, DigestTrie, RelativePath, SymlinkBehavior}; -use futures::future::{BoxFuture, TryFutureExt}; +use fs::{DigestTrie, RelativePath, SymlinkBehavior, directory}; use futures::FutureExt; +use futures::future::{BoxFuture, TryFutureExt}; use hashing::Digest; use parking_lot::Mutex; use protos::gen::build::bazel::remote::execution::v2 as remexec; use protos::require_digest; use remexec::{ActionResult, Command, Tree}; -use remote_provider::{choose_action_cache_provider, ActionCacheProvider}; +use remote_provider::{ActionCacheProvider, choose_action_cache_provider}; use store::{Store, StoreError}; use workunit_store::{ - in_workunit, Level, Metric, ObservationMetric, RunningWorkunit, WorkunitMetadata, + Level, Metric, ObservationMetric, RunningWorkunit, WorkunitMetadata, in_workunit, }; use process_execution::{ - check_cache_content, populate_fallible_execution_result, CacheContentBehavior, Context, - FallibleProcessResultWithPlatform, Process, ProcessCacheScope, ProcessError, - ProcessExecutionEnvironment, ProcessResultSource, + CacheContentBehavior, Context, FallibleProcessResultWithPlatform, Process, ProcessCacheScope, + ProcessError, ProcessExecutionEnvironment, ProcessResultSource, check_cache_content, + populate_fallible_execution_result, }; -use process_execution::{make_execute_request, EntireExecuteRequest}; +use process_execution::{EntireExecuteRequest, make_execute_request}; // Consumers of this crate shouldn't need to worry about the exact crate structure that comes // together to make a remote cache command runner. @@ -141,14 +141,14 @@ impl CommandRunner { "Declared output directory path {directory_path:?} in output \ digest {trie_digest:?} contained a symlink instead.", trie_digest = root_trie.compute_root_digest(), - )) + )); } Some(directory::Entry::File(_)) => { return Err(format!( "Declared output directory path {directory_path:?} in output \ digest {trie_digest:?} contained a file instead.", trie_digest = root_trie.compute_root_digest(), - )) + )); } }; diff --git a/src/rust/engine/process_execution/remote/src/remote_cache_tests.rs b/src/rust/engine/process_execution/remote/src/remote_cache_tests.rs index 501747ebafe..e32d1368dc8 100644 --- a/src/rust/engine/process_execution/remote/src/remote_cache_tests.rs +++ b/src/rust/engine/process_execution/remote/src/remote_cache_tests.rs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0 (see LICENSE). use std::collections::{BTreeMap, HashSet}; use std::convert::TryInto; -use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::Arc; +use std::sync::atomic::{AtomicUsize, Ordering}; use std::time::Duration; use async_trait::async_trait; @@ -11,7 +11,7 @@ use maplit::hashset; use tempfile::TempDir; use tokio::time::sleep; -use fs::{DirectoryDigest, RelativePath, EMPTY_DIRECTORY_DIGEST}; +use fs::{DirectoryDigest, EMPTY_DIRECTORY_DIGEST, RelativePath}; use grpc_util::tls; use hashing::{Digest, EMPTY_DIGEST}; use mock::StubCAS; @@ -23,10 +23,10 @@ use workunit_store::{RunId, RunningWorkunit, WorkunitStore}; use crate::remote::ensure_action_stored_locally; use crate::remote_cache::{RemoteCacheRunnerOptions, RemoteCacheWarningsBehavior}; use process_execution::{ - make_execute_request, CacheContentBehavior, CommandRunner as CommandRunnerTrait, Context, - EntireExecuteRequest, FallibleProcessResultWithPlatform, Platform, Process, ProcessCacheScope, - ProcessError, ProcessExecutionEnvironment, ProcessExecutionStrategy, ProcessResultMetadata, - ProcessResultSource, + CacheContentBehavior, CommandRunner as CommandRunnerTrait, Context, EntireExecuteRequest, + FallibleProcessResultWithPlatform, Platform, Process, ProcessCacheScope, ProcessError, + ProcessExecutionEnvironment, ProcessExecutionStrategy, ProcessResultMetadata, + ProcessResultSource, make_execute_request, }; const CACHE_READ_TIMEOUT: Duration = Duration::from_secs(5); @@ -682,26 +682,30 @@ async fn extract_output_file() { assert_eq!(file_digest, TestData::roland().digest()); // Extract non-existent files to make sure that Ok(None) is returned. - assert!(crate::remote_cache::CommandRunner::extract_output_file( - &input_tree.digest_trie(), - "animals.ext", - ) - .unwrap() - .is_none()); - assert!(crate::remote_cache::CommandRunner::extract_output_file( - &input_tree.digest_trie(), - "cats/xyzzy", - ) - .unwrap() - .is_none()); + assert!( + crate::remote_cache::CommandRunner::extract_output_file( + &input_tree.digest_trie(), + "animals.ext", + ) + .unwrap() + .is_none() + ); + assert!( + crate::remote_cache::CommandRunner::extract_output_file( + &input_tree.digest_trie(), + "cats/xyzzy", + ) + .unwrap() + .is_none() + ); // Error if a path has been declared as a file but isn't. assert_eq!( crate::remote_cache::CommandRunner::extract_output_file(&input_tree.digest_trie(), "cats",), Err(format!( - "Declared output file path \"cats\" in output digest {:?} contained a directory instead.", - TestDirectory::nested().digest() - )) + "Declared output file path \"cats\" in output digest {:?} contained a directory instead.", + TestDirectory::nested().digest() + )) ); } diff --git a/src/rust/engine/process_execution/remote/src/remote_tests.rs b/src/rust/engine/process_execution/remote/src/remote_tests.rs index 916028b0a61..3aeedb9a9d2 100644 --- a/src/rust/engine/process_execution/remote/src/remote_tests.rs +++ b/src/rust/engine/process_execution/remote/src/remote_tests.rs @@ -13,7 +13,7 @@ use mock::execution_server::{ExpectedAPICall, MockOperation}; use prost::Message; use protos::gen::build::bazel::remote::execution::v2 as remexec; use protos::gen::google::longrunning::Operation; -use remexec::{execution_stage::Value as ExecutionStageValue, ExecutedActionMetadata}; +use remexec::{ExecutedActionMetadata, execution_stage::Value as ExecutionStageValue}; use store::{RemoteProvider, RemoteStoreOptions, SnapshotOps, Store, StoreError}; use tempfile::TempDir; use testutil::data::{TestData, TestDirectory, TestTree}; @@ -22,7 +22,7 @@ use tokio::time::{sleep, timeout}; use workunit_store::{Level, RunId, RunningWorkunit, WorkunitStore}; use crate::remote::{CommandRunner, ExecutionError, OperationOrStatus}; -use fs::{DirectoryDigest, RelativePath, SymlinkBehavior, EMPTY_DIRECTORY_DIGEST}; +use fs::{DirectoryDigest, EMPTY_DIRECTORY_DIGEST, RelativePath, SymlinkBehavior}; use process_execution::{ CacheName, CommandRunner as CommandRunnerTrait, Context, EntireExecuteRequest, FallibleProcessResultWithPlatform, InputDigests, Platform, Process, ProcessCacheScope, @@ -1677,9 +1677,11 @@ async fn initial_response_missing_response_and_error() { .await .expect_err("Want Err"); - assert!(result - .to_string() - .ends_with("Operation finished but no response supplied")); + assert!( + result + .to_string() + .ends_with("Operation finished but no response supplied") + ); } #[tokio::test] diff --git a/src/rust/engine/process_execution/src/bounded.rs b/src/rust/engine/process_execution/src/bounded.rs index 8aed95d7895..78af25e8f8f 100644 --- a/src/rust/engine/process_execution/src/bounded.rs +++ b/src/rust/engine/process_execution/src/bounded.rs @@ -1,12 +1,12 @@ // Copyright 2022 Pants project contributors (see CONTRIBUTORS.md). // Licensed under the Apache License, Version 2.0 (see LICENSE). use std::borrow::Cow; -use std::cmp::{max, min, Ordering, Reverse}; +use std::cmp::{Ordering, Reverse, max, min}; use std::collections::VecDeque; use std::fmt::{self, Debug}; use std::future::Future; use std::sync::LazyLock; -use std::sync::{atomic, Arc}; +use std::sync::{Arc, atomic}; use std::time::{Duration, Instant}; use async_trait::async_trait; @@ -16,7 +16,7 @@ use regex::Regex; use task_executor::Executor; use tokio::sync::{Notify, Semaphore, SemaphorePermit}; use tokio::time::sleep; -use workunit_store::{in_workunit, RunningWorkunit}; +use workunit_store::{RunningWorkunit, in_workunit}; use crate::{Context, FallibleProcessResultWithPlatform, Process, ProcessError}; diff --git a/src/rust/engine/process_execution/src/bounded_tests.rs b/src/rust/engine/process_execution/src/bounded_tests.rs index aeea73dad42..535783f0e84 100644 --- a/src/rust/engine/process_execution/src/bounded_tests.rs +++ b/src/rust/engine/process_execution/src/bounded_tests.rs @@ -7,7 +7,7 @@ use futures::channel::oneshot; use futures::future::{self, FutureExt}; use tokio::time::{sleep, timeout}; -use crate::bounded::{balance, AsyncSemaphore, State, Task}; +use crate::bounded::{AsyncSemaphore, State, Task, balance}; fn mk_semaphore(permits: usize) -> AsyncSemaphore { mk_semaphore_with_preemptible_duration(permits, Duration::from_millis(200)) diff --git a/src/rust/engine/process_execution/src/cache.rs b/src/rust/engine/process_execution/src/cache.rs index 9c2690e3943..fadee91ff00 100644 --- a/src/rust/engine/process_execution/src/cache.rs +++ b/src/rust/engine/process_execution/src/cache.rs @@ -14,13 +14,13 @@ use protos::gen::pants::cache::{CacheKey, CacheKeyType}; use serde::{Deserialize, Serialize}; use store::{Store, StoreError}; use workunit_store::{ - in_workunit, Level, Metric, ObservationMetric, RunningWorkunit, WorkunitMetadata, + Level, Metric, ObservationMetric, RunningWorkunit, WorkunitMetadata, in_workunit, }; use crate::{ - check_cache_content, CacheContentBehavior, Context, FallibleProcessResultWithPlatform, - Platform, Process, ProcessCacheScope, ProcessError, ProcessExecutionEnvironment, - ProcessResultSource, + CacheContentBehavior, Context, FallibleProcessResultWithPlatform, Platform, Process, + ProcessCacheScope, ProcessError, ProcessExecutionEnvironment, ProcessResultSource, + check_cache_content, }; // TODO: Consider moving into protobuf as a CacheValue type. diff --git a/src/rust/engine/process_execution/src/cache_tests.rs b/src/rust/engine/process_execution/src/cache_tests.rs index 7d839ab52a0..611c6807cdb 100644 --- a/src/rust/engine/process_execution/src/cache_tests.rs +++ b/src/rust/engine/process_execution/src/cache_tests.rs @@ -15,8 +15,8 @@ use tokio::sync::RwLock; use workunit_store::{RunningWorkunit, WorkunitStore}; use crate::{ - local::KeepSandboxes, CacheContentBehavior, CommandRunner as CommandRunnerTrait, Context, - FallibleProcessResultWithPlatform, NamedCaches, Process, ProcessError, + CacheContentBehavior, CommandRunner as CommandRunnerTrait, Context, + FallibleProcessResultWithPlatform, NamedCaches, Process, ProcessError, local::KeepSandboxes, }; struct RoundtripResults { @@ -175,11 +175,13 @@ async fn recover_from_missing_store_contents() { .unwrap(); let removed = store.remove_file(output_child_digest).await.unwrap(); assert!(removed); - assert!(store - .contents_for_directory(output_dir_digest) - .await - .err() - .is_some()) + assert!( + store + .contents_for_directory(output_dir_digest) + .await + .err() + .is_some() + ) } // Ensure that we don't fail if we re-run. @@ -189,9 +191,11 @@ async fn recover_from_missing_store_contents() { .unwrap(); // And that the entire output directory can be loaded. - assert!(store - .contents_for_directory(second_result.output_directory) - .await - .ok() - .is_some()) + assert!( + store + .contents_for_directory(second_result.output_directory) + .await + .ok() + .is_some() + ) } diff --git a/src/rust/engine/process_execution/src/children.rs b/src/rust/engine/process_execution/src/children.rs index d3640066f55..4345fd2f4c9 100644 --- a/src/rust/engine/process_execution/src/children.rs +++ b/src/rust/engine/process_execution/src/children.rs @@ -4,8 +4,8 @@ use std::ops::{Deref, DerefMut}; use std::{thread, time}; use nix::sys::signal; -use nix::unistd::getpgid; use nix::unistd::Pid; +use nix::unistd::getpgid; use tokio::process::{Child, Command}; const GRACEFUL_SHUTDOWN_POLL_TIME: time::Duration = time::Duration::from_millis(50); @@ -135,11 +135,14 @@ impl ManagedChild { Ok(false) => { // We timed out waiting for the child to exit, so we need to kill it. log::warn!( - "Timed out waiting for graceful shutdown of process group. Will try SIGKILL instead." - ); + "Timed out waiting for graceful shutdown of process group. Will try SIGKILL instead." + ); } Err(e) => { - log::warn!("An error occurred while waiting for graceful shutdown of process group ({}). Will try SIGKILL instead.", e); + log::warn!( + "An error occurred while waiting for graceful shutdown of process group ({}). Will try SIGKILL instead.", + e + ); } } } diff --git a/src/rust/engine/process_execution/src/fork_exec.rs b/src/rust/engine/process_execution/src/fork_exec.rs index 3c356d5cc10..1d14c769d9f 100644 --- a/src/rust/engine/process_execution/src/fork_exec.rs +++ b/src/rust/engine/process_execution/src/fork_exec.rs @@ -56,11 +56,11 @@ pub async fn spawn_process( continue; } else if retries > 0 { break Err(format!( - "Error launching process after {} {} for ETXTBSY. Final error was: {:?}", - retries, - if retries == 1 { "retry" } else { "retries" }, - e - )); + "Error launching process after {} {} for ETXTBSY. Final error was: {:?}", + retries, + if retries == 1 { "retry" } else { "retries" }, + e + )); } else { break Err(format!("Error launching process: {e:?}")); } diff --git a/src/rust/engine/process_execution/src/lib.rs b/src/rust/engine/process_execution/src/lib.rs index 19bee39114c..09da897aa05 100644 --- a/src/rust/engine/process_execution/src/lib.rs +++ b/src/rust/engine/process_execution/src/lib.rs @@ -14,12 +14,12 @@ use async_trait::async_trait; use bytes::Bytes; use concrete_time::{Duration, TimeSpan}; use deepsize::DeepSizeOf; -use fs::{DirectoryDigest, RelativePath, EMPTY_DIRECTORY_DIGEST}; +use fs::{DirectoryDigest, EMPTY_DIRECTORY_DIGEST, RelativePath}; use fs::{File, PathStat}; +use futures::FutureExt; use futures::future::try_join_all; use futures::future::{self, BoxFuture, TryFutureExt}; use futures::try_join; -use futures::FutureExt; use grpc_util::prost::MessageExt; use hashing::Digest; use itertools::Itertools; @@ -37,7 +37,7 @@ use store::{SnapshotOps, Store, StoreError}; use task_executor::TailTasks; use tryfuture::try_future; use uuid::Uuid; -use workunit_store::{in_workunit, Level, RunId, RunningWorkunit, WorkunitStore}; +use workunit_store::{Level, RunId, RunningWorkunit, WorkunitStore, in_workunit}; pub mod bounded; #[cfg(test)] @@ -1522,7 +1522,7 @@ pub fn extract_output_files( return future::ready::>(Ok( DirectoryDigest::from_persisted_digest(digest), )) - .boxed() + .boxed(); } Err(err) => return futures::future::err(err.into()).boxed(), }; @@ -1620,14 +1620,15 @@ pub fn extract_output_files( } async move { - let files_snapshot = - Snapshot::from_path_stats(StoreOneOffRemoteDigest::new(path_map), path_stats).map_err( - move |error| { - format!( + let files_snapshot = Snapshot::from_path_stats( + StoreOneOffRemoteDigest::new(path_map), + path_stats, + ) + .map_err(move |error| { + format!( "Error when storing the output file directory info in the remote CAS: {error:?}" ) - }, - ); + }); let (files_snapshot, mut directory_digests) = future::try_join(files_snapshot, future::try_join_all(directory_digests)).await?; diff --git a/src/rust/engine/process_execution/src/local.rs b/src/rust/engine/process_execution/src/local.rs index eb1a1159fe2..741c23718aa 100644 --- a/src/rust/engine/process_execution/src/local.rs +++ b/src/rust/engine/process_execution/src/local.rs @@ -14,12 +14,12 @@ use std::time::Instant; use async_trait::async_trait; use bytes::{Bytes, BytesMut}; use fs::{ - self, DigestTrie, DirectoryDigest, GlobExpansionConjunction, GlobMatching, PathGlobs, - Permissions, RelativePath, StrictGlobMatching, SymlinkBehavior, TypedPath, - EMPTY_DIRECTORY_DIGEST, + self, DigestTrie, DirectoryDigest, EMPTY_DIRECTORY_DIGEST, GlobExpansionConjunction, + GlobMatching, PathGlobs, Permissions, RelativePath, StrictGlobMatching, SymlinkBehavior, + TypedPath, }; use futures::stream::{BoxStream, StreamExt, TryStreamExt}; -use futures::{try_join, FutureExt, TryFutureExt}; +use futures::{FutureExt, TryFutureExt, try_join}; use log::{debug, info}; use nails::execution::ExitCode; use shell_quote::Bash; @@ -33,7 +33,7 @@ use tokio::process::Command; use tokio::sync::RwLock; use tokio::time::timeout; use tokio_util::codec::{BytesCodec, FramedRead}; -use workunit_store::{in_workunit, Level, Metric, RunningWorkunit}; +use workunit_store::{Level, Metric, RunningWorkunit, in_workunit}; use crate::fork_exec::spawn_process; use crate::{ diff --git a/src/rust/engine/process_execution/src/local_tests.rs b/src/rust/engine/process_execution/src/local_tests.rs index d546c583998..fe3fdb126e5 100644 --- a/src/rust/engine/process_execution/src/local_tests.rs +++ b/src/rust/engine/process_execution/src/local_tests.rs @@ -19,9 +19,8 @@ use tokio::sync::RwLock; use workunit_store::{RunningWorkunit, WorkunitStore}; use crate::{ - local, local::KeepSandboxes, CacheName, CommandRunner as CommandRunnerTrait, Context, - FallibleProcessResultWithPlatform, InputDigests, NamedCaches, Process, ProcessError, - RelativePath, + CacheName, CommandRunner as CommandRunnerTrait, Context, FallibleProcessResultWithPlatform, + InputDigests, NamedCaches, Process, ProcessError, RelativePath, local, local::KeepSandboxes, }; #[derive(PartialEq, Debug)] @@ -466,9 +465,11 @@ async fn test_directory_preservation() { // Ensure the bash command line is provided. let bytes_quoted_command_line = Bash::quote_vec(&bash_contents); let quoted_command_line = str::from_utf8(&bytes_quoted_command_line).unwrap(); - assert!(std::fs::read_to_string(&run_script_path) - .unwrap() - .contains(quoted_command_line)); + assert!( + std::fs::read_to_string(&run_script_path) + .unwrap() + .contains(quoted_command_line) + ); } #[tokio::test] diff --git a/src/rust/engine/process_execution/src/named_caches.rs b/src/rust/engine/process_execution/src/named_caches.rs index 2432179fe79..423283baf60 100644 --- a/src/rust/engine/process_execution/src/named_caches.rs +++ b/src/rust/engine/process_execution/src/named_caches.rs @@ -10,7 +10,7 @@ use futures::{FutureExt, TryFutureExt}; use parking_lot::Mutex; use serde::Serialize; -use fs::{default_cache_path, RelativePath}; +use fs::{RelativePath, default_cache_path}; use store::WorkdirSymlink; #[derive(Clone, Debug, DeepSizeOf, Eq, PartialEq, Hash, PartialOrd, Ord, Serialize)] @@ -25,8 +25,8 @@ impl CacheName { Ok(CacheName(name)) } else { Err(format!( - "Cache names may only contain lowercase alphanumeric characters or underscores: got {name:?}" - )) + "Cache names may only contain lowercase alphanumeric characters or underscores: got {name:?}" + )) } } @@ -61,9 +61,9 @@ impl NamedCaches { pub fn new( base_path: PathBuf, initializer: impl Fn(&Path) -> futures::future::BoxFuture> - + Send - + Sync - + 'static, + + Send + + Sync + + 'static, ) -> Self { Self(Arc::new(Inner { base_path, diff --git a/src/rust/engine/process_execution/src/switched.rs b/src/rust/engine/process_execution/src/switched.rs index 1e6cc70707f..b7f1ab41d3d 100644 --- a/src/rust/engine/process_execution/src/switched.rs +++ b/src/rust/engine/process_execution/src/switched.rs @@ -68,8 +68,8 @@ mod tests { use async_trait::async_trait; use workunit_store::{RunningWorkunit, WorkunitStore}; - use crate::switched::SwitchedCommandRunner; use crate::CommandRunner; + use crate::switched::SwitchedCommandRunner; use crate::{Context, FallibleProcessResultWithPlatform, Process, ProcessError}; #[derive(Debug)] diff --git a/src/rust/engine/process_execution/src/tests.rs b/src/rust/engine/process_execution/src/tests.rs index ab82d61bf14..b41641d9b2a 100644 --- a/src/rust/engine/process_execution/src/tests.rs +++ b/src/rust/engine/process_execution/src/tests.rs @@ -1,8 +1,8 @@ // Copyright 2021 Pants project contributors (see CONTRIBUTORS.md). // Licensed under the Apache License, Version 2.0 (see LICENSE). -use std::collections::hash_map::DefaultHasher; use std::collections::BTreeMap; +use std::collections::hash_map::DefaultHasher; use std::fs::Permissions; use std::hash::{Hash, Hasher}; use std::os::unix::fs::PermissionsExt; @@ -18,8 +18,8 @@ use tempfile::TempDir; use workunit_store::RunId; use crate::{ - maybe_make_wrapper_script, CacheName, Platform, Process, ProcessExecutionEnvironment, - ProcessExecutionStrategy, ProcessResultMetadata, ProcessResultSource, + CacheName, Platform, Process, ProcessExecutionEnvironment, ProcessExecutionStrategy, + ProcessResultMetadata, ProcessResultSource, maybe_make_wrapper_script, }; #[test] diff --git a/src/rust/engine/process_execution/src/workspace.rs b/src/rust/engine/process_execution/src/workspace.rs index 3d270161b3e..4f20e0e000e 100644 --- a/src/rust/engine/process_execution/src/workspace.rs +++ b/src/rust/engine/process_execution/src/workspace.rs @@ -20,14 +20,14 @@ use task_executor::Executor; use tokio::process::Command; use tokio::sync::RwLock; use tokio_util::codec::{BytesCodec, FramedRead}; -use workunit_store::{in_workunit, RunningWorkunit}; +use workunit_store::{RunningWorkunit, in_workunit}; use crate::fork_exec::spawn_process; use crate::{ + Context, FallibleProcessResultWithPlatform, ManagedChild, NamedCaches, Process, ProcessError, local::{ - apply_chroot, create_sandbox, prepare_workdir, CapturedWorkdir, ChildOutput, KeepSandboxes, + CapturedWorkdir, ChildOutput, KeepSandboxes, apply_chroot, create_sandbox, prepare_workdir, }, - Context, FallibleProcessResultWithPlatform, ManagedChild, NamedCaches, Process, ProcessError, }; pub struct CommandRunner { diff --git a/src/rust/engine/process_execution/src/workspace_tests.rs b/src/rust/engine/process_execution/src/workspace_tests.rs index a3c6fad184b..5d7620a52a4 100644 --- a/src/rust/engine/process_execution/src/workspace_tests.rs +++ b/src/rust/engine/process_execution/src/workspace_tests.rs @@ -23,9 +23,8 @@ use workunit_store::{RunningWorkunit, WorkunitStore}; use crate::local_tests::named_caches_and_immutable_inputs; use crate::{ - workspace, CacheName, CommandRunner as CommandRunnerTrait, Context, - FallibleProcessResultWithPlatform, InputDigests, NamedCaches, Process, ProcessError, - RelativePath, + CacheName, CommandRunner as CommandRunnerTrait, Context, FallibleProcessResultWithPlatform, + InputDigests, NamedCaches, Process, ProcessError, RelativePath, workspace, }; #[derive(PartialEq, Debug)] diff --git a/src/rust/engine/process_executor/src/main.rs b/src/rust/engine/process_executor/src/main.rs index 148344e1e0d..2bfc9fa6749 100644 --- a/src/rust/engine/process_executor/src/main.rs +++ b/src/rust/engine/process_executor/src/main.rs @@ -14,8 +14,8 @@ use clap::StructOpt; use fs::{DirectoryDigest, Permissions, RelativePath}; use hashing::{Digest, Fingerprint}; use process_execution::{ - local::KeepSandboxes, CacheContentBehavior, Context, InputDigests, NamedCaches, Platform, - ProcessCacheScope, ProcessExecutionEnvironment, ProcessExecutionStrategy, + CacheContentBehavior, Context, InputDigests, NamedCaches, Platform, ProcessCacheScope, + ProcessExecutionEnvironment, ProcessExecutionStrategy, local::KeepSandboxes, }; use prost::Message; use protos::gen::build::bazel::remote::execution::v2::{Action, Command}; @@ -24,7 +24,7 @@ use protos::require_digest; use remote::remote_cache::RemoteCacheRunnerOptions; use store::{ImmutableInputs, RemoteProvider, RemoteStoreOptions, Store}; use tokio::sync::RwLock; -use workunit_store::{in_workunit, Level, WorkunitStore}; +use workunit_store::{Level, WorkunitStore, in_workunit}; #[derive(Clone, Debug, Default)] struct ProcessMetadata { @@ -314,7 +314,9 @@ async fn main() { (Some(certs), Some(key)) => Some((certs, key)), (None, None) => None, _ => { - panic!("Must specify both --cas-client-certs-file and --cas-client-key-file or neither") + panic!( + "Must specify both --cas-client-certs-file and --cas-client-key-file or neither" + ) } }; diff --git a/src/rust/engine/protos/src/hashing.rs b/src/rust/engine/protos/src/hashing.rs index 9d1e5d08c8a..f5e399114a0 100644 --- a/src/rust/engine/protos/src/hashing.rs +++ b/src/rust/engine/protos/src/hashing.rs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0 (see LICENSE). use std::hash::{Hash, Hasher}; -use crate::gen::pants::cache::dependency_inference_request::Metadata; use crate::gen::pants::cache::JavascriptInferenceMetadata; +use crate::gen::pants::cache::dependency_inference_request::Metadata; impl Hash for JavascriptInferenceMetadata { fn hash(&self, state: &mut H) { diff --git a/src/rust/engine/protos/src/lib.rs b/src/rust/engine/protos/src/lib.rs index 06bd343c138..5b2ab61b512 100644 --- a/src/rust/engine/protos/src/lib.rs +++ b/src/rust/engine/protos/src/lib.rs @@ -38,11 +38,11 @@ pub mod gen { pub fn empty_digest() -> Digest { Digest { - hash: String::from( - "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - ), - size_bytes: 0, - } + hash: String::from( + "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + ), + size_bytes: 0, + } } } } diff --git a/src/rust/engine/protos/src/verification.rs b/src/rust/engine/protos/src/verification.rs index 007a7b840bd..48d1fe95531 100644 --- a/src/rust/engine/protos/src/verification.rs +++ b/src/rust/engine/protos/src/verification.rs @@ -27,8 +27,8 @@ pub fn verify_directory_canonical( .collect(); if child_names.len() != directory.files.len() + directory.directories.len() { return Err(format!( - "Child paths must be unique, but a child path of {digest:?} was both a file and a directory: {directory:?}" - )); + "Child paths must be unique, but a child path of {digest:?} was both a file and a directory: {directory:?}" + )); } Ok(()) } diff --git a/src/rust/engine/remote_provider/remote_provider_opendal/src/byte_store_tests.rs b/src/rust/engine/remote_provider/remote_provider_opendal/src/byte_store_tests.rs index 9fd4bf1e391..1d7b664baa5 100644 --- a/src/rust/engine/remote_provider/remote_provider_opendal/src/byte_store_tests.rs +++ b/src/rust/engine/remote_provider/remote_provider_opendal/src/byte_store_tests.rs @@ -180,11 +180,13 @@ async fn store_bytes_empty() { .unwrap(); // We don't actually store an empty file. - assert!(!provider - .operator - .exists(&test_path(&testdata)) - .await - .unwrap()); + assert!( + !provider + .operator + .exists(&test_path(&testdata)) + .await + .unwrap() + ); } #[tokio::test] @@ -235,11 +237,13 @@ async fn store_file_empty_file() { .unwrap(); // We don't actually store an empty file. - assert!(!provider - .operator - .exists(&test_path(&testdata)) - .await - .unwrap()); + assert!( + !provider + .operator + .exists(&test_path(&testdata)) + .await + .unwrap() + ); } #[tokio::test] diff --git a/src/rust/engine/remote_provider/remote_provider_opendal/src/lib.rs b/src/rust/engine/remote_provider/remote_provider_opendal/src/lib.rs index a67fa75d671..ac1f0da0b41 100644 --- a/src/rust/engine/remote_provider/remote_provider_opendal/src/lib.rs +++ b/src/rust/engine/remote_provider/remote_provider_opendal/src/lib.rs @@ -8,7 +8,7 @@ use async_trait::async_trait; use bytes::Bytes; use futures::future; use grpc_util::prost::MessageExt; -use hashing::{async_verified_copy, Digest, Fingerprint, EMPTY_DIGEST}; +use hashing::{Digest, EMPTY_DIGEST, Fingerprint, async_verified_copy}; use http::header::AUTHORIZATION; use opendal::layers::{ConcurrentLimitLayer, RetryLayer, TimeoutLayer}; use opendal::{Builder, Operator}; diff --git a/src/rust/engine/remote_provider/remote_provider_reapi/src/action_cache.rs b/src/rust/engine/remote_provider/remote_provider_reapi/src/action_cache.rs index f8f82beb7e1..17517b001af 100644 --- a/src/rust/engine/remote_provider/remote_provider_reapi/src/action_cache.rs +++ b/src/rust/engine/remote_provider/remote_provider_reapi/src/action_cache.rs @@ -5,11 +5,11 @@ use std::sync::Arc; use async_trait::async_trait; use grpc_util::retry::{retry_call, status_is_retryable}; -use grpc_util::{headers_to_http_header_map, layered_service, status_to_str, LayeredService}; +use grpc_util::{LayeredService, headers_to_http_header_map, layered_service, status_to_str}; use hashing::Digest; use protos::gen::build::bazel::remote::execution::v2 as remexec; -use remexec::action_cache_client::ActionCacheClient; use remexec::ActionResult; +use remexec::action_cache_client::ActionCacheClient; use remote_provider_traits::{ActionCacheProvider, RemoteStoreOptions}; use workunit_store::Metric; diff --git a/src/rust/engine/remote_provider/remote_provider_reapi/src/byte_store.rs b/src/rust/engine/remote_provider/remote_provider_reapi/src/byte_store.rs index eb98b40ef7f..1bb6b9e2b99 100644 --- a/src/rust/engine/remote_provider/remote_provider_reapi/src/byte_store.rs +++ b/src/rust/engine/remote_provider/remote_provider_reapi/src/byte_store.rs @@ -13,15 +13,14 @@ use bytes::Bytes; use futures::{FutureExt, StreamExt}; use grpc_util::retry::{retry_call, status_is_retryable}; use grpc_util::{ - headers_to_http_header_map, layered_service, status_ref_to_str, status_to_str, LayeredService, + LayeredService, headers_to_http_header_map, layered_service, status_ref_to_str, status_to_str, }; use hashing::{Digest, Hasher}; use protos::gen::build::bazel::remote::execution::v2 as remexec; use protos::gen::google::bytestream::byte_stream_client::ByteStreamClient; use remexec::{ - capabilities_client::CapabilitiesClient, - content_addressable_storage_client::ContentAddressableStorageClient, BatchUpdateBlobsRequest, - ServerCapabilities, + BatchUpdateBlobsRequest, ServerCapabilities, capabilities_client::CapabilitiesClient, + content_addressable_storage_client::ContentAddressableStorageClient, }; use tokio::fs::File; use tokio::io::{AsyncRead, AsyncSeekExt, AsyncWriteExt}; diff --git a/src/rust/engine/remote_provider/remote_provider_reapi/src/lib.rs b/src/rust/engine/remote_provider/remote_provider_reapi/src/lib.rs index b1f45a74070..081aad8b9d7 100644 --- a/src/rust/engine/remote_provider/remote_provider_reapi/src/lib.rs +++ b/src/rust/engine/remote_provider/remote_provider_reapi/src/lib.rs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0 (see LICENSE). use protos::gen::build::bazel::remote::execution::v2 as remexec; -use tonic::metadata::BinaryMetadataValue; use tonic::Request; +use tonic::metadata::BinaryMetadataValue; use grpc_util::prost::MessageExt; diff --git a/src/rust/engine/rule_graph/src/builder.rs b/src/rust/engine/rule_graph/src/builder.rs index af29146bdf4..67f68e63d16 100644 --- a/src/rust/engine/rule_graph/src/builder.rs +++ b/src/rust/engine/rule_graph/src/builder.rs @@ -3,7 +3,7 @@ use crate::rules::{CallSignature, DependencyKey, ParamTypes, Query, Rule, RuleId}; use crate::{ - params_str, Entry, EntryWithDeps, Reentry, RootEntry, RuleEdges, RuleEntry, RuleGraph, + Entry, EntryWithDeps, Reentry, RootEntry, RuleEdges, RuleEntry, RuleGraph, params_str, }; use std::borrow::Cow; @@ -13,9 +13,9 @@ use fnv::{FnvHashMap as HashMap, FnvHashSet as HashSet}; use indexmap::IndexSet; use internment::Intern; use itertools::Itertools; +use petgraph::Direction; use petgraph::graph::{DiGraph, EdgeReference, NodeIndex}; use petgraph::visit::{DfsPostOrder, EdgeRef, IntoNodeReferences, NodeRef, VisitMap, Visitable}; -use petgraph::Direction; #[derive(Debug, Eq, PartialEq, Hash, Clone)] enum Node { @@ -720,13 +720,13 @@ impl Builder { }) .count(); log::trace!( - "rule_graph monomorphize: iteration {}: live: {}, minimal: {}, to_visit: {}, total: {}", - iteration, - live_count, - minimal_count, - to_visit.len(), - graph.node_count(), - ); + "rule_graph monomorphize: iteration {}: live: {}, minimal: {}, to_visit: {}, total: {}", + iteration, + live_count, + minimal_count, + to_visit.len(), + graph.node_count(), + ); } // Group dependencies by DependencyKey. @@ -782,27 +782,27 @@ impl Builder { let trace_str = if looping { format!( - "creating monomorphizations (from {} dependent sets and {:?} dependencies) for {:?}: {} with {:#?} and {:#?}", - dependents_by_out_set.len(), - dependencies_by_key - .iter() - .map(|edges| edges.len()) - .collect::>(), - node_id, - graph[node_id], - dependencies_by_key - .iter() - .flat_map(|choices| { - choices - .iter() - .map(|(dk, di)| (dk.to_string(), graph[*di].to_string())) - }) - .collect::>(), - dependents_by_out_set - .keys() - .map(params_str) - .collect::>(), - ) + "creating monomorphizations (from {} dependent sets and {:?} dependencies) for {:?}: {} with {:#?} and {:#?}", + dependents_by_out_set.len(), + dependencies_by_key + .iter() + .map(|edges| edges.len()) + .collect::>(), + node_id, + graph[node_id], + dependencies_by_key + .iter() + .flat_map(|choices| { + choices + .iter() + .map(|(dk, di)| (dk.to_string(), graph[*di].to_string())) + }) + .collect::>(), + dependents_by_out_set + .keys() + .map(params_str) + .collect::>(), + ) } else { "".to_owned() }; @@ -930,16 +930,19 @@ impl Builder { if looping { log::trace!( - " generating {:#?}, with {} dependents and {} dependencies ({} minimal) which consumes: {:#?}", - new_node, - dependents.len(), - dependencies.len(), - dependencies.iter().filter(|(_, dependency_id)| minimal_in_set.contains(dependency_id)).count(), - dependencies - .iter() - .map(|(dk, di)| (dk.to_string(), graph[*di].to_string(),)) - .collect::>() - ); + " generating {:#?}, with {} dependents and {} dependencies ({} minimal) which consumes: {:#?}", + new_node, + dependents.len(), + dependencies.len(), + dependencies + .iter() + .filter(|(_, dependency_id)| minimal_in_set.contains(dependency_id)) + .count(), + dependencies + .iter() + .map(|(dk, di)| (dk.to_string(), graph[*di].to_string(),)) + .collect::>() + ); } let replacement_id = graph.add_node(MaybeDeleted::new(new_node)); @@ -1323,12 +1326,12 @@ impl Builder { ) } else { format!( - "No installed rules return the type {} to satisfy {} for {}.\nEnsure that the rule you are \ + "No installed rules return the type {} to satisfy {} for {}.\nEnsure that the rule you are \ expecting to use is installed.", - dependency_key.product(), - dependency_key, - node, - ) + dependency_key.product(), + dependency_key, + node, + ) } } @@ -1439,8 +1442,8 @@ impl Builder { Entry::Param(p) => { if !dependencies.is_empty() { return Err(format!( - "Param {p} should not have had dependencies, but had: {dependencies:#?}", - )); + "Param {p} should not have had dependencies, but had: {dependencies:#?}", + )); } } } diff --git a/src/rust/engine/rule_graph/src/lib.rs b/src/rust/engine/rule_graph/src/lib.rs index 674967a7eb9..360c37b5f3d 100644 --- a/src/rust/engine/rule_graph/src/lib.rs +++ b/src/rust/engine/rule_graph/src/lib.rs @@ -397,11 +397,11 @@ impl RuleGraph { } else { suggestions.sort(); format!( - "can compute {} given input Params({}), but it can be produced using:\n {}", - product, - params_str(¶ms), - suggestions.join("\n ") - ) + "can compute {} given input Params({}), but it can be produced using:\n {}", + product, + params_str(¶ms), + suggestions.join("\n ") + ) }; Err(format!("No installed QueryRules {suggestions_str}",)) } diff --git a/src/rust/engine/rule_graph/src/rules.rs b/src/rust/engine/rule_graph/src/rules.rs index cd2a80fe9fd..a7e7f3e64a2 100644 --- a/src/rust/engine/rule_graph/src/rules.rs +++ b/src/rust/engine/rule_graph/src/rules.rs @@ -9,7 +9,7 @@ use std::hash::Hash; use deepsize::DeepSizeOf; use smallvec::SmallVec; -use super::{params_str, Palette}; +use super::{Palette, params_str}; pub type ParamTypes = BTreeSet; @@ -216,19 +216,11 @@ pub struct DisplayForGraphArgs { impl DisplayForGraphArgs { pub fn line_separator(&self) -> &'static str { - if self.multiline { - "\n" - } else { - " " - } + if self.multiline { "\n" } else { " " } } pub fn optional_line_separator(&self) -> &'static str { - if self.multiline { - "\n" - } else { - "" - } + if self.multiline { "\n" } else { "" } } } diff --git a/src/rust/engine/rule_graph/src/tests.rs b/src/rust/engine/rule_graph/src/tests.rs index f8f3435807e..fe51007a2db 100644 --- a/src/rust/engine/rule_graph/src/tests.rs +++ b/src/rust/engine/rule_graph/src/tests.rs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0 (see LICENSE). use std::fmt; -use indexmap::{indexset, IndexSet}; +use indexmap::{IndexSet, indexset}; use crate::builder::combinations_of_one; use crate::{DependencyKey, Palette, Query, RuleGraph, RuleId}; @@ -42,10 +42,12 @@ fn validation() { Rule::new("t", "get_t", vec![DependencyKey::new("v")]) ]; let queries = indexset![Query::new("a", vec!["b"])]; - assert!(RuleGraph::new(rules, queries) - .err() - .unwrap() - .contains("The following rule ids were each used by more than one rule: get_a, get_t")); + assert!( + RuleGraph::new(rules, queries) + .err() + .unwrap() + .contains("The following rule ids were each used by more than one rule: get_a, get_t") + ); } #[test] @@ -73,10 +75,12 @@ fn insufficient_query() { let rules = indexset![Rule::new("a", "a_from_b", vec![DependencyKey::new("b")])]; let queries = indexset![Query::new("a", vec![])]; - assert!(RuleGraph::new(rules, queries) - .err() - .unwrap() - .contains("No installed rules return the type b")); + assert!( + RuleGraph::new(rules, queries) + .err() + .unwrap() + .contains("No installed rules return the type b") + ); } #[test] @@ -84,10 +88,12 @@ fn no_rules() { let rules: IndexSet = indexset![]; let queries = indexset![Query::new("a", vec![])]; - assert!(RuleGraph::new(rules, queries) - .err() - .unwrap() - .contains("No installed rules return the type a")); + assert!( + RuleGraph::new(rules, queries) + .err() + .unwrap() + .contains("No installed rules return the type a") + ); } #[test] @@ -98,10 +104,12 @@ fn ambiguity() { ]; let queries = indexset![Query::new("a", vec!["b", "c"])]; - assert!(RuleGraph::new(rules, queries) - .err() - .unwrap() - .contains("Encountered 1 rule graph error:\n Too many")); + assert!( + RuleGraph::new(rules, queries) + .err() + .unwrap() + .contains("Encountered 1 rule graph error:\n Too many") + ); } #[test] @@ -303,9 +311,11 @@ fn in_scope_basic() { Rule::new( "a", "a_from_b", - vec![DependencyKey::new("b") - .provided_params(vec!["c"]) - .in_scope_params(vec!["d"])] + vec![ + DependencyKey::new("b") + .provided_params(vec!["c"]) + .in_scope_params(vec!["d"]) + ] ), Rule::new("b", "b_from_c_and_d", vec![DependencyKey::new("c")],), ]; @@ -327,9 +337,11 @@ fn in_scope_filtered() { Rule::new( "a", "a_from_b", - vec![DependencyKey::new("b") - .provided_params(vec!["c"]) - .in_scope_params(vec!["d"])] + vec![ + DependencyKey::new("b") + .provided_params(vec!["c"]) + .in_scope_params(vec!["d"]) + ] ), Rule::new( "b", @@ -351,9 +363,11 @@ fn in_scope_computed() { Rule::new( "a", "a_from_b", - vec![DependencyKey::new("b") - .provided_params(vec!["c"]) - .in_scope_params(vec!["d"])] + vec![ + DependencyKey::new("b") + .provided_params(vec!["c"]) + .in_scope_params(vec!["d"]) + ] ), Rule::new("b", "b_from_c", vec![DependencyKey::new("c")],), Rule::new("d", "d", vec![],), @@ -373,9 +387,11 @@ fn in_scope_provided() { Rule::new( "a", "a_from_b", - vec![DependencyKey::new("b") - .provided_params(vec!["c", "d"]) - .in_scope_params(vec!["d"])] + vec![ + DependencyKey::new("b") + .provided_params(vec!["c", "d"]) + .in_scope_params(vec!["d"]) + ] ), Rule::new( "b", diff --git a/src/rust/engine/rustfmt.toml b/src/rust/engine/rustfmt.toml new file mode 100644 index 00000000000..3501136812c --- /dev/null +++ b/src/rust/engine/rustfmt.toml @@ -0,0 +1 @@ +style_edition = "2024" diff --git a/src/rust/engine/sharded_lmdb/src/lib.rs b/src/rust/engine/sharded_lmdb/src/lib.rs index 2151ee87b74..8cbb50b984a 100644 --- a/src/rust/engine/sharded_lmdb/src/lib.rs +++ b/src/rust/engine/sharded_lmdb/src/lib.rs @@ -10,7 +10,7 @@ use std::sync::Arc; use std::time::{self, Duration}; use bytes::{BufMut, Bytes}; -use hashing::{sync_verified_copy, AgedFingerprint, Digest, Fingerprint, FINGERPRINT_SIZE}; +use hashing::{AgedFingerprint, Digest, FINGERPRINT_SIZE, Fingerprint, sync_verified_copy}; use lmdb::{ self, Cursor, Database, DatabaseFlags, Environment, EnvironmentCopyFlags, EnvironmentFlags, RwTransaction, Transaction, WriteFlags, @@ -609,10 +609,10 @@ impl ShardedLmdb { } Err(StoreError::Lmdb(lmdb::Error::KeyExist)) => return Ok(()), Err(StoreError::Lmdb(err)) => { - return Err(format!("Error storing {expected_digest:?}: {err}")) + return Err(format!("Error storing {expected_digest:?}: {err}")); } Err(StoreError::Io(err)) => { - return Err(format!("Error storing {expected_digest:?}: {err}")) + return Err(format!("Error storing {expected_digest:?}: {err}")); } }; } diff --git a/src/rust/engine/sharded_lmdb/src/tests.rs b/src/rust/engine/sharded_lmdb/src/tests.rs index 998b4a53587..68cd601a3fe 100644 --- a/src/rust/engine/sharded_lmdb/src/tests.rs +++ b/src/rust/engine/sharded_lmdb/src/tests.rs @@ -8,7 +8,7 @@ use parking_lot::Mutex; use task_executor::Executor; use tempfile::TempDir; -use crate::{ShardedLmdb, DEFAULT_LEASE_TIME}; +use crate::{DEFAULT_LEASE_TIME, ShardedLmdb}; fn new_store(shard_count: u8) -> (ShardedLmdb, TempDir) { let tempdir = TempDir::new().unwrap(); diff --git a/src/rust/engine/src/context.rs b/src/rust/engine/src/context.rs index 7878a85a76f..770844261b7 100644 --- a/src/rust/engine/src/context.rs +++ b/src/rust/engine/src/context.rs @@ -11,7 +11,7 @@ use std::sync::Arc; use std::time::Duration; use crate::nodes::{ExecuteProcess, NodeKey, NodeOutput, NodeResult, SubjectPath}; -use crate::python::{throw, Failure}; +use crate::python::{Failure, throw}; use crate::session::{Session, Sessions}; use crate::tasks::{Rule, Tasks}; use crate::types::Types; @@ -21,14 +21,14 @@ use fs::{GitignoreStyleExcludes, PosixFS}; use futures::FutureExt; use graph::{Graph, InvalidationResult}; use hashing::Digest; -use log::{log, Level}; +use log::{Level, log}; use parking_lot::Mutex; // use docker::docker::{self, DOCKER, IMAGE_PULL_CACHE}; use docker::docker; use process_execution::switched::SwitchedCommandRunner; use process_execution::{ - self, bounded, local, CacheContentBehavior, CommandRunner, NamedCaches, - ProcessExecutionStrategy, + self, CacheContentBehavior, CommandRunner, NamedCaches, ProcessExecutionStrategy, bounded, + local, }; use regex::Regex; use remote::remote_cache::{RemoteCacheRunnerOptions, RemoteCacheWarningsBehavior}; @@ -914,9 +914,9 @@ impl SessionCore { // TODO: This message should likely be at `info`, or eventually, debug. // see https://github.com/pantsbuild/pants/issues/15867 log::warn!( - "Making attempt {new_level} to backtrack and retry `{description}`, due to \ + "Making attempt {new_level} to backtrack and retry `{description}`, due to \ missing digest {digest:?}." - ); + ); Some(root) } else { None diff --git a/src/rust/engine/src/downloads.rs b/src/rust/engine/src/downloads.rs index 60818cf297d..d02bff5f821 100644 --- a/src/rust/engine/src/downloads.rs +++ b/src/rust/engine/src/downloads.rs @@ -10,17 +10,17 @@ use std::time::Duration; use async_trait::async_trait; use bytes::{BufMut, Bytes}; -use futures::stream::StreamExt; use futures::TryFutureExt; +use futures::stream::StreamExt; use hashing::Digest; -use humansize::{file_size_opts, FileSize}; -use reqwest::header::{HeaderMap, HeaderName}; +use humansize::{FileSize, file_size_opts}; use reqwest::Error; +use reqwest::header::{HeaderMap, HeaderName}; use store::Store; -use tokio_retry2::{strategy::ExponentialFactorBackoff, Retry, RetryError}; +use tokio_retry2::{Retry, RetryError, strategy::ExponentialFactorBackoff}; use url::Url; -use workunit_store::{in_workunit, Level}; +use workunit_store::{Level, in_workunit}; #[derive(Debug)] enum StreamingError { @@ -287,13 +287,13 @@ mod tests { net::SocketAddr, num::NonZeroUsize, sync::{ - atomic::{AtomicU32, Ordering}, Arc, + atomic::{AtomicU32, Ordering}, }, time::Duration, }; - use axum::{extract::State, response::IntoResponse, routing::get, Router}; + use axum::{Router, extract::State, response::IntoResponse, routing::get}; use hashing::Digest; use maplit::hashset; use reqwest::StatusCode; diff --git a/src/rust/engine/src/externs/address.rs b/src/rust/engine/src/externs/address.rs index 885be0d2a2f..a279f0486a0 100644 --- a/src/rust/engine/src/externs/address.rs +++ b/src/rust/engine/src/externs/address.rs @@ -297,13 +297,13 @@ impl AddressInput { // AddressSpec constructor because we weren't sure if the path_spec referred to a file // vs. a directory. return Err(InvalidTargetNameError::new_err(format!( - "Addresses for generated first-party targets in the build root must include \ + "Addresses for generated first-party targets in the build root must include \ which target generator they come from, such as `{}:original_target`. However, \ `{}` from {} did not have a target name.", - self.path_component.display(), - self.original_spec, - self.description_of_origin, - ))); + self.path_component.display(), + self.original_spec, + self.description_of_origin, + ))); } } }; @@ -472,12 +472,12 @@ impl Address { .collect::>(); if !banned.is_empty() { return Err(InvalidTargetNameError::new_err(format!( - "The generated name `{generated_name}` (defined in directory {}, the part after \ + "The generated name `{generated_name}` (defined in directory {}, the part after \ `#`) contains banned characters (`{}`). Please replace \ these characters with another separator character like `_`, `-`, or `/`.", - spec_path.display(), - banned.join(","), - ))); + spec_path.display(), + banned.join(","), + ))); } } diff --git a/src/rust/engine/src/externs/dep_inference.rs b/src/rust/engine/src/externs/dep_inference.rs index 24dd2a58da7..c467fdca10e 100644 --- a/src/rust/engine/src/externs/dep_inference.rs +++ b/src/rust/engine/src/externs/dep_inference.rs @@ -9,7 +9,7 @@ use pyo3::types::PyDict; use fs::DirectoryDigest; use protos::gen::pants::cache::{ - dependency_inference_request, javascript_inference_metadata, JavascriptInferenceMetadata, + JavascriptInferenceMetadata, dependency_inference_request, javascript_inference_metadata, }; use crate::externs::fs::PyDigest; diff --git a/src/rust/engine/src/externs/engine_aware.rs b/src/rust/engine/src/externs/engine_aware.rs index 929ba4cabdf..b83a84c887c 100644 --- a/src/rust/engine/src/externs/engine_aware.rs +++ b/src/rust/engine/src/externs/engine_aware.rs @@ -3,10 +3,10 @@ use std::sync::Arc; +use crate::Value; use crate::externs; use crate::externs::fs::PyFileDigest; use crate::nodes::{lift_directory_digest, lift_file_digest}; -use crate::Value; use pyo3::prelude::*; use pyo3::types::PyDict; diff --git a/src/rust/engine/src/externs/fs.rs b/src/rust/engine/src/externs/fs.rs index 909766747a2..965c8a20bd0 100644 --- a/src/rust/engine/src/externs/fs.rs +++ b/src/rust/engine/src/externs/fs.rs @@ -15,14 +15,14 @@ use pyo3::pybacked::PyBackedStr; use pyo3::types::{PyIterator, PyString, PyTuple, PyType}; use fs::{ - DirectoryDigest, FilespecMatcher, GlobExpansionConjunction, PathGlobs, PathMetadata, - StrictGlobMatching, EMPTY_DIRECTORY_DIGEST, + DirectoryDigest, EMPTY_DIRECTORY_DIGEST, FilespecMatcher, GlobExpansionConjunction, PathGlobs, + PathMetadata, StrictGlobMatching, }; -use hashing::{Digest, Fingerprint, EMPTY_DIGEST}; +use hashing::{Digest, EMPTY_DIGEST, Fingerprint}; use store::Snapshot; -use crate::python::PyComparedBool; use crate::Failure; +use crate::python::PyComparedBool; pub(crate) fn register(m: &Bound<'_, PyModule>) -> PyResult<()> { m.add_class::()?; diff --git a/src/rust/engine/src/externs/interface.rs b/src/rust/engine/src/externs/interface.rs index d5bbbdf431a..007024ef0f9 100644 --- a/src/rust/engine/src/externs/interface.rs +++ b/src/rust/engine/src/externs/interface.rs @@ -23,25 +23,25 @@ use std::time::Duration; use async_latch::AsyncLatch; use fnv::FnvHasher; use fs::DirectoryDigest; -use futures::future::{self, FutureExt}; use futures::Future; +use futures::future::{self, FutureExt}; use hashing::Digest; -use log::{self, debug, error, warn, Log}; +use log::{self, Log, debug, error, warn}; use logging::logger::PANTS_LOGGER; use logging::{Logger, PythonLogLevel}; use petgraph::graph::{DiGraph, Graph}; use process_execution::CacheContentBehavior; use pyo3::exceptions::{PyException, PyIOError, PyKeyboardInterrupt, PyValueError}; use pyo3::prelude::{ - pyclass, pyfunction, pymethods, pymodule, wrap_pyfunction, PyModule, PyObject, - PyResult as PyO3Result, Python, + PyModule, PyObject, PyResult as PyO3Result, Python, pyclass, pyfunction, pymethods, pymodule, + wrap_pyfunction, }; use pyo3::sync::GILProtected; use pyo3::types::{ PyAnyMethods, PyBytes, PyDict, PyDictMethods, PyList, PyListMethods, PyModuleMethods, PyTuple, PyType, }; -use pyo3::{create_exception, Bound, IntoPyObject, PyAny, PyRef}; +use pyo3::{Bound, IntoPyObject, PyAny, PyRef, create_exception}; use regex::Regex; use remote::remote_cache::RemoteCacheWarningsBehavior; use rule_graph::{self, RuleGraph}; @@ -53,13 +53,13 @@ use workunit_store::{ WorkunitStoreHandle, }; -use crate::externs::fs::{possible_store_missing_digest, PyFileDigest}; +use crate::externs::fs::{PyFileDigest, possible_store_missing_digest}; use crate::externs::process::PyProcessExecutionEnvironment; use crate::intrinsics; use crate::{ - externs, nodes, Core, ExecutionRequest, ExecutionStrategyOptions, ExecutionTermination, - Failure, Function, Key, LocalStoreOptions, Params, RemotingOptions, Rule, Scheduler, Session, - SessionCore, Tasks, TypeId, Types, Value, + Core, ExecutionRequest, ExecutionStrategyOptions, ExecutionTermination, Failure, Function, Key, + LocalStoreOptions, Params, RemotingOptions, Rule, Scheduler, Session, SessionCore, Tasks, + TypeId, Types, Value, externs, nodes, }; #[pymodule] diff --git a/src/rust/engine/src/externs/mod.rs b/src/rust/engine/src/externs/mod.rs index 5a3a2ff712c..d1a1e467354 100644 --- a/src/rust/engine/src/externs/mod.rs +++ b/src/rust/engine/src/externs/mod.rs @@ -4,15 +4,15 @@ // File-specific allowances to silence internal warnings of `[pyclass]`. #![allow(clippy::used_underscore_binding)] -use futures::future::{BoxFuture, Future}; use futures::FutureExt; +use futures::future::{BoxFuture, Future}; +use pyo3::FromPyObject; use pyo3::exceptions::{PyAssertionError, PyException, PyStopIteration, PyTypeError, PyValueError}; use pyo3::prelude::*; use pyo3::sync::GILProtected; use pyo3::types::{PyBool, PyBytes, PyDict, PySequence, PyString, PyTuple, PyType}; -use pyo3::FromPyObject; use pyo3::{create_exception, import_exception, intern}; -use smallvec::{smallvec, SmallVec}; +use smallvec::{SmallVec, smallvec}; use std::cell::{Ref, RefCell}; use std::collections::BTreeMap; use std::convert::TryInto; @@ -376,8 +376,8 @@ pub(crate) fn generator_send( Ok(GeneratorResponse::All(gogs)) } else { Err(PyValueError::new_err(format!( - "Async @rule error. Expected a rule query such as `Get(..)` or similar, but got: {response}" - ))) + "Async @rule error. Expected a rule query such as `Get(..)` or similar, but got: {response}" + ))) }; Ok(result?) @@ -470,9 +470,9 @@ fn interpret_get_inputs( let actual_type = input_arg1.get_type(); if !declared_type.is(&actual_type) && !is_union(py, declared_type)? { return Err(PyTypeError::new_err(format!( - "Invalid Get. The third argument `{input_arg1}` must have the exact same type as the \ + "Invalid Get. The third argument `{input_arg1}` must have the exact same type as the \ second argument, {declared_type}, but had the type {actual_type}." - ))); + ))); } Ok(( diff --git a/src/rust/engine/src/externs/options.rs b/src/rust/engine/src/externs/options.rs index b3ddf5e1163..4356a2b51dc 100644 --- a/src/rust/engine/src/externs/options.rs +++ b/src/rust/engine/src/externs/options.rs @@ -3,12 +3,12 @@ use pyo3::exceptions::PyException; use pyo3::types::{PyBool, PyDict, PyFloat, PyInt, PyList, PyString, PyTuple}; -use pyo3::{prelude::*, BoundObject}; +use pyo3::{BoundObject, prelude::*}; use options::{ - apply_dict_edits, apply_list_edits, bin_name, Args, ConfigSource, DictEdit, DictEditAction, - Env, GoalInfo, ListEdit, ListEditAction, ListOptionValue, OptionId, OptionParser, - OptionalOptionValue, PantsCommand, Scope, Source, Val, + Args, ConfigSource, DictEdit, DictEditAction, Env, GoalInfo, ListEdit, ListEditAction, + ListOptionValue, OptionId, OptionParser, OptionalOptionValue, PantsCommand, Scope, Source, Val, + apply_dict_edits, apply_list_edits, bin_name, }; use itertools::Itertools; @@ -166,7 +166,7 @@ impl PyOptionId { return Err(ParseError::new_err(format!( "Switch value should contain a single character, but was: {}", s - ))) + ))); } }; let option_id = diff --git a/src/rust/engine/src/intrinsics/dep_inference.rs b/src/rust/engine/src/intrinsics/dep_inference.rs index 4f022112c9d..45eae1e3232 100644 --- a/src/rust/engine/src/intrinsics/dep_inference.rs +++ b/src/rust/engine/src/intrinsics/dep_inference.rs @@ -13,19 +13,19 @@ use fs::{DirectoryDigest, Entry, SymlinkBehavior}; use grpc_util::prost::MessageExt; use hashing::Digest; use protos::gen::pants::cache::{ - dependency_inference_request, CacheKey, CacheKeyType, DependencyInferenceRequest, + CacheKey, CacheKeyType, DependencyInferenceRequest, dependency_inference_request, }; -use pyo3::prelude::{pyfunction, wrap_pyfunction, PyModule, PyResult, Python}; +use pyo3::prelude::{PyModule, PyResult, Python, pyfunction, wrap_pyfunction}; use pyo3::types::{PyAnyMethods, PyModuleMethods}; use pyo3::{Bound, IntoPyObject, PyErr}; use store::Store; -use workunit_store::{in_workunit, Level}; +use workunit_store::{Level, in_workunit}; use crate::externs::dep_inference::PyNativeDependenciesRequest; -use crate::externs::{store_dict, PyGeneratorResponseNativeCall}; -use crate::nodes::{task_get_context, NodeResult}; +use crate::externs::{PyGeneratorResponseNativeCall, store_dict}; +use crate::nodes::{NodeResult, task_get_context}; use crate::python::{Failure, Value}; -use crate::{externs, Core}; +use crate::{Core, externs}; pub fn register(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> { m.add_function(wrap_pyfunction!(parse_dockerfile_info, m)?)?; diff --git a/src/rust/engine/src/intrinsics/digests.rs b/src/rust/engine/src/intrinsics/digests.rs index 39673282e92..5ad6bb4eba8 100644 --- a/src/rust/engine/src/intrinsics/digests.rs +++ b/src/rust/engine/src/intrinsics/digests.rs @@ -9,22 +9,22 @@ use fs::{ DigestTrie, DirectoryDigest, GlobMatching, PathStat, RelativePath, SymlinkBehavior, TypedPath, }; use hashing::{Digest, EMPTY_DIGEST}; -use pyo3::prelude::{pyfunction, wrap_pyfunction, PyModule, PyRef, PyResult, Python}; +use pyo3::prelude::{PyModule, PyRef, PyResult, Python, pyfunction, wrap_pyfunction}; use pyo3::types::{PyAnyMethods, PyModuleMethods, PyTuple, PyTypeMethods}; use pyo3::{Bound, IntoPyObject, PyAny}; use store::{SnapshotOps, SubsetParams}; +use crate::Failure; use crate::externs; +use crate::externs::PyGeneratorResponseNativeCall; use crate::externs::fs::{ PyAddPrefix, PyFileDigest, PyMergeDigests, PyPathMetadata, PyPathNamespace, PyRemovePrefix, }; -use crate::externs::PyGeneratorResponseNativeCall; use crate::nodes::{ - lift_directory_digest, task_get_context, unmatched_globs_additional_context, DownloadedFile, - NodeResult, PathMetadataNode, Snapshot, SubjectPath, + DownloadedFile, NodeResult, PathMetadataNode, Snapshot, SubjectPath, lift_directory_digest, + task_get_context, unmatched_globs_additional_context, }; -use crate::python::{throw, Key, Value}; -use crate::Failure; +use crate::python::{Key, Value, throw}; pub fn register(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> { m.add_function(wrap_pyfunction!(add_prefix, m)?)?; diff --git a/src/rust/engine/src/intrinsics/docker.rs b/src/rust/engine/src/intrinsics/docker.rs index 9faa559195a..b0bc7efb7b0 100644 --- a/src/rust/engine/src/intrinsics/docker.rs +++ b/src/rust/engine/src/intrinsics/docker.rs @@ -1,11 +1,11 @@ // Copyright 2021 Pants project contributors (see CONTRIBUTORS.md). // Licensed under the Apache License, Version 2.0 (see LICENSE). -use docker::docker::{ImagePullPolicy, ImagePullScope, DOCKER, IMAGE_PULL_CACHE}; +use docker::docker::{DOCKER, IMAGE_PULL_CACHE, ImagePullPolicy, ImagePullScope}; use process_execution::Platform; -use pyo3::prelude::{pyfunction, wrap_pyfunction, PyModule, PyResult, Python}; -use pyo3::types::{PyModuleMethods, PyString}; use pyo3::Bound; +use pyo3::prelude::{PyModule, PyResult, Python, pyfunction, wrap_pyfunction}; +use pyo3::types::{PyModuleMethods, PyString}; use crate::externs::{self, PyGeneratorResponseNativeCall}; use crate::nodes::task_get_context; diff --git a/src/rust/engine/src/intrinsics/interactive_process.rs b/src/rust/engine/src/intrinsics/interactive_process.rs index 1585a652cc4..075323d9e9c 100644 --- a/src/rust/engine/src/intrinsics/interactive_process.rs +++ b/src/rust/engine/src/intrinsics/interactive_process.rs @@ -8,20 +8,20 @@ use std::str::FromStr; use futures::future::TryFutureExt; use process_execution::local::{ - apply_chroot, create_sandbox, prepare_workdir, setup_run_sh_script, KeepSandboxes, + KeepSandboxes, apply_chroot, create_sandbox, prepare_workdir, setup_run_sh_script, }; use process_execution::{ManagedChild, ProcessExecutionStrategy}; -use pyo3::prelude::{pyfunction, wrap_pyfunction, PyAny, PyModule, PyResult, Python}; +use pyo3::Bound; +use pyo3::prelude::{PyAny, PyModule, PyResult, Python, pyfunction, wrap_pyfunction}; use pyo3::pybacked::PyBackedStr; use pyo3::types::{PyAnyMethods, PyModuleMethods}; -use pyo3::Bound; use stdio::TryCloneAsFile; use tokio::process; -use workunit_store::{in_workunit, Level}; +use workunit_store::{Level, in_workunit}; use crate::context::Context; use crate::externs::{self, PyGeneratorResponseNativeCall}; -use crate::nodes::{task_get_context, ExecuteProcess, NodeResult}; +use crate::nodes::{ExecuteProcess, NodeResult, task_get_context}; use crate::python::{Failure, Value}; pub fn register(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> { diff --git a/src/rust/engine/src/intrinsics/process.rs b/src/rust/engine/src/intrinsics/process.rs index fbf7c6e26e4..dedb51146a9 100644 --- a/src/rust/engine/src/intrinsics/process.rs +++ b/src/rust/engine/src/intrinsics/process.rs @@ -6,10 +6,10 @@ use std::time::Duration; use futures::future::TryFutureExt; use futures::try_join; use pyo3::types::{PyAnyMethods, PyModule, PyModuleMethods}; -use pyo3::{pyfunction, wrap_pyfunction, Bound, IntoPyObject, PyResult, Python}; +use pyo3::{Bound, IntoPyObject, PyResult, Python, pyfunction, wrap_pyfunction}; use crate::externs::{self, PyGeneratorResponseNativeCall}; -use crate::nodes::{task_get_context, ExecuteProcess, NodeResult, Snapshot}; +use crate::nodes::{ExecuteProcess, NodeResult, Snapshot, task_get_context}; use crate::python::Value; pub fn register(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> { diff --git a/src/rust/engine/src/intrinsics/values.rs b/src/rust/engine/src/intrinsics/values.rs index c2d951bfa14..55ea4e8b095 100644 --- a/src/rust/engine/src/intrinsics/values.rs +++ b/src/rust/engine/src/intrinsics/values.rs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0 (see LICENSE). use pyo3::types::{PyModule, PyModuleMethods}; -use pyo3::{pyfunction, wrap_pyfunction, Bound, PyResult, Python}; +use pyo3::{Bound, PyResult, Python, pyfunction, wrap_pyfunction}; use crate::externs::PyGeneratorResponseNativeCall; -use crate::nodes::{task_get_context, RunId, SessionValues}; +use crate::nodes::{RunId, SessionValues, task_get_context}; pub fn register(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> { m.add_function(wrap_pyfunction!(session_values, m)?)?; diff --git a/src/rust/engine/src/nodes/downloaded_file.rs b/src/rust/engine/src/nodes/downloaded_file.rs index 1431f8640da..2bec8202dae 100644 --- a/src/rust/engine/src/nodes/downloaded_file.rs +++ b/src/rust/engine/src/nodes/downloaded_file.rs @@ -21,7 +21,7 @@ use crate::context::{Context, Core}; use crate::downloads; use crate::externs; use crate::externs::fs::PyFileDigest; -use crate::python::{throw, Key}; +use crate::python::{Key, throw}; #[derive(Clone, Debug, DeepSizeOf, Eq, Hash, PartialEq)] pub struct DownloadedFile(pub Key); diff --git a/src/rust/engine/src/nodes/execute_process.rs b/src/rust/engine/src/nodes/execute_process.rs index b90f4f04c33..e3e25e30749 100644 --- a/src/rust/engine/src/nodes/execute_process.rs +++ b/src/rust/engine/src/nodes/execute_process.rs @@ -12,18 +12,18 @@ use process_execution::{ self, CacheName, InputDigests, Process, ProcessCacheScope, ProcessExecutionStrategy, ProcessResultSource, }; +use pyo3::Bound; use pyo3::prelude::{PyAny, Python}; use pyo3::pybacked::PyBackedStr; -use pyo3::Bound; use store::{self, Store, StoreError}; use workunit_store::{ Metric, ObservationMetric, RunningWorkunit, UserMetadataItem, WorkunitMetadata, }; -use super::{lift_directory_digest, NodeKey, NodeOutput, NodeResult}; +use super::{NodeKey, NodeOutput, NodeResult, lift_directory_digest}; use crate::context::Context; use crate::externs; -use crate::python::{throw, Value}; +use crate::python::{Value, throw}; /// A Node that represents a process to execute. /// diff --git a/src/rust/engine/src/nodes/mod.rs b/src/rust/engine/src/nodes/mod.rs index 39093dcaf16..0a511d90aab 100644 --- a/src/rust/engine/src/nodes/mod.rs +++ b/src/rust/engine/src/nodes/mod.rs @@ -4,8 +4,8 @@ use std::convert::TryFrom; use std::fmt::Display; use std::path::{Path, PathBuf}; -use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; +use std::sync::atomic::{AtomicBool, Ordering}; use async_trait::async_trait; use deepsize::DeepSizeOf; @@ -16,17 +16,17 @@ use futures::future::{self, BoxFuture, FutureExt, TryFutureExt}; use graph::{Node, NodeError}; use internment::Intern; use process_execution::{self, ProcessCacheScope}; +use pyo3::Bound; use pyo3::prelude::{PyAny, Python}; use pyo3::types::{PyAnyMethods, PyTypeMethods}; -use pyo3::Bound; use rule_graph::{DependencyKey, Query}; use store::{self, StoreFileByDigest}; -use workunit_store::{in_workunit, Level}; +use workunit_store::{Level, in_workunit}; use crate::context::{Context, SessionCore}; use crate::externs; use crate::externs::engine_aware::{EngineAwareParameter, EngineAwareReturnType}; -use crate::python::{display_sorted_in_parens, throw, Failure, Key, Params, TypeId, Value}; +use crate::python::{Failure, Key, Params, TypeId, Value, display_sorted_in_parens, throw}; use crate::tasks::Rule; // Sub-modules for the differnt node kinds. @@ -238,10 +238,10 @@ pub fn unmatched_globs_additional_context() -> Option { ) }); Some(format!( - "\n\nDo the file(s) exist? If so, check if the file(s) are in your `.gitignore` or the global \ + "\n\nDo the file(s) exist? If so, check if the file(s) are in your `.gitignore` or the global \ `pants_ignore` option, which may result in Pants not being able to see the file(s) even though \ they exist on disk. Refer to {url}." - )) + )) } /// @@ -617,7 +617,10 @@ impl Node for NodeKey { path.push(path[0].clone()); } let url = Python::with_gil(|py| { - externs::doc_url(py, "docs/using-pants/key-concepts/targets-and-build-files#dependencies-and-dependency-inference") + externs::doc_url( + py, + "docs/using-pants/key-concepts/targets-and-build-files#dependencies-and-dependency-inference", + ) }); throw(format!( "The dependency graph contained a cycle:\ diff --git a/src/rust/engine/src/nodes/snapshot.rs b/src/rust/engine/src/nodes/snapshot.rs index a4dbb410a08..499e3f61d27 100644 --- a/src/rust/engine/src/nodes/snapshot.rs +++ b/src/rust/engine/src/nodes/snapshot.rs @@ -10,13 +10,13 @@ use fs::{ }; use futures::TryFutureExt; use graph::CompoundNode; -use pyo3::prelude::{Py, PyAny, Python}; use pyo3::Bound; +use pyo3::prelude::{Py, PyAny, Python}; -use super::{unmatched_globs_additional_context, NodeKey, NodeOutput, NodeResult}; +use super::{NodeKey, NodeOutput, NodeResult, unmatched_globs_additional_context}; use crate::context::Context; use crate::externs; -use crate::python::{throw, Value}; +use crate::python::{Value, throw}; /// /// A Node that captures an store::Snapshot for a PathGlobs subject. diff --git a/src/rust/engine/src/nodes/task.rs b/src/rust/engine/src/nodes/task.rs index 5d6f75a6511..d45394bf9a6 100644 --- a/src/rust/engine/src/nodes/task.rs +++ b/src/rust/engine/src/nodes/task.rs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0 (see LICENSE). use std::fmt; -use std::sync::atomic::AtomicBool; use std::sync::Arc; +use std::sync::atomic::AtomicBool; use deepsize::DeepSizeOf; use futures::future::{self, BoxFuture, FutureExt}; @@ -13,13 +13,13 @@ use pyo3::prelude::{PyAnyMethods, PyErr, Python}; use pyo3::types::{PyDict, PyDictMethods, PyTuple}; use pyo3::{Bound, IntoPyObject}; use rule_graph::DependencyKey; -use workunit_store::{in_workunit, Level, RunningWorkunit}; +use workunit_store::{Level, RunningWorkunit, in_workunit}; -use super::{select, task_context, NodeKey, NodeResult, Params}; +use super::{NodeKey, NodeResult, Params, select, task_context}; use crate::context::Context; use crate::externs::engine_aware::EngineAwareReturnType; use crate::externs::{self, GeneratorInput, GeneratorResponse}; -use crate::python::{throw, Failure, Key, TypeId, Value}; +use crate::python::{Failure, Key, TypeId, Value, throw}; use crate::tasks::{self, Rule}; #[derive(DeepSizeOf, Derivative, Clone)] diff --git a/src/rust/engine/src/python.rs b/src/rust/engine/src/python.rs index e3d0c26a4cd..0e362803209 100644 --- a/src/rust/engine/src/python.rs +++ b/src/rust/engine/src/python.rs @@ -5,10 +5,10 @@ use std::convert::Infallible; use std::sync::Arc; use std::{fmt, hash}; -use deepsize::{known_deep_size, DeepSizeOf}; +use deepsize::{DeepSizeOf, known_deep_size}; +use pyo3::FromPyObject; use pyo3::prelude::*; use pyo3::types::{PyBool, PyDict, PyType}; -use pyo3::FromPyObject; use smallvec::SmallVec; use hashing::Digest; @@ -475,11 +475,11 @@ impl Failure { // engine traceback and restoring the original python exception cause. py_err.set_cause(py, Some(PyErr::from_value(val.0.bind(py).to_owned()))); ( - format!( - "{python_traceback}\nDuring handling of the above exception, another exception occurred:\n\n" - ), - engine_traceback, - ) + format!( + "{python_traceback}\nDuring handling of the above exception, another exception occurred:\n\n" + ), + engine_traceback, + ) } _ => ("".to_string(), Vec::new()), } @@ -630,7 +630,7 @@ impl<'py> IntoPyObject<'py> for PyComparedBool { #[cfg(test)] mod pycomparedbool_tests { use super::PyComparedBool; - use pyo3::{types::PyAnyMethods, IntoPyObject, Python}; + use pyo3::{IntoPyObject, Python, types::PyAnyMethods}; #[test] fn pycomparedbool_conversion_tests() { @@ -653,10 +653,12 @@ mod pycomparedbool_tests { .unwrap(), false ); - assert!(PyComparedBool(None) - .into_pyobject(py) - .unwrap() - .is(&py.NotImplemented()),); + assert!( + PyComparedBool(None) + .into_pyobject(py) + .unwrap() + .is(&py.NotImplemented()), + ); }) } } diff --git a/src/rust/engine/src/scheduler.rs b/src/rust/engine/src/scheduler.rs index dc2fa331da3..1a746b85a7c 100644 --- a/src/rust/engine/src/scheduler.rs +++ b/src/rust/engine/src/scheduler.rs @@ -9,7 +9,7 @@ use std::sync::Arc; use std::time::{Duration, Instant}; use deepsize::DeepSizeOf; -use futures::{future, FutureExt}; +use futures::{FutureExt, future}; use log::debug; use tokio::time; diff --git a/src/rust/engine/src/session.rs b/src/rust/engine/src/session.rs index 78747768ee7..81672a31834 100644 --- a/src/rust/engine/src/session.rs +++ b/src/rust/engine/src/session.rs @@ -18,10 +18,10 @@ use log::warn; use parking_lot::Mutex; use pyo3::prelude::*; use task_executor::{Executor, TailTasks}; -use tokio::signal::unix::{signal, SignalKind}; +use tokio::signal::unix::{SignalKind, signal}; use tokio::task::JoinHandle; use ui::ConsoleUI; -use workunit_store::{format_workunit_duration_ms, RunId, WorkunitStore}; +use workunit_store::{RunId, WorkunitStore, format_workunit_duration_ms}; // When enabled, the interval at which all stragglers that have been running for longer than a // threshold should be logged. The threshold might become configurable, but this might not need diff --git a/src/rust/engine/stdio/src/lib.rs b/src/rust/engine/stdio/src/lib.rs index ba5abe784b0..2a0034e2f9b 100644 --- a/src/rust/engine/stdio/src/lib.rs +++ b/src/rust/engine/stdio/src/lib.rs @@ -158,7 +158,7 @@ impl Destination { _ => { return Err(format!( "Cannot start Exclusive access on Destination {destination:?}" - )) + )); } }; let console = std::mem::replace( diff --git a/src/rust/engine/testutil/mock/src/action_cache_service.rs b/src/rust/engine/testutil/mock/src/action_cache_service.rs index d8f23b99034..75d9730e3c9 100644 --- a/src/rust/engine/testutil/mock/src/action_cache_service.rs +++ b/src/rust/engine/testutil/mock/src/action_cache_service.rs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0 (see LICENSE). use std::collections::HashMap; -use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; +use std::sync::atomic::{AtomicBool, Ordering}; use std::time::Duration; use parking_lot::Mutex; @@ -128,7 +128,7 @@ impl ActionCache for ActionCacheResponder { None => { return Err(Status::invalid_argument( "Must provide action result".to_owned(), - )) + )); } }; diff --git a/src/rust/engine/testutil/mock/src/cas.rs b/src/rust/engine/testutil/mock/src/cas.rs index 3896e389b68..ee92ef2c979 100644 --- a/src/rust/engine/testutil/mock/src/cas.rs +++ b/src/rust/engine/testutil/mock/src/cas.rs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0 (see LICENSE). use std::collections::HashMap; use std::net::SocketAddr; -use std::sync::atomic::AtomicBool; use std::sync::Arc; +use std::sync::atomic::AtomicBool; use std::time::Duration; use bytes::Bytes; diff --git a/src/rust/engine/testutil/mock/src/cas_service.rs b/src/rust/engine/testutil/mock/src/cas_service.rs index 1d321ba29d4..43d559e12b4 100644 --- a/src/rust/engine/testutil/mock/src/cas_service.rs +++ b/src/rust/engine/testutil/mock/src/cas_service.rs @@ -6,15 +6,15 @@ use std::pin::Pin; use std::sync::Arc; use bytes::{Bytes, BytesMut}; -use futures::stream::StreamExt; use futures::Stream; +use futures::stream::StreamExt; use hashing::{Digest, Fingerprint}; use parking_lot::Mutex; use protos::gen::build::bazel::remote::execution::v2 as remexec; use protos::gen::build::bazel::semver::SemVer; use protos::gen::google::bytestream::{ - byte_stream_server::ByteStream, QueryWriteStatusRequest, QueryWriteStatusResponse, ReadRequest, - ReadResponse, WriteRequest, WriteResponse, + QueryWriteStatusRequest, QueryWriteStatusResponse, ReadRequest, ReadResponse, WriteRequest, + WriteResponse, byte_stream_server::ByteStream, }; use remexec::capabilities_server::Capabilities; use remexec::content_addressable_storage_server::ContentAddressableStorage; @@ -262,7 +262,7 @@ impl ByteStream for StubCASResponder { Err(e) => { return Err(Status::invalid_argument(format!( "Client sent an error: {e}" - ))) + ))); } }; @@ -271,9 +271,9 @@ impl ByteStream for StubCASResponder { Some(ref resource_name) => { if *resource_name != req.resource_name { return Err(Status::invalid_argument(format!( - "All resource names in stream must be the same. Got {} but earlier saw {}", - req.resource_name, resource_name - ))); + "All resource names in stream must be the same. Got {} but earlier saw {}", + req.resource_name, resource_name + ))); } } } @@ -556,8 +556,8 @@ impl Capabilities for StubCASResponder { #[cfg(test)] mod tests { use super::{ - parse_read_resource_name, parse_write_resource_name, ParsedReadResourceName, - ParsedWriteResourceName, + ParsedReadResourceName, ParsedWriteResourceName, parse_read_resource_name, + parse_write_resource_name, }; #[test] diff --git a/src/rust/engine/testutil/mock/src/execution_server.rs b/src/rust/engine/testutil/mock/src/execution_server.rs index 869a9b1ca5c..91951e22782 100644 --- a/src/rust/engine/testutil/mock/src/execution_server.rs +++ b/src/rust/engine/testutil/mock/src/execution_server.rs @@ -17,17 +17,17 @@ use parking_lot::Mutex; use protos::gen::build::bazel::remote::execution::v2 as remexec; use protos::gen::build::bazel::semver::SemVer; use protos::gen::google::longrunning::{ - operations_server::Operations, operations_server::OperationsServer, CancelOperationRequest, - DeleteOperationRequest, GetOperationRequest, ListOperationsRequest, ListOperationsResponse, - Operation, + CancelOperationRequest, DeleteOperationRequest, GetOperationRequest, ListOperationsRequest, + ListOperationsResponse, Operation, operations_server::Operations, + operations_server::OperationsServer, }; use protos::require_digest; use remexec::{ + ActionResult, CacheCapabilities, ExecuteRequest, ExecutionCapabilities, GetActionResultRequest, + GetCapabilitiesRequest, ServerCapabilities, UpdateActionResultRequest, WaitExecutionRequest, action_cache_server::ActionCache, action_cache_server::ActionCacheServer, capabilities_server::Capabilities, capabilities_server::CapabilitiesServer, - execution_server::Execution, execution_server::ExecutionServer, ActionResult, - CacheCapabilities, ExecuteRequest, ExecutionCapabilities, GetActionResultRequest, - GetCapabilitiesRequest, ServerCapabilities, UpdateActionResultRequest, WaitExecutionRequest, + execution_server::Execution, execution_server::ExecutionServer, }; use tokio_stream::wrappers::TcpListenerStream; use tonic::metadata::MetadataMap; @@ -174,22 +174,21 @@ impl Drop for TestServer { .len(); if remaining_expected_responses != 0 { let message = format!( - "Expected {} more requests. Remaining expected responses:\n{}\nReceived requests:\n{}", - remaining_expected_responses, - MockResponder::display_all(&Vec::from_iter( - self - .mock_responder - .mock_execution - .expected_api_calls - .lock() - .deref(), - )), - MockResponder::display_all(&self.mock_responder.received_messages.deref().lock()) - ); + "Expected {} more requests. Remaining expected responses:\n{}\nReceived requests:\n{}", + remaining_expected_responses, + MockResponder::display_all(&Vec::from_iter( + self.mock_responder + .mock_execution + .expected_api_calls + .lock() + .deref(), + )), + MockResponder::display_all(&self.mock_responder.received_messages.deref().lock()) + ); if std::thread::panicking() { eprintln!( - "TestServer missing requests, but not panicking because caller is already panicking: {message}" - ); + "TestServer missing requests, but not panicking because caller is already panicking: {message}" + ); } else { assert_eq!(remaining_expected_responses, 0, "{message}",); } @@ -291,8 +290,8 @@ impl Execution for MockResponder { } } else { return Err(Status::invalid_argument(format!( - "Did not expect this request. Expected: {execute_request:?}, Got: {request:?}" - ))); + "Did not expect this request. Expected: {execute_request:?}, Got: {request:?}" + ))); } } @@ -335,9 +334,9 @@ impl Execution for MockResponder { } } else { return Err(Status::invalid_argument(format!( - "Did not expect WaitExecution for this operation. Expected: {:?}, Got: {:?}", - operation_name, request.name - ))); + "Did not expect WaitExecution for this operation. Expected: {:?}, Got: {:?}", + operation_name, request.name + ))); } } diff --git a/src/rust/engine/tryfuture/src/lib.rs b/src/rust/engine/tryfuture/src/lib.rs index 8238d12a7ff..c96ebc0af65 100644 --- a/src/rust/engine/tryfuture/src/lib.rs +++ b/src/rust/engine/tryfuture/src/lib.rs @@ -25,8 +25,8 @@ macro_rules! try_future { #[cfg(test)] mod tests { - use futures::future::{self, BoxFuture}; use futures::FutureExt; + use futures::future::{self, BoxFuture}; fn returns_normally( result: Result<&'static str, &'static str>, diff --git a/src/rust/engine/ui/src/instance.rs b/src/rust/engine/ui/src/instance.rs index 13ec4f055fd..fc844813366 100644 --- a/src/rust/engine/ui/src/instance.rs +++ b/src/rust/engine/ui/src/instance.rs @@ -42,7 +42,7 @@ impl Instance { ) -> Result { let stderr_fd = stdio::get_destination().stderr_as_raw_fd()?; let (terminal_width, terminal_height) = terminal_size_using_fd(stderr_fd) - .map(|terminal_dimensions| (terminal_dimensions.0 .0, terminal_dimensions.1 .0 - 1)) + .map(|terminal_dimensions| (terminal_dimensions.0.0, terminal_dimensions.1.0 - 1)) .unwrap_or((50, local_parallelism.try_into().unwrap())); if ui_use_prodash { diff --git a/src/rust/engine/ui/src/instance/indicatif.rs b/src/rust/engine/ui/src/instance/indicatif.rs index 49d8b3c78a7..ae6123d428c 100644 --- a/src/rust/engine/ui/src/instance/indicatif.rs +++ b/src/rust/engine/ui/src/instance/indicatif.rs @@ -7,8 +7,8 @@ use std::future; use std::sync::Arc; use std::time::SystemTime; -use futures::future::BoxFuture; use futures::FutureExt; +use futures::future::BoxFuture; use indexmap::IndexSet; use indicatif::MultiProgress; use indicatif::ProgressBar; @@ -17,8 +17,8 @@ use indicatif::ProgressStyle; use indicatif::WeakProgressBar; use parking_lot::Mutex; -use workunit_store::format_workunit_duration_ms; use workunit_store::SpanId; +use workunit_store::format_workunit_duration_ms; use super::TaskState; use crate::ConsoleUI; diff --git a/src/rust/engine/ui/src/instance/prodash.rs b/src/rust/engine/ui/src/instance/prodash.rs index a1616b94535..a58baaf9978 100644 --- a/src/rust/engine/ui/src/instance/prodash.rs +++ b/src/rust/engine/ui/src/instance/prodash.rs @@ -8,17 +8,17 @@ use std::time::Duration; use std::time::SystemTime; use std::time::UNIX_EPOCH; -use futures::future::BoxFuture; use futures::FutureExt; -use prodash::progress::Step; -use prodash::render::line; +use futures::future::BoxFuture; use prodash::Root; use prodash::TreeOptions; +use prodash::progress::Step; +use prodash::render::line; use logging::fatal_log; use task_executor::Executor; -use workunit_store::format_workunit_duration_ms; use workunit_store::SpanId; +use workunit_store::format_workunit_duration_ms; use super::TaskState; use crate::ConsoleUI; diff --git a/src/rust/engine/watch/src/lib.rs b/src/rust/engine/watch/src/lib.rs index 0ef2e90b79b..354a5842296 100644 --- a/src/rust/engine/watch/src/lib.rs +++ b/src/rust/engine/watch/src/lib.rs @@ -330,10 +330,12 @@ fn maybe_enrich_notify_error(path: &Path, e: notify::Error) -> String { } else { "unable to read limit value".to_string() }; - format!("\n\nOn Linux, this can be caused by a `max_user_watches` setting that is lower \ + format!( + "\n\nOn Linux, this can be caused by a `max_user_watches` setting that is lower \ than the number of files and directories in your repository ({limit_value}). Please see \ https://www.pantsbuild.org/docs/troubleshooting#no-space-left-on-device-error-while-watching-files \ - for more information.") + for more information." + ) } _ => "".to_string(), }; diff --git a/src/rust/engine/watch/src/tests.rs b/src/rust/engine/watch/src/tests.rs index 2d646c66206..f884b5baec9 100644 --- a/src/rust/engine/watch/src/tests.rs +++ b/src/rust/engine/watch/src/tests.rs @@ -135,9 +135,11 @@ async fn liveness_watch_error() { .unwrap(); // Should exit. - assert!(liveness_receiver - .recv_timeout(Duration::from_millis(1000)) - .is_ok()); + assert!( + liveness_receiver + .recv_timeout(Duration::from_millis(1000)) + .is_ok() + ); join_handle.join().unwrap(); } diff --git a/src/rust/engine/workunit_store/src/lib.rs b/src/rust/engine/workunit_store/src/lib.rs index 5035a5eccab..24ab12bc783 100644 --- a/src/rust/engine/workunit_store/src/lib.rs +++ b/src/rust/engine/workunit_store/src/lib.rs @@ -4,25 +4,25 @@ use std::any::Any; use std::cell::RefCell; use std::cmp::Reverse; -use std::collections::{hash_map, BinaryHeap, HashMap, HashSet}; +use std::collections::{BinaryHeap, HashMap, HashSet, hash_map}; use std::fmt::Debug; use std::future::Future; -use std::sync::atomic::{self, AtomicBool}; use std::sync::Arc; +use std::sync::atomic::{self, AtomicBool}; use std::time::{Duration, SystemTime}; use bytes::{BufMut, Bytes, BytesMut}; use concrete_time::TimeSpan; use deepsize::DeepSizeOf; use hdrhistogram::serialization::Serializer; -use log::log; pub use log::Level; +use log::log; pub use metrics::{Metric, ObservationMetric}; use parking_lot::Mutex; use petgraph::stable_graph::{NodeIndex, StableDiGraph}; use petgraph::visit::{VisitMap, Visitable}; -use rand::thread_rng; use rand::Rng; +use rand::thread_rng; use smallvec::SmallVec; use tokio::sync::mpsc::{self, UnboundedReceiver, UnboundedSender}; use tokio::task_local; @@ -769,9 +769,7 @@ impl WorkunitStore { #[macro_export] macro_rules! format_workunit_duration_ms { - ($workunit_duration_ms:expr) => {{ - format_args!("{:.2}s", ($workunit_duration_ms as f64) / 1000.0) - }}; + ($workunit_duration_ms:expr) => {{ format_args!("{:.2}s", ($workunit_duration_ms as f64) / 1000.0) }}; } ///