mirror of
https://github.com/astral-sh/uv.git
synced 2025-07-24 13:43:45 +00:00
Add various grammar changes to conflict error messages (#9369)
## Summary If all items are the same kind, we can avoid repeating "extra" and "group". If there are two, we now use "X and Y", etc.
This commit is contained in:
parent
619ec8dcce
commit
b2bad8d59d
5 changed files with 125 additions and 64 deletions
|
@ -2422,7 +2422,7 @@ impl DiscoveryPreferences {
|
|||
.map(ToString::to_string)
|
||||
.collect::<Vec<_>>();
|
||||
match self.environment_preference {
|
||||
EnvironmentPreference::Any => conjunction(
|
||||
EnvironmentPreference::Any => disjunction(
|
||||
&["virtual environments"]
|
||||
.into_iter()
|
||||
.chain(python_sources.iter().map(String::as_str))
|
||||
|
@ -2430,23 +2430,23 @@ impl DiscoveryPreferences {
|
|||
),
|
||||
EnvironmentPreference::ExplicitSystem => {
|
||||
if request.is_explicit_system() {
|
||||
conjunction(
|
||||
disjunction(
|
||||
&["virtual environments"]
|
||||
.into_iter()
|
||||
.chain(python_sources.iter().map(String::as_str))
|
||||
.collect::<Vec<_>>(),
|
||||
)
|
||||
} else {
|
||||
conjunction(&["virtual environments"])
|
||||
disjunction(&["virtual environments"])
|
||||
}
|
||||
}
|
||||
EnvironmentPreference::OnlySystem => conjunction(
|
||||
EnvironmentPreference::OnlySystem => disjunction(
|
||||
&python_sources
|
||||
.iter()
|
||||
.map(String::as_str)
|
||||
.collect::<Vec<_>>(),
|
||||
),
|
||||
EnvironmentPreference::OnlyVirtual => conjunction(&["virtual environments"]),
|
||||
EnvironmentPreference::OnlyVirtual => disjunction(&["virtual environments"]),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2471,8 +2471,9 @@ impl fmt::Display for PythonNotFound {
|
|||
}
|
||||
|
||||
/// Join a series of items with `or` separators, making use of commas when necessary.
|
||||
fn conjunction(items: &[&str]) -> String {
|
||||
fn disjunction(items: &[&str]) -> String {
|
||||
match items.len() {
|
||||
0 => String::new(),
|
||||
1 => items[0].to_string(),
|
||||
2 => format!("{} or {}", items[0], items[1]),
|
||||
_ => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue