Skip to content

Commit

Permalink
Merge pull request #822 from epage/template
Browse files Browse the repository at this point in the history
chore: Update from _rust template
  • Loading branch information
epage authored Sep 27, 2024
2 parents 9bb2af2 + a888481 commit f15f6c8
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 40 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.x'
- uses: pre-commit/[email protected]
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ We ask that commits are atomic, meaning they are complete and have a single resp
PRs should tell a cohesive story, with test and refactor commits that keep the
fix or feature commits simple and clear.

Specifically, we would encouage
Specifically, we would encourage
- File renames be isolated into their own commit
- Add tests in a commit before their feature or fix, showing the current behavior.
The diff for the feature/fix commit will then show how the behavior changed,
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ string_lit_as_bytes = "warn"
string_to_string = "warn"
todo = "warn"
trait_duplication_in_bounds = "warn"
uninlined_format_args = "warn"
verbose_file_reads = "warn"
wildcard_imports = "warn"
zero_sized_map_values = "warn"
Expand Down
5 changes: 1 addition & 4 deletions src/ops/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,7 @@ fn upgrade_req(

let _ = crate::ops::shell::status(
"Updating",
format!(
"{}'s dependency from {} to {}",
manifest_name, existing_req_str, new_req
),
format!("{manifest_name}'s dependency from {existing_req_str} to {new_req}"),
);
*version_value = toml_edit::value(new_req);
true
Expand Down
14 changes: 6 additions & 8 deletions src/ops/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub fn is_behind_remote(dir: &Path, remote: &str, branch: &str) -> CargoResult<b

let branch_id = repo.revparse_single(branch)?.id();

let remote_branch = format!("{}/{}", remote, branch);
let remote_branch = format!("{remote}/{branch}");
let behind = match repo.revparse_single(&remote_branch) {
Ok(o) => {
let remote_branch_id = o.id();
Expand All @@ -36,8 +36,7 @@ pub fn is_behind_remote(dir: &Path, remote: &str, branch: &str) -> CargoResult<b
base_id != remote_branch_id
}
Err(err) => {
let _ =
crate::ops::shell::warn(format!("push target `{}` doesn't exist", remote_branch));
let _ = crate::ops::shell::warn(format!("push target `{remote_branch}` doesn't exist"));
log::trace!("error {}", err);
false
}
Expand All @@ -51,7 +50,7 @@ pub fn is_local_unchanged(dir: &Path, remote: &str, branch: &str) -> CargoResult

let branch_id = repo.revparse_single(branch)?.id();

let remote_branch = format!("{}/{}", remote, branch);
let remote_branch = format!("{remote}/{branch}");
let unchanged = match repo.revparse_single(&remote_branch) {
Ok(o) => {
let remote_branch_id = o.id();
Expand All @@ -64,8 +63,7 @@ pub fn is_local_unchanged(dir: &Path, remote: &str, branch: &str) -> CargoResult
base_id == branch_id
}
Err(err) => {
let _ =
crate::ops::shell::warn(format!("push target `{}` doesn't exist", remote_branch));
let _ = crate::ops::shell::warn(format!("push target `{remote_branch}` doesn't exist"));
log::trace!("error {}", err);
false
}
Expand All @@ -90,7 +88,7 @@ pub fn is_dirty(dir: &Path) -> CargoResult<Option<Vec<String>>> {
let state = repo.state();
let dirty_state = state != git2::RepositoryState::Clean;
if dirty_state {
entries.push(format!("Dirty because of state {:?}", state));
entries.push(format!("Dirty because of state {state:?}"));
}

let mut options = git2::StatusOptions::new();
Expand Down Expand Up @@ -118,7 +116,7 @@ pub fn changed_files(dir: &Path, tag: &str) -> CargoResult<Option<Vec<PathBuf>>>

let output = Command::new("git")
.arg("diff")
.arg(&format!("{}..HEAD", tag))
.arg(format!("{tag}..HEAD"))
.arg("--name-only")
.arg("--exit-code")
.arg("--")
Expand Down
4 changes: 2 additions & 2 deletions src/ops/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::ops::style::{ERROR, HEADER, NOTE, WARN};
pub fn confirm(prompt: &str) -> bool {
let mut input = String::new();

console_println(&format!("{} [y/N] ", prompt), Style::new());
console_println(&format!("{prompt} [y/N] "), Style::new());

stdout().flush().unwrap();
stdin().read_line(&mut input).expect("y/n required");
Expand All @@ -32,7 +32,7 @@ pub fn print(
if justified {
write!(stderr, "{style}{status:>12}{style:#}")?;
} else {
write!(stderr, "{style}{}{style:#}:", status)?;
write!(stderr, "{style}{status}{style:#}:")?;
}

writeln!(stderr, " {message:#}").with_context(|| "Failed to write message")?;
Expand Down
15 changes: 7 additions & 8 deletions src/ops/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ impl VersionExt for semver::Version {
} else {
1
};
self.pre = semver::Prerelease::new(&format!("{}.{}", VERSION_ALPHA, new_ext_ver))?;
self.pre = semver::Prerelease::new(&format!("{VERSION_ALPHA}.{new_ext_ver}"))?;
Ok(())
}
} else {
self.increment_patch();
self.pre = semver::Prerelease::new(&format!("{}.1", VERSION_ALPHA))?;
self.pre = semver::Prerelease::new(&format!("{VERSION_ALPHA}.1"))?;
Ok(())
}
}
Expand All @@ -92,12 +92,12 @@ impl VersionExt for semver::Version {
} else {
1
};
self.pre = semver::Prerelease::new(&format!("{}.{}", VERSION_BETA, new_ext_ver))?;
self.pre = semver::Prerelease::new(&format!("{VERSION_BETA}.{new_ext_ver}"))?;
Ok(())
}
} else {
self.increment_patch();
self.pre = semver::Prerelease::new(&format!("{}.1", VERSION_BETA))?;
self.pre = semver::Prerelease::new(&format!("{VERSION_BETA}.1"))?;
Ok(())
}
}
Expand All @@ -109,11 +109,11 @@ impl VersionExt for semver::Version {
} else {
1
};
self.pre = semver::Prerelease::new(&format!("{}.{}", VERSION_RC, new_ext_ver))?;
self.pre = semver::Prerelease::new(&format!("{VERSION_RC}.{new_ext_ver}"))?;
Ok(())
} else {
self.increment_patch();
self.pre = semver::Prerelease::new(&format!("{}.1", VERSION_RC))?;
self.pre = semver::Prerelease::new(&format!("{VERSION_RC}.1"))?;
Ok(())
}
}
Expand Down Expand Up @@ -172,8 +172,7 @@ pub fn upgrade_requirement(req: &str, version: &semver::Version) -> CargoResult<
{
assert!(
new_req.matches(version),
"Invalid req created: {}",
new_req_text
"Invalid req created: {new_req_text}"
);
}
if new_req_text == req_text {
Expand Down
2 changes: 1 addition & 1 deletion src/steps/changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub fn changes(
let repo = git2::Repository::discover(workspace_root)?;

let mut tag_id = None;
let fq_prior_tag_name = format!("refs/tags/{}", prior_tag_name);
let fq_prior_tag_name = format!("refs/tags/{prior_tag_name}");
repo.tag_foreach(|id, name| {
if name == fq_prior_tag_name.as_bytes() {
tag_id = Some(id);
Expand Down
3 changes: 1 addition & 2 deletions src/steps/hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,7 @@ pub fn hook(
// so here we set dry_run=false and always execute the command.
if !cmd::call_with_env(pre_rel_hook, envs, cwd, false)? {
let _ = crate::ops::shell::error(format!(
"release of {} aborted by non-zero return of prerelease hook.",
crate_name
"release of {crate_name} aborted by non-zero return of prerelease hook."
));
return Err(101.into());
}
Expand Down
17 changes: 7 additions & 10 deletions src/steps/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub fn verify_tags_missing(
let crate_name = pkg.meta.name.as_str();
let _ = crate::ops::shell::log(
level,
format!("tag `{}` already exists (for `{}`)", tag_name, crate_name),
format!("tag `{tag_name}` already exists (for `{crate_name}`)"),
);
tag_exists = true;
}
Expand Down Expand Up @@ -91,7 +91,7 @@ pub fn verify_tags_exist(
let crate_name = pkg.meta.name.as_str();
let _ = crate::ops::shell::log(
level,
format!("tag `{}` doesn't exist (for `{}`)", tag_name, crate_name),
format!("tag `{tag_name}` doesn't exist (for `{crate_name}`)"),
);
tag_missing = true;
}
Expand Down Expand Up @@ -163,10 +163,7 @@ pub fn verify_if_behind(
let branch = crate::ops::git::current_branch(path)?;
crate::ops::git::fetch(path, git_remote, &branch)?;
if crate::ops::git::is_behind_remote(path, git_remote, &branch)? {
let _ = crate::ops::shell::log(
level,
format!("{} is behind {}/{}", branch, git_remote, branch),
);
let _ = crate::ops::shell::log(level, format!("{branch} is behind {git_remote}/{branch}"));
if level == log::Level::Error {
success = false;
if !dry_run {
Expand Down Expand Up @@ -464,7 +461,7 @@ pub fn confirm(
use std::io::Write;

let mut buffer: Vec<u8> = vec![];
writeln!(&mut buffer, "{}", step).unwrap();
writeln!(&mut buffer, "{step}").unwrap();
for pkg in pkgs {
let crate_name = pkg.meta.name.as_str();
let version = pkg.planned_version.as_ref().unwrap_or(&pkg.initial_version);
Expand Down Expand Up @@ -558,10 +555,10 @@ impl std::fmt::Display for TargetVersion {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
match self {
TargetVersion::Relative(bump_level) => {
write!(f, "{}", bump_level)
write!(f, "{bump_level}")
}
TargetVersion::Absolute(version) => {
write!(f, "{}", version)
write!(f, "{version}")
}
}
}
Expand Down Expand Up @@ -660,7 +657,7 @@ impl FromStr for BumpLevel {
return Ok(*variant);
}
}
Err(format!("Invalid variant: {}", s))
Err(format!("Invalid variant: {s}"))
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/steps/release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ impl ReleaseStep {
{
if !changed.is_empty() {
let _ = crate::ops::shell::warn(format!(
"disabled by user, skipping {} which has files changed since {}: {:#?}",
crate_name, prior_tag_name, changed
"disabled by user, skipping {crate_name} which has files changed since {prior_tag_name}: {changed:#?}"
));
} else {
log::trace!(
Expand Down
3 changes: 1 addition & 2 deletions src/steps/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ impl TagStep {
if git::tag_exists(ws_meta.workspace_root.as_std_path(), tag_name)? {
let crate_name = pkg.meta.name.as_str();
let _ = crate::ops::shell::warn(format!(
"disabled due to existing tag ({}), skipping {}",
tag_name, crate_name
"disabled due to existing tag ({tag_name}), skipping {crate_name}"
));
pkg.planned_tag = None;
pkg.config.tag = Some(false);
Expand Down

0 comments on commit f15f6c8

Please sign in to comment.