Skip to main content

uv_python_commands/
dir.rs

1use std::fmt::Write;
2
3use anyhow::Context;
4use owo_colors::OwoColorize;
5
6use uv_fs::Simplified;
7use uv_python_managed::{ManagedPythonInstallations, python_executable_dir};
8
9use uv_command_support::Printer;
10
11/// Show the Python installation directory.
12pub fn dir(bin: bool, printer: Printer) -> anyhow::Result<()> {
13    if bin {
14        let bin = python_executable_dir()?;
15        writeln!(printer.stdout(), "{}", bin.simplified_display().cyan())?;
16    } else {
17        let installed_toolchains = ManagedPythonInstallations::from_settings(None)
18            .context("Failed to initialize toolchain settings")?;
19        writeln!(
20            printer.stdout(),
21            "{}",
22            installed_toolchains.root().simplified_display().cyan()
23        )?;
24    }
25
26    Ok(())
27}