Repository: astral-sh/uv
File: crates/uv/tests/it/python_install.rs (Rust)

Code before:

    ----- stderr -----
    error: `uv python install --upgrade` only accepts minor versions, got: 3.11.4
    ");

    // Request a version that isn't installed yet
    uv_snapshot!(context.filters(), context.python_install().arg("--upgrade").arg("3.11"), @r"
    success: true
    exit_code: 0
    ----- stdout -----

    ----- stderr -----
    Installed Python 3.11.14 in [TIME]
     + cpython-3.11.14-[PLATFORM] (python3.11)
    ");

    // Ask for it again
    uv_snapshot!(context.filters(), context.python_install().arg("--upgrade").arg("3.11"), @r"
    success: true
    exit_code: 0
    ----- stdout -----

    ----- stderr -----
    Python 3.11 is already on the latest supported patch release
    ");

    // Install an outdated version
    uv_snapshot!(context.filters(), context.python_install().arg("3.9.5"), @r"
    success: true
    exit_code: 0
    ----- stdout -----

    ----- stderr -----
    Installed Python 3.9.5 in [TIME]
     + cpython-3.9.5-[PLATFORM] (python3.9)
    ");

    // We shouldn't update it when not relevant
    uv_snapshot!(context.filters(), context.python_install().arg("--upgrade").arg("3.11"), @r"
    success: true
    exit_code: 0
    ----- stdout -----

    ----- stderr -----
    Python 3.11 is already on the latest supported patch release
    ");

    // Ask for multiple already satisfied versions
    uv_snapshot!(context.filters(), context.python_install().arg("--upgrade").arg("3.10").arg("3.11"), @r"
    success: true
    exit_code: 0

Review comment (suggestion):
Another quirk: The output log for plain without any pin is the same with and without upgrade. I'd have expected something like "latest patch version Python 3.14.0 is already installed".

```
$ uv python install
Python is already installed. Use `uv python install <request>` to install another version.
$ uv python install --upgrade
Python is already installed. Use `uv python install <request>` to install another version.
```

Similar to what an explicit request tells you:

```
$ uv python install --upgrade 3.14
Python 3.14 is already on the latest supported patch release
```

It's pre-existing, but it would also be nice if `uv python install` and `uv python install --upgrade 3.14` would tell me the version that is installed that they consider latest.

Code after:
    exit_code: 2
    ----- stdout -----

    ----- stderr -----
    error: No download found for request: pypy-3.10-[PLATFORM]
    ");
}

#[test]
fn python_install_upgrade() {
    let context: TestContext = TestContext::new_with_versions(&[])
        .with_python_download_cache()
        .with_filtered_python_keys()
        .with_filtered_exe_suffix()
        .with_managed_python_dirs();

    // Provide `--upgrade` as an `install` option without any versions
    uv_snapshot!(context.filters(), context.python_install().arg("--upgrade"), @r"
    success: true
    exit_code: 0
    ----- stdout -----

    ----- stderr -----
    Installed Python 3.14.0 in [TIME]
     + cpython-3.14.0-[PLATFORM] (python3.14)
    ");

    // Provide `--upgrade` as an `install` option without any versions again!
    uv_snapshot!(context.filters(), context.python_install().arg("--upgrade"), @r"
    success: true
    exit_code: 0
    ----- stdout -----

    ----- stderr -----
    The default Python installation is already on the latest supported patch release. Use `uv python install <request>` to install another version.
    ");

    // Install an earlier patch version
    uv_snapshot!(context.filters(), context.python_install().arg("3.10.17"), @r"
    success: true
    exit_code: 0
    ----- stdout -----

    ----- stderr -----
    Installed Python 3.10.17 in [TIME]
     + cpython-3.10.17-[PLATFORM] (python3.10)
    ");

    // Ask for an `--upgrade`
    uv_snapshot!(context.filters(), context.python_install().arg("--upgrade").arg("3.10"), @r"
    success: true