Skip to content

Commit 37bd761

Browse files
authored
style: simplify string formatting (#88)
1 parent f33a69b commit 37bd761

File tree

13 files changed

+84
-124
lines changed

13 files changed

+84
-124
lines changed

crates/pet-conda/src/environment_locations.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,12 @@ pub fn get_known_conda_install_locations(env_vars: &EnvVariables) -> Vec<PathBuf
258258
"", // We need to look in `/anaconda3` and `/miniconda3` as well.
259259
];
260260
for directory in directories_to_look_in.iter() {
261-
known_paths.push(PathBuf::from(format!("{}/anaconda", directory)));
262-
known_paths.push(PathBuf::from(format!("{}/anaconda3", directory)));
263-
known_paths.push(PathBuf::from(format!("{}/miniconda", directory)));
264-
known_paths.push(PathBuf::from(format!("{}/miniconda3", directory)));
265-
known_paths.push(PathBuf::from(format!("{}/miniforge", directory)));
266-
known_paths.push(PathBuf::from(format!("{}/miniforge3", directory)));
261+
known_paths.push(PathBuf::from(format!("{directory}/anaconda")));
262+
known_paths.push(PathBuf::from(format!("{directory}/anaconda3")));
263+
known_paths.push(PathBuf::from(format!("{directory}/miniconda")));
264+
known_paths.push(PathBuf::from(format!("{directory}/miniconda3")));
265+
known_paths.push(PathBuf::from(format!("{directory}/miniforge")));
266+
known_paths.push(PathBuf::from(format!("{directory}/miniforge3")));
267267
}
268268
if let Some(ref conda_root) = env_vars.conda_root {
269269
known_paths.push(PathBuf::from(conda_root.clone()));

crates/pet-core/src/arch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub enum Architecture {
1212

1313
impl Ord for Architecture {
1414
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
15-
format!("{:?}", self).cmp(&format!("{:?}", other))
15+
format!("{self:?}").cmp(&format!("{other:?}"))
1616
}
1717
}
1818
impl PartialOrd for Architecture {

crates/pet-core/src/manager.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub enum EnvManagerType {
1515

1616
impl Ord for EnvManagerType {
1717
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
18-
format!("{:?}", self).cmp(&format!("{:?}", other))
18+
format!("{self:?}").cmp(&format!("{other:?}"))
1919
}
2020
}
2121
impl PartialOrd for EnvManagerType {
@@ -72,7 +72,7 @@ impl std::fmt::Display for EnvManager {
7272
)
7373
.unwrap_or_default();
7474
if let Some(version) = &self.version {
75-
writeln!(f, " Version : {}", version).unwrap_or_default();
75+
writeln!(f, " Version : {version}").unwrap_or_default();
7676
}
7777
Ok(())
7878
}

crates/pet-core/src/python_environment.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub enum PythonEnvironmentCategory {
3333
}
3434
impl Ord for PythonEnvironmentCategory {
3535
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
36-
format!("{:?}", self).cmp(&format!("{:?}", other))
36+
format!("{self:?}").cmp(&format!("{other:?}"))
3737
}
3838
}
3939
impl PartialOrd for PythonEnvironmentCategory {
@@ -140,17 +140,17 @@ impl std::fmt::Display for PythonEnvironment {
140140
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
141141
writeln!(f, "Environment ({:?})", self.category).unwrap_or_default();
142142
if let Some(name) = &self.display_name {
143-
writeln!(f, " Display-Name: {}", name).unwrap_or_default();
143+
writeln!(f, " Display-Name: {name}").unwrap_or_default();
144144
}
145145
if let Some(name) = &self.name {
146-
writeln!(f, " Name : {}", name).unwrap_or_default();
146+
writeln!(f, " Name : {name}").unwrap_or_default();
147147
}
148148
if let Some(exe) = &self.executable {
149149
writeln!(f, " Executable : {}", exe.to_str().unwrap_or_default())
150150
.unwrap_or_default();
151151
}
152152
if let Some(version) = &self.version {
153-
writeln!(f, " Version : {}", version).unwrap_or_default();
153+
writeln!(f, " Version : {version}").unwrap_or_default();
154154
}
155155
if let Some(prefix) = &self.prefix {
156156
writeln!(
@@ -167,7 +167,7 @@ impl std::fmt::Display for PythonEnvironment {
167167
writeln!(f, " Search Path : {}", search_path.to_str().unwrap()).unwrap_or_default();
168168
}
169169
if let Some(arch) = &self.arch {
170-
writeln!(f, " Architecture: {}", arch).unwrap_or_default();
170+
writeln!(f, " Architecture: {arch}").unwrap_or_default();
171171
}
172172
if let Some(manager) = &self.manager {
173173
writeln!(
@@ -190,9 +190,9 @@ impl std::fmt::Display for PythonEnvironment {
190190
if !symlinks.is_empty() {
191191
for (i, symlink) in symlinks.iter().enumerate() {
192192
if i == 0 {
193-
writeln!(f, " Symlinks : {:?}", symlink).unwrap_or_default();
193+
writeln!(f, " Symlinks : {symlink:?}").unwrap_or_default();
194194
} else {
195-
writeln!(f, " : {:?}", symlink).unwrap_or_default();
195+
writeln!(f, " : {symlink:?}").unwrap_or_default();
196196
}
197197
}
198198
}

crates/pet-homebrew/src/sym_links.rs

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -87,25 +87,25 @@ pub fn get_known_symlinks_impl(
8787
let version = version.as_str().to_string();
8888
let mut symlinks = vec![symlink_resolved_python_exe.to_owned()];
8989
for possible_symlink in [
90-
PathBuf::from(format!("/opt/homebrew/bin/python{}", version)),
91-
PathBuf::from(format!("/opt/homebrew/opt/python@{}/bin/python{}", version, version)),
92-
PathBuf::from(format!("/opt/homebrew/Cellar/python@{}/{}/bin/python{}",version, full_version, version)),
93-
PathBuf::from(format!("/opt/homebrew/Cellar/python@{}/{}/Frameworks/Python.framework/Versions/{}/bin/python{}", version, full_version, version, version)),
94-
PathBuf::from(format!("/opt/homebrew/Cellar/python@{}/{}/Frameworks/Python.framework/Versions/Current/bin/python{}", version, full_version, version)),
95-
PathBuf::from(format!("/opt/homebrew/Frameworks/Python.framework/Versions/{}/bin/python{}", version, version)),
96-
PathBuf::from(format!("/opt/homebrew/Frameworks/Python.framework/Versions/Current/bin/python{}", version)),
97-
PathBuf::from(format!("/usr/local/opt/python@{}/bin/python3", version)),
98-
PathBuf::from(format!("/usr/local/opt/python@{}/bin/python{}", version, version)),
90+
PathBuf::from(format!("/opt/homebrew/bin/python{version}")),
91+
PathBuf::from(format!("/opt/homebrew/opt/python@{version}/bin/python{version}")),
92+
PathBuf::from(format!("/opt/homebrew/Cellar/python@{version}/{full_version}/bin/python{version}")),
93+
PathBuf::from(format!("/opt/homebrew/Cellar/python@{version}/{full_version}/Frameworks/Python.framework/Versions/{version}/bin/python{version}")),
94+
PathBuf::from(format!("/opt/homebrew/Cellar/python@{version}/{full_version}/Frameworks/Python.framework/Versions/Current/bin/python{version}")),
95+
PathBuf::from(format!("/opt/homebrew/Frameworks/Python.framework/Versions/{version}/bin/python{version}")),
96+
PathBuf::from(format!("/opt/homebrew/Frameworks/Python.framework/Versions/Current/bin/python{version}")),
97+
PathBuf::from(format!("/usr/local/opt/python@{version}/bin/python3")),
98+
PathBuf::from(format!("/usr/local/opt/python@{version}/bin/python{version}")),
9999
PathBuf::from("/opt/homebrew/opt/python/bin/python3"),
100-
PathBuf::from(format!("/opt/homebrew/opt/python/bin/python{}", version)),
100+
PathBuf::from(format!("/opt/homebrew/opt/python/bin/python{version}")),
101101
PathBuf::from("/opt/homebrew/opt/python@3/bin/python3"),
102-
PathBuf::from(format!("/opt/homebrew/opt/python@3/bin/python{}", version)),
103-
PathBuf::from(format!("/opt/homebrew/opt/python@{}/bin/python3", version)),
104-
PathBuf::from(format!("/opt/homebrew/opt/python@{}/bin/python{}", version, version)),
102+
PathBuf::from(format!("/opt/homebrew/opt/python@3/bin/python{version}")),
103+
PathBuf::from(format!("/opt/homebrew/opt/python@{version}/bin/python3")),
104+
PathBuf::from(format!("/opt/homebrew/opt/python@{version}/bin/python{version}")),
105105
PathBuf::from("/usr/local/opt/python@3/bin/python3"),
106-
PathBuf::from(format!("/usr/local/opt/python@3/bin/python{}", version)),
106+
PathBuf::from(format!("/usr/local/opt/python@3/bin/python{version}")),
107107
// Check if this symlink is pointing to the same place as the resolved python exe
108-
PathBuf::from(format!("/opt/homebrew/opt/python3/bin/python{}", version)),
108+
PathBuf::from(format!("/opt/homebrew/opt/python3/bin/python{version}")),
109109
// Check if this symlink is pointing to the same place as the resolved python exe
110110
PathBuf::from("/opt/homebrew/bin/python3"),
111111
// Check if this symlink is pointing to the same place as the resolved python exe
@@ -148,21 +148,19 @@ pub fn get_known_symlinks_impl(
148148
// 1. python 3.8 has sysprefix in /usr/local/Cellar/[email protected]/3.9.19/Frameworks/Python.framework/Versions/3.9
149149
// 2. python 3.9 has sysprefix in /usr/local/opt/[email protected]/Frameworks/Python.framework/Versions/3.9
150150
// 3. python 3.11 has sysprefix in /usr/local/opt/[email protected]/Frameworks/Python.framework/Versions/3.11
151-
PathBuf::from(format!("/usr/local/opt/python@{}/bin/python3", version)),
152-
PathBuf::from(format!("/usr/local/opt/python@{}/bin/python{}", version, version)),
151+
PathBuf::from(format!("/usr/local/opt/python@{version}/bin/python3")),
152+
PathBuf::from(format!("/usr/local/opt/python@{version}/bin/python{version}")),
153153
PathBuf::from("/usr/local/opt/python@3/bin/python3"),
154-
PathBuf::from(format!("/usr/local/opt/python@3/bin/python{}", version)),
154+
PathBuf::from(format!("/usr/local/opt/python@3/bin/python{version}")),
155155
PathBuf::from(format!(
156-
"/usr/local/Cellar/python@{}/{}/bin/python{}",
157-
version, full_version, version
156+
"/usr/local/Cellar/python@{version}/{full_version}/bin/python{version}"
158157
)),
159158
PathBuf::from(format!(
160-
"/usr/local/Cellar/python@{}/{}/Frameworks/Python.framework/Versions/{}/bin/python{}",
161-
version, full_version, version, version
159+
"/usr/local/Cellar/python@{version}/{full_version}/Frameworks/Python.framework/Versions/{version}/bin/python{version}"
162160
)),
163161
// This is a special folder, if users install python using other means, this file
164162
// might get overridden. So we should only add this if this files points to the same place
165-
PathBuf::from(format!("/usr/local/bin/python{}", version)),
163+
PathBuf::from(format!("/usr/local/bin/python{version}")),
166164
// Check if this symlink is pointing to the same place as the resolved python exe
167165
PathBuf::from("/usr/local/bin/python3"),
168166
// Check if this symlink is pointing to the same place as the resolved python exe
@@ -201,36 +199,30 @@ pub fn get_known_symlinks_impl(
201199
let mut symlinks = vec![symlink_resolved_python_exe.to_owned()];
202200
for possible_symlink in [
203201
PathBuf::from("/home/linuxbrew/.linuxbrew/bin/python3"),
204-
PathBuf::from(format!("/home/linuxbrew/.linuxbrew/bin/python{}", version)),
202+
PathBuf::from(format!("/home/linuxbrew/.linuxbrew/bin/python{version}")),
205203
PathBuf::from(format!(
206-
"/home/linuxbrew/.linuxbrew/Cellar/python@{}/{}/bin/python{}",
207-
version, full_version, version
204+
"/home/linuxbrew/.linuxbrew/Cellar/python@{version}/{full_version}/bin/python{version}"
208205
)),
209206
PathBuf::from(format!(
210-
"/home/linuxbrew/.linuxbrew/Cellar/python@{}/{}/bin/python3",
211-
version, full_version
207+
"/home/linuxbrew/.linuxbrew/Cellar/python@{version}/{full_version}/bin/python3"
212208
)),
213209
PathBuf::from(format!(
214-
"/home/linuxbrew/.linuxbrew/opt/python@{}/bin/python{}",
215-
version, version
210+
"/home/linuxbrew/.linuxbrew/opt/python@{version}/bin/python{version}"
216211
)),
217212
PathBuf::from(format!(
218-
"/home/linuxbrew/.linuxbrew/opt/python@{}/bin/python3",
219-
version
213+
"/home/linuxbrew/.linuxbrew/opt/python@{version}/bin/python3"
220214
)),
221215
PathBuf::from(format!(
222-
"/home/linuxbrew/.linuxbrew/opt/python3/bin/python{}",
223-
version
216+
"/home/linuxbrew/.linuxbrew/opt/python3/bin/python{version}"
224217
)),
225218
PathBuf::from("/home/linuxbrew/.linuxbrew/opt/python3/bin/python3"),
226219
PathBuf::from(format!(
227-
"/home/linuxbrew/.linuxbrew/opt/python@3/bin/python{}",
228-
version
220+
"/home/linuxbrew/.linuxbrew/opt/python@3/bin/python{version}"
229221
)),
230222
PathBuf::from("/home/linuxbrew/.linuxbrew/opt/python@3/bin/python3"),
231223
// This is a special folder, if users install python using other means, this file
232224
// might get overridden. So we should only add this if this files points to the same place
233-
PathBuf::from(format!("/usr/local/bin/python{}", version)),
225+
PathBuf::from(format!("/usr/local/bin/python{version}")),
234226
// Check if this symlink is pointing to the same place as the resolved python exe
235227
PathBuf::from("/usr/local/bin/python3"),
236228
// Check if this symlink is pointing to the same place as the resolved python exe

crates/pet-jsonrpc/src/server.rs

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -58,36 +58,33 @@ impl<C> HandlersKeyedByMethodName<C> {
5858
if let Some(handler) = self.requests.get(method) {
5959
handler(self.context.clone(), id as u32, message["params"].clone());
6060
} else {
61-
eprint!("Failed to find handler for method: {}", method);
61+
eprint!("Failed to find handler for method: {method}");
6262
send_error(
6363
Some(id as u32),
6464
-1,
65-
format!("Failed to find handler for request {}", method),
65+
format!("Failed to find handler for request {method}"),
6666
);
6767
}
6868
} else {
6969
// No id, so this is a notification
7070
if let Some(handler) = self.notifications.get(method) {
7171
handler(self.context.clone(), message["params"].clone());
7272
} else {
73-
eprint!("Failed to find handler for method: {}", method);
73+
eprint!("Failed to find handler for method: {method}");
7474
send_error(
7575
None,
7676
-2,
77-
format!("Failed to find handler for notification {}", method),
77+
format!("Failed to find handler for notification {method}"),
7878
);
7979
}
8080
}
8181
}
8282
None => {
83-
eprint!("Failed to get method from message: {}", message);
83+
eprint!("Failed to get method from message: {message}");
8484
send_error(
8585
None,
8686
-3,
87-
format!(
88-
"Failed to extract method from JSONRPC payload {:?}",
89-
message
90-
),
87+
format!("Failed to extract method from JSONRPC payload {message:?}"),
9188
);
9289
}
9390
};
@@ -115,20 +112,17 @@ pub fn start_server<C>(handlers: &HandlersKeyedByMethodName<C>) -> ! {
115112
match serde_json::from_str(&request) {
116113
Ok(request) => handlers.handle_request(request),
117114
Err(err) => {
118-
eprint!("Failed to parse LINE: {}, {:?}", request, err)
115+
eprint!("Failed to parse LINE: {request}, {err:?}")
119116
}
120117
}
121118
continue;
122119
}
123120
Err(err) => {
124-
eprint!(
125-
"Failed to read exactly {} bytes, {:?}",
126-
content_length, err
127-
)
121+
eprint!("Failed to read exactly {content_length} bytes, {err:?}")
128122
}
129123
}
130124
}
131-
Err(err) => eprint!("Failed to get content length from {}, {:?}", input, err),
125+
Err(err) => eprint!("Failed to get content length from {input}, {err:?}"),
132126
};
133127
}
134128
Err(error) => eprint!("Error in reading a line from stdin: {error}"),
@@ -152,8 +146,7 @@ fn get_content_length(line: &str) -> Result<usize, String> {
152146
}
153147
} else {
154148
Err(format!(
155-
"String 'Content-Length' not found in input => {}",
156-
line
149+
"String 'Content-Length' not found in input => {line}"
157150
))
158151
}
159152
}

crates/pet-mac-xcode/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ impl Locator for MacXCode {
8383
let xcode_folder_name = exe_str.split('/').nth(2).unwrap_or_default();
8484

8585
let bin = PathBuf::from(format!(
86-
"/Applications/{}/Contents/Developer/usr/bin",
87-
xcode_folder_name
86+
"/Applications/{xcode_folder_name}/Contents/Developer/usr/bin"
8887
));
8988
let exe = bin.join("python3");
9089
if let Some(symlink) = resolve_symlink(&exe) {

crates/pet-poetry/src/environment_locations.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ pub fn generate_env_name(name: &str, cwd: &PathBuf) -> String {
190190
.chars()
191191
.take(8)
192192
.collect::<String>();
193-
format!("{}-{}-py", sanitized_name, h_str)
193+
format!("{sanitized_name}-{h_str}-py")
194194
}
195195

196196
#[cfg(test)]

crates/pet-reporter/src/stdio.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl Reporter for StdioReporter {
4141
let count = managers.get(&manager.tool).unwrap_or(&0) + 1;
4242
managers.insert(manager.tool, count);
4343
if self.print_list {
44-
println!("{}", manager)
44+
println!("{manager}")
4545
}
4646
}
4747

@@ -50,7 +50,7 @@ impl Reporter for StdioReporter {
5050
let count = environments.get(&env.category).unwrap_or(&0) + 1;
5151
environments.insert(env.category, count);
5252
if self.print_list {
53-
println!("{}", env)
53+
println!("{env}")
5454
}
5555
}
5656
}

0 commit comments

Comments
 (0)