Skip to content

Commit d103a75

Browse files
authored
List all existing tool references on rye toolchain remove (#1346)
Using `rye toolchain remove` now lists all tools that use a specific toolchain. This eliminates the Whac-a-Mole game of reiterating through the `rye toolchain remove blabla` command in order to actually remove it. ## Example Usage ```bash $ rye install black --quiet --python 3.11.7 $ rye toolchain remove 3.11.7 error: toolchain [email protected] is still in use by tool black $ rye install ruff --quiet --python 3.11.7 $ rye toolchain remove 3.11.7 error: toolchain [email protected] is still in use by tools: black, ruff ``` _(Side note: Rust isn't my main d2d language, feel free to comment on coding style and unidiomatic code)_
1 parent 6067894 commit d103a75

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

rye/src/cli/toolchain.rs

+21-5
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,28 @@ fn check_in_use(ver: &PythonVersion) -> Result<(), Error> {
121121

122122
// Check if used by any tool.
123123
let installed_tools = list_installed_tools()?;
124-
for (tool, info) in &installed_tools {
125-
if let Some(ref venv_marker) = info.venv_marker {
126-
if &venv_marker.python == ver {
127-
bail!("toolchain {} is still in use by tool {}", ver, tool);
124+
125+
let toolchain_refs = installed_tools
126+
.iter()
127+
.filter_map(|(tool, info)| {
128+
if let Some(ref venv_marker) = info.venv_marker {
129+
match &venv_marker.python == ver {
130+
true => Some(tool.clone()),
131+
false => None,
132+
}
133+
} else {
134+
None
128135
}
129-
}
136+
})
137+
.collect::<Vec<_>>();
138+
139+
if !toolchain_refs.is_empty() {
140+
bail!(
141+
"toolchain {} is still in use by tool{} {}",
142+
ver,
143+
if toolchain_refs.len() > 1 { "s:" } else { "" },
144+
toolchain_refs.join(", ")
145+
);
130146
}
131147

132148
Ok(())

0 commit comments

Comments
 (0)