Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 20 additions & 40 deletions src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -70,6 +70,7 @@ enum UploadSource {
Data(Bytes),
}

#[allow(clippy::too_many_arguments)]
async fn upload_release_artifact(
client: &Client,
retry_policy: &impl RetryPolicy,
Expand Down Expand Up @@ -286,16 +287,13 @@ pub async fn command_fetch_release_distributions(args: &ArgMatches) -> Result<()
let parts = name.split('-').collect::<Vec<_>>();

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;
}

Expand All @@ -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;
};

Expand All @@ -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;
}

Expand All @@ -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);
Expand Down Expand Up @@ -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"),
);
}
}
Expand All @@ -490,7 +470,7 @@ pub async fn command_upload_release_distributions(args: &ArgMatches) -> Result<(
.collect::<Vec<_>>();

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());
Expand Down Expand Up @@ -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::<Vec<_>>()
.join("");

Expand Down
23 changes: 11 additions & 12 deletions src/macho.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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}"))
}
}

Expand Down Expand Up @@ -128,9 +128,9 @@ impl RequiredSymbols {
fn tbd_relative_path(path: &str) -> Result<String> {
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))
Expand Down Expand Up @@ -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}")),
),
);

Expand Down Expand Up @@ -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}")),
),
);

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(());
}
Expand Down
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -240,7 +240,7 @@ fn main() {
let exit_code = match main_impl() {
Ok(()) => 0,
Err(err) => {
eprintln!("Error: {:?}", err);
eprintln!("Error: {err:?}");
1
}
};
Expand Down
6 changes: 3 additions & 3 deletions src/release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -628,7 +628,7 @@ static LLVM_URL: Lazy<Url> = Lazy::new(|| {
/// Returns the path to the top-level `llvm` directory.
pub async fn bootstrap_llvm() -> Result<PathBuf> {
let url = &*LLVM_URL;
let filename = url.path_segments().unwrap().last().unwrap();
let filename = url.path_segments().unwrap().next_back().unwrap();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"warning: called Iterator::last on a DoubleEndedIterator; this will needlessly iterate the entire iterator"

https://rust-lang.github.io/rust-clippy/master/index.html#double_ended_iterator_last


let llvm_dir = Path::new("build").join("llvm");
std::fs::create_dir_all(&llvm_dir)?;
Expand All @@ -646,7 +646,7 @@ pub async fn bootstrap_llvm() -> Result<PathBuf> {
// 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())
Expand Down
Loading
Loading