mirror of
https://github.com/astral-sh/uv.git
synced 2025-07-31 17:13:45 +00:00
Add --install-dir
arg to uv python install
and uninstall
(#7920)
## Summary This PR adds `--install-dir` argument for the following commands: - `uv python install` - `uv python uninstall` The `UV_PYTHON_INSTALL_DIR` env variable can be used to set it (previously it was also used internally). Any more commands we would want to add this to? ## Test Plan For now just manual test (works on my machine hehe) ``` ❯ ./target/debug/uv python install --install-dir /tmp/pythons 3.8.12 Searching for Python versions matching: Python 3.8.12 Installed Python 3.8.12 in 4.31s + cpython-3.8.12-linux-x86_64-gnu ❯ /tmp/pythons/cpython-3.8.12-linux-x86_64-gnu/bin/python --help usage: /tmp/pythons/cpython-3.8.12-linux-x86_64-gnu/bin/python [option] ... [-c cmd | -m mod | file | -] [arg] ... ``` Open to add some tests after the initial feedback. --------- Co-authored-by: Zanie Blue <contact@zanie.dev>
This commit is contained in:
parent
b751648bfe
commit
d0ccc9a16f
13 changed files with 76 additions and 19 deletions
|
@ -107,11 +107,15 @@ impl ManagedPythonInstallations {
|
|||
}
|
||||
|
||||
/// Prefer, in order:
|
||||
/// 1. The specific Python directory specified by the user, i.e., `UV_PYTHON_INSTALL_DIR`
|
||||
/// 2. A directory in the system-appropriate user-level data directory, e.g., `~/.local/uv/python`
|
||||
/// 3. A directory in the local data directory, e.g., `./.uv/python`
|
||||
pub fn from_settings() -> Result<Self, Error> {
|
||||
if let Some(install_dir) = std::env::var_os(EnvVars::UV_PYTHON_INSTALL_DIR) {
|
||||
///
|
||||
/// 1. The specific Python directory passed via the `install_dir` argument.
|
||||
/// 2. The specific Python directory specified with the `UV_PYTHON_INSTALL_DIR` environment variable.
|
||||
/// 3. A directory in the system-appropriate user-level data directory, e.g., `~/.local/uv/python`.
|
||||
/// 4. A directory in the local data directory, e.g., `./.uv/python`.
|
||||
pub fn from_settings(install_dir: Option<PathBuf>) -> Result<Self, Error> {
|
||||
if let Some(install_dir) = install_dir {
|
||||
Ok(Self::from_path(install_dir))
|
||||
} else if let Some(install_dir) = std::env::var_os(EnvVars::UV_PYTHON_INSTALL_DIR) {
|
||||
Ok(Self::from_path(install_dir))
|
||||
} else {
|
||||
Ok(Self::from_path(
|
||||
|
@ -227,7 +231,7 @@ impl ManagedPythonInstallations {
|
|||
) -> Result<impl DoubleEndedIterator<Item = ManagedPythonInstallation>, Error> {
|
||||
let platform_key = platform_key_from_env()?;
|
||||
|
||||
let iter = ManagedPythonInstallations::from_settings()?
|
||||
let iter = ManagedPythonInstallations::from_settings(None)?
|
||||
.find_all()?
|
||||
.filter(move |installation| {
|
||||
installation
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue