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

View file

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