diff --git a/src/github.rs b/src/github.rs index 5db22472..87e316e0 100644 --- a/src/github.rs +++ b/src/github.rs @@ -4,22 +4,22 @@ use { crate::release::{ - bootstrap_llvm, produce_install_only, produce_install_only_stripped, RELEASE_TRIPLES, + RELEASE_TRIPLES, bootstrap_llvm, produce_install_only, produce_install_only_stripped, }, - anyhow::{anyhow, Result}, + anyhow::{Result, anyhow}, bytes::Bytes, clap::ArgMatches, futures::StreamExt, octocrab::{ + Octocrab, OctocrabBuilder, models::{repos::Release, workflows::WorkflowListArtifact}, params::actions::ArchiveFormat, - Octocrab, OctocrabBuilder, }, rayon::prelude::*, reqwest::{Client, StatusCode}, reqwest_retry::{ - default_on_request_failure, policies::ExponentialBackoff, RetryPolicy, Retryable, - RetryableStrategy, + RetryPolicy, Retryable, RetryableStrategy, default_on_request_failure, + policies::ExponentialBackoff, }, sha2::{Digest, Sha256}, std::{ @@ -70,6 +70,7 @@ enum UploadSource { Data(Bytes), } +#[allow(clippy::too_many_arguments)] async fn upload_release_artifact( client: &Client, retry_policy: &impl RetryPolicy, @@ -286,16 +287,13 @@ pub async fn command_fetch_release_distributions(args: &ArgMatches) -> Result<() let parts = name.split('-').collect::>(); if parts[0] != "cpython" { - println!("ignoring {} not a cpython artifact", name); + println!("ignoring {name} not a cpython artifact"); continue; }; let python_version = pep440_rs::Version::from_str(parts[1])?; if !release_version_range.contains(&python_version) { - println!( - "{} not in release version range {}", - name, release_version_range - ); + println!("{name} not in release version range {release_version_range}"); continue; } @@ -310,17 +308,14 @@ pub async fn command_fetch_release_distributions(args: &ArgMatches) -> Result<() } }) else { - println!( - "ignoring {} does not match any registered release triples", - name - ); + println!("ignoring {name} does not match any registered release triples"); continue; }; let stripped_name = if let Some(s) = name.strip_suffix(".tar.zst") { s } else { - println!("ignoring {} not a .tar.zst artifact", name); + println!("ignoring {name} not a .tar.zst artifact"); continue; }; @@ -333,7 +328,7 @@ pub async fn command_fetch_release_distributions(args: &ArgMatches) -> Result<() let build_suffix = &stripped_name[triple_start + triple.len() + 1..]; if !release.suffixes(None).any(|suffix| build_suffix == suffix) { - println!("ignoring {} not a release artifact for triple", name); + println!("ignoring {name} not a release artifact for triple"); continue; } @@ -342,7 +337,7 @@ pub async fn command_fetch_release_distributions(args: &ArgMatches) -> Result<() zf.read_to_end(&mut buf)?; std::fs::write(&dest_path, &buf)?; - println!("prepared {} for release", name); + println!("prepared {name} for release"); if build_suffix == release.install_only_suffix { install_paths.push(dest_path); @@ -452,34 +447,19 @@ pub async fn command_upload_release_distributions(args: &ArgMatches) -> Result<( for suffix in release.suffixes(Some(&python_version)) { wanted_filenames.insert( - format!( - "cpython-{}-{}-{}-{}.tar.zst", - version, triple, suffix, datetime - ), - format!( - "cpython-{}+{}-{}-{}-full.tar.zst", - version, tag, triple, suffix - ), + format!("cpython-{version}-{triple}-{suffix}-{datetime}.tar.zst"), + format!("cpython-{version}+{tag}-{triple}-{suffix}-full.tar.zst"), ); } wanted_filenames.insert( - format!( - "cpython-{}-{}-install_only-{}.tar.gz", - version, triple, datetime - ), - format!("cpython-{}+{}-{}-install_only.tar.gz", version, tag, triple), + format!("cpython-{version}-{triple}-install_only-{datetime}.tar.gz"), + format!("cpython-{version}+{tag}-{triple}-install_only.tar.gz"), ); wanted_filenames.insert( - format!( - "cpython-{}-{}-install_only_stripped-{}.tar.gz", - version, triple, datetime - ), - format!( - "cpython-{}+{}-{}-install_only_stripped.tar.gz", - version, tag, triple - ), + format!("cpython-{version}-{triple}-install_only_stripped-{datetime}.tar.gz"), + format!("cpython-{version}+{tag}-{triple}-install_only_stripped.tar.gz"), ); } } @@ -490,7 +470,7 @@ pub async fn command_upload_release_distributions(args: &ArgMatches) -> Result<( .collect::>(); for f in &missing { - println!("missing release artifact: {}", f); + println!("missing release artifact: {f}"); } if missing.is_empty() { println!("found all {} release artifacts", wanted_filenames.len()); @@ -564,7 +544,7 @@ pub async fn command_upload_release_distributions(args: &ArgMatches) -> Result<( let shasums = digests .iter() - .map(|(filename, digest)| format!("{} {}\n", digest, filename)) + .map(|(filename, digest)| format!("{digest} {filename}\n")) .collect::>() .join(""); diff --git a/src/macho.rs b/src/macho.rs index 4717fb96..2173ee7b 100644 --- a/src/macho.rs +++ b/src/macho.rs @@ -4,7 +4,7 @@ use { crate::validation::ValidationContext, - anyhow::{anyhow, Context, Result}, + anyhow::{Context, Result, anyhow}, apple_sdk::{AppleSdk, SdkSearch, SdkSearchLocation, SdkSorting, SdkVersion, SimpleSdk}, semver::Version, std::{ @@ -53,7 +53,7 @@ impl std::fmt::Display for MachOPackedVersion { let minor = (self.value >> 8) & 0xff; let subminor = self.value & 0xff; - f.write_str(&format!("{}.{}.{}", major, minor, subminor)) + f.write_str(&format!("{major}.{minor}.{subminor}")) } } @@ -128,9 +128,9 @@ impl RequiredSymbols { fn tbd_relative_path(path: &str) -> Result { if let Some(stripped) = path.strip_prefix('/') { if let Some(stem) = stripped.strip_suffix(".dylib") { - Ok(format!("{}.tbd", stem)) + Ok(format!("{stem}.tbd")) } else { - Ok(format!("{}.tbd", stripped)) + Ok(format!("{stripped}.tbd")) } } else { Err(anyhow!("could not determine tbd path from {}", path)) @@ -165,13 +165,13 @@ impl TbdMetadata { export .objc_classes .iter() - .map(|cls| format!("_OBJC_CLASS_${}", cls)), + .map(|cls| format!("_OBJC_CLASS_${cls}")), ) .chain( export .objc_classes .iter() - .map(|cls| format!("_OBJC_METACLASS_${}", cls)), + .map(|cls| format!("_OBJC_METACLASS_${cls}")), ), ); @@ -214,13 +214,13 @@ impl TbdMetadata { export .objc_classes .iter() - .map(|cls| format!("_OBJC_CLASS_$_{}", cls)), + .map(|cls| format!("_OBJC_CLASS_$_{cls}")), ) .chain( export .objc_classes .iter() - .map(|cls| format!("_OBJC_METACLASS_$_{}", cls)), + .map(|cls| format!("_OBJC_METACLASS_$_{cls}")), ), ); @@ -249,13 +249,13 @@ impl TbdMetadata { export .objc_classes .iter() - .map(|cls| format!("_OBJC_CLASS_$_{}", cls)), + .map(|cls| format!("_OBJC_CLASS_$_{cls}")), ) .chain( export .objc_classes .iter() - .map(|cls| format!("_OBJC_METACLASS_$_{}", cls)), + .map(|cls| format!("_OBJC_METACLASS_$_{cls}")), ), ); res.weak_symbols @@ -370,8 +370,7 @@ impl IndexedSdks { "x86_64-apple-darwin" => "x86_64-macos", _ => { context.errors.push(format!( - "unknown target triple for Mach-O symbol analysis: {}", - triple + "unknown target triple for Mach-O symbol analysis: {triple}" )); return Ok(()); } diff --git a/src/main.rs b/src/main.rs index c8d422e8..99ef5b5e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,8 +9,8 @@ mod release; mod validation; use { - anyhow::{anyhow, Context, Result}, - clap::{value_parser, Arg, ArgAction, Command}, + anyhow::{Context, Result, anyhow}, + clap::{Arg, ArgAction, Command, value_parser}, std::{ io::Read, path::{Path, PathBuf}, @@ -240,7 +240,7 @@ fn main() { let exit_code = match main_impl() { Ok(()) => 0, Err(err) => { - eprintln!("Error: {:?}", err); + eprintln!("Error: {err:?}"); 1 } }; diff --git a/src/release.rs b/src/release.rs index 4c123f61..b49f0fac 100644 --- a/src/release.rs +++ b/src/release.rs @@ -13,7 +13,7 @@ use std::{ use url::Url; use { crate::json::parse_python_json, - anyhow::{anyhow, Result}, + anyhow::{Result, anyhow}, once_cell::sync::Lazy, pep440_rs::VersionSpecifier, std::{ @@ -628,7 +628,7 @@ static LLVM_URL: Lazy = Lazy::new(|| { /// Returns the path to the top-level `llvm` directory. pub async fn bootstrap_llvm() -> Result { let url = &*LLVM_URL; - let filename = url.path_segments().unwrap().last().unwrap(); + let filename = url.path_segments().unwrap().next_back().unwrap(); let llvm_dir = Path::new("build").join("llvm"); std::fs::create_dir_all(&llvm_dir)?; @@ -646,7 +646,7 @@ pub async fn bootstrap_llvm() -> Result { // Download the tarball. let tarball_path = temp_dir .path() - .join(url.path_segments().unwrap().last().unwrap()); + .join(url.path_segments().unwrap().next_back().unwrap()); let mut tarball_file = tokio::fs::File::create(&tarball_path).await?; let mut bytes_stream = reqwest::Client::new() .get(url.clone()) diff --git a/src/validation.rs b/src/validation.rs index 33e61e2e..dbe89764 100644 --- a/src/validation.rs +++ b/src/validation.rs @@ -4,13 +4,14 @@ use { crate::{json::*, macho::*}, - anyhow::{anyhow, Context, Result}, + anyhow::{Context, Result, anyhow}, clap::ArgMatches, normalize_path::NormalizePath, object::{ + Architecture, Endianness, FileKind, Object, SectionIndex, SymbolScope, elf::{ - FileHeader32, FileHeader64, ET_DYN, ET_EXEC, SHN_UNDEF, STB_GLOBAL, STB_WEAK, STV_DEFAULT, - STV_HIDDEN, + ET_DYN, ET_EXEC, FileHeader32, FileHeader64, SHN_UNDEF, STB_GLOBAL, STB_WEAK, + STV_DEFAULT, STV_HIDDEN, }, macho::{LC_CODE_SIGNATURE, MH_OBJECT, MH_TWOLEVEL, MachHeader32, MachHeader64}, read::{ @@ -18,7 +19,6 @@ use { macho::{LoadCommandVariant, MachHeader, Nlist, Section, Segment}, pe::{ImageNtHeaders, PeFile, PeFile32, PeFile64}, }, - Architecture, Endianness, FileKind, Object, SectionIndex, SymbolScope, }, once_cell::sync::Lazy, std::{ @@ -973,7 +973,7 @@ fn validate_elf>( "x86_64_v2-unknown-linux-musl" => object::elf::EM_X86_64, "x86_64_v3-unknown-linux-musl" => object::elf::EM_X86_64, "x86_64_v4-unknown-linux-musl" => object::elf::EM_X86_64, - _ => panic!("unhandled target triple: {}", target_triple), + _ => panic!("unhandled target triple: {target_triple}"), }; let endian = elf.endian()?; @@ -998,27 +998,23 @@ fn validate_elf>( if json.libpython_link_mode == "shared" { if target_triple.contains("-musl") { // On musl, we link to `libpython` and rely on `RUN PATH` - allowed_libraries.push(format!("libpython{}.so.1.0", python_major_minor)); - allowed_libraries.push(format!("libpython{}d.so.1.0", python_major_minor)); - allowed_libraries.push(format!("libpython{}t.so.1.0", python_major_minor)); - allowed_libraries.push(format!("libpython{}td.so.1.0", python_major_minor)); + allowed_libraries.push(format!("libpython{python_major_minor}.so.1.0")); + allowed_libraries.push(format!("libpython{python_major_minor}d.so.1.0")); + allowed_libraries.push(format!("libpython{python_major_minor}t.so.1.0")); + allowed_libraries.push(format!("libpython{python_major_minor}td.so.1.0")); } else { // On glibc, we can use `$ORIGIN` for relative, reloctable linking allowed_libraries.push(format!( - "$ORIGIN/../lib/libpython{}.so.1.0", - python_major_minor + "$ORIGIN/../lib/libpython{python_major_minor}.so.1.0" )); allowed_libraries.push(format!( - "$ORIGIN/../lib/libpython{}d.so.1.0", - python_major_minor + "$ORIGIN/../lib/libpython{python_major_minor}d.so.1.0" )); allowed_libraries.push(format!( - "$ORIGIN/../lib/libpython{}t.so.1.0", - python_major_minor + "$ORIGIN/../lib/libpython{python_major_minor}t.so.1.0" )); allowed_libraries.push(format!( - "$ORIGIN/../lib/libpython{}td.so.1.0", - python_major_minor + "$ORIGIN/../lib/libpython{python_major_minor}td.so.1.0" )); } } @@ -1229,8 +1225,8 @@ fn validate_macho>( bytes: &[u8], ) -> Result<()> { let advertised_target_version = - semver::Version::parse(&format!("{}.0", advertised_target_version))?; - let advertised_sdk_version = semver::Version::parse(&format!("{}.0", advertised_sdk_version))?; + semver::Version::parse(&format!("{advertised_target_version}.0"))?; + let advertised_sdk_version = semver::Version::parse(&format!("{advertised_sdk_version}.0"))?; let endian = header.endian()?; @@ -1661,7 +1657,7 @@ fn validate_extension_modules( wanted.extend(GLOBAL_EXTENSIONS_PYTHON_3_14); } _ => { - panic!("unhandled Python version: {}", python_major_minor); + panic!("unhandled Python version: {python_major_minor}"); } } @@ -1732,11 +1728,11 @@ fn validate_extension_modules( } for extra in have_extensions.difference(&wanted) { - errors.push(format!("extra/unknown extension module: {}", extra)); + errors.push(format!("extra/unknown extension module: {extra}")); } for missing in wanted.difference(have_extensions) { - errors.push(format!("missing extension module: {}", missing)); + errors.push(format!("missing extension module: {missing}")); } Ok(errors) @@ -1791,7 +1787,7 @@ fn validate_json(json: &PythonJsonMain, triple: &str, is_debug: bool) -> Result< for extension in json.build_info.extensions.keys() { if GLOBALLY_BANNED_EXTENSIONS.contains(&extension.as_str()) { - errors.push(format!("banned extension detected: {}", extension)); + errors.push(format!("banned extension detected: {extension}")); } } @@ -1828,11 +1824,7 @@ fn validate_distribution( let triple = RECOGNIZED_TRIPLES .iter() - .find(|triple| { - dist_path - .to_string_lossy() - .contains(&format!("-{}-", triple)) - }) + .find(|triple| dist_path.to_string_lossy().contains(&format!("-{triple}-"))) .ok_or_else(|| { anyhow!( "could not identify triple from distribution filename: {}", @@ -1883,7 +1875,7 @@ fn validate_distribution( .unwrap() .python_paths .values() - .map(|x| format!("python/{}", x)), + .map(|x| format!("python/{x}")), ); } else { context.errors.push(format!( @@ -2031,8 +2023,7 @@ fn validate_distribution( for path in wanted_python_paths { context.errors.push(format!( - "path prefix {} seen in python_paths does not appear in archive", - path + "path prefix {path} seen in python_paths does not appear in archive" )); } @@ -2046,7 +2037,7 @@ fn validate_distribution( for lib in wanted_dylibs.difference(&context.seen_dylibs) { context .errors - .push(format!("required library dependency {} not seen", lib)); + .push(format!("required library dependency {lib} not seen")); } if triple.contains("-windows-") && is_static { @@ -2083,8 +2074,7 @@ fn validate_distribution( if let Some(shared) = &ext.shared_lib { if !seen_paths.contains(&PathBuf::from("python").join(shared)) { context.errors.push(format!( - "extension module {} references missing shared library path {}", - name, shared + "extension module {name} references missing shared library path {shared}" )); } } @@ -2106,13 +2096,11 @@ fn validate_distribution( if want_shared && ext.shared_lib.is_none() { context.errors.push(format!( - "extension module {} does not have a shared library", - name + "extension module {name} does not have a shared library" )); } else if !want_shared && ext.shared_lib.is_some() { context.errors.push(format!( - "extension module {} contains a shared library unexpectedly", - name + "extension module {name} contains a shared library unexpectedly" )); } @@ -2165,7 +2153,7 @@ fn validate_distribution( if triple.contains("-apple-darwin") { if let Some(sdks) = macos_sdks { if let Some(value) = json.as_ref().unwrap().apple_sdk_deployment_target.as_ref() { - let target_minimum_sdk = semver::Version::parse(&format!("{}.0", value))?; + let target_minimum_sdk = semver::Version::parse(&format!("{value}.0"))?; sdks.validate_context(&mut context, target_minimum_sdk, triple)?; } else { @@ -2253,7 +2241,7 @@ pub fn command_validate_distribution(args: &ArgMatches) -> Result<()> { println!(" {} OK", path.display()); } else { for error in errors { - println!(" error: {}", error); + println!(" error: {error}"); } success = false;