Improve 'any' search message during uv python install (#4940)

Special cases the `Any` request in output

e.g.,

```
❯ cargo run -q -- python install --isolated
warning: `uv python install` is experimental and may change without warning.
Searching for Python installations
Found existing installation: cpython-3.12.3-macos-aarch64-none
Python is already available. Use `uv python install <request>` to install a specific version.
```

instead of 

```
❯ cargo run -q -- python install --isolated
warning: `uv python install` is experimental and may change without warning.
Searching for Python versions matching: any Python
Found existing installation for any Python: cpython-3.12.3-macos-aarch64-none
Python is already available. Use `uv python install <request>` to install a specific version.
```
This commit is contained in:
Zanie Blue 2024-07-10 11:03:22 -04:00 committed by GitHub
parent 42ccce9641
commit d497adaacb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 27 additions and 12 deletions

View file

@ -26,6 +26,7 @@ pub(crate) async fn install(
native_tls: bool,
connectivity: Connectivity,
preview: PreviewMode,
isolated: bool,
_cache: &Cache,
printer: Printer,
) -> Result<ExitStatus> {
@ -41,7 +42,12 @@ pub(crate) async fn install(
let targets = targets.into_iter().collect::<BTreeSet<_>>();
let requests: Vec<_> = if targets.is_empty() {
if let Some(requests) = requests_from_version_file().await? {
// Read from the version file, unless `isolated` was requested
if let Some(requests) = if isolated {
None
} else {
requests_from_version_file().await?
} {
requests
} else {
vec![PythonRequest::Any]
@ -61,21 +67,29 @@ pub(crate) async fn install(
let installed_installations: Vec<_> = installations.find_all()?.collect();
let mut unfilled_requests = Vec::new();
for (request, download_request) in requests.iter().zip(download_requests) {
writeln!(
printer.stderr(),
"Searching for Python versions matching: {}",
request.cyan()
)?;
if matches!(requests.as_slice(), [PythonRequest::Any]) {
writeln!(printer.stderr(), "Searching for Python installations")?;
} else {
writeln!(
printer.stderr(),
"Searching for Python versions matching: {}",
request.cyan()
)?;
}
if let Some(installation) = installed_installations
.iter()
.find(|installation| download_request.satisfied_by_key(installation.key()))
{
writeln!(
printer.stderr(),
"Found existing installation for {}: {}",
request.cyan(),
installation.key().green(),
)?;
if matches!(request, PythonRequest::Any) {
writeln!(printer.stderr(), "Found: {}", installation.key().green(),)?;
} else {
writeln!(
printer.stderr(),
"Found existing installation for {}: {}",
request.cyan(),
installation.key().green(),
)?;
}
if force {
writeln!(
printer.stderr(),

View file

@ -776,6 +776,7 @@ async fn run() -> Result<ExitStatus> {
globals.native_tls,
globals.connectivity,
globals.preview,
globals.isolated,
&cache,
printer,
)