Add EXTERNALLY-MANAGED markers to managed toolchains (#4312)

Closes #4240 

e.g.

```
❯ cargo run -q -- pip install anyio --python "/Users/zb/Library/Application Support/uv/toolchains/cpython-3.12.0-macos-aarch64-none/install/bin/python3"
error: The interpreter at /Users/zb/Library/Application Support/uv/toolchains/cpython-3.12.0-macos-aarch64-none/install is externally managed, and indicates the following:

  This toolchain is managed by uv and should not be modified.

Consider creating a virtual environment with `uv venv`.
```
This commit is contained in:
Zanie Blue 2024-06-17 11:25:34 -04:00 committed by GitHub
parent e264637b63
commit 67f1285ce3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 30 additions and 3 deletions

View file

@ -8,7 +8,7 @@ use uv_toolchain::ToolchainRequest;
use uv_fs::Simplified;
use uv_toolchain::downloads::{DownloadResult, Error, PythonDownload, PythonDownloadRequest};
use uv_toolchain::managed::InstalledToolchains;
use uv_toolchain::managed::{InstalledToolchain, InstalledToolchains};
#[derive(Parser, Debug)]
pub(crate) struct FetchPythonArgs {
@ -73,6 +73,11 @@ pub(crate) async fn fetch_python(args: FetchPythonArgs) -> Result<()> {
results.push((version, path));
}
for (_, path) in results {
let installed = InstalledToolchain::new(path)?;
installed.ensure_externally_managed()?;
}
if downloaded > 0 {
let s = if downloaded == 1 { "" } else { "s" };
info!(