diff --git a/rye/src/bootstrap.rs b/rye/src/bootstrap.rs index 862178ae8e..28ad721dfc 100644 --- a/rye/src/bootstrap.rs +++ b/rye/src/bootstrap.rs @@ -64,6 +64,28 @@ fn is_up_to_date() -> bool { *UP_TO_UPDATE || FORCED_TO_UPDATE.load(atomic::Ordering::Relaxed) } +#[derive(Debug, Clone)] +pub(crate) enum SelfVenvStatus { + NotUpToDate, + DoesNotExist, +} + +/// Get self venv path and check if it exists and is up to date +pub fn get_self_venv_status() -> Result { + let app_dir = get_app_dir(); + let venv_dir = app_dir.join("self"); + + if venv_dir.is_dir() { + if is_up_to_date() { + Ok(venv_dir) + } else { + Err((venv_dir, SelfVenvStatus::NotUpToDate)) + } + } else { + Err((venv_dir, SelfVenvStatus::DoesNotExist)) + } +} + /// Bootstraps the venv for rye itself pub fn ensure_self_venv(output: CommandOutput) -> Result { ensure_self_venv_with_toolchain(output, None) @@ -75,19 +97,20 @@ pub fn ensure_self_venv_with_toolchain( toolchain_version_request: Option, ) -> Result { let app_dir = get_app_dir(); - let venv_dir = app_dir.join("self"); - if venv_dir.is_dir() { - if is_up_to_date() { - return Ok(venv_dir); - } else { + let venv_dir = match get_self_venv_status() { + Ok(venv_dir) => return Ok(venv_dir), + Err((venv_dir, SelfVenvStatus::DoesNotExist)) => venv_dir, + Err((venv_dir, SelfVenvStatus::NotUpToDate)) => { if output != CommandOutput::Quiet { echo!("Detected outdated rye internals. Refreshing"); } fs::remove_dir_all(&venv_dir) .path_context(&venv_dir, "could not remove self-venv for update")?; + + venv_dir } - } + }; if output != CommandOutput::Quiet { echo!("Bootstrapping rye internals"); diff --git a/rye/src/cli/mod.rs b/rye/src/cli/mod.rs index c34a163de3..32054b82ee 100644 --- a/rye/src/cli/mod.rs +++ b/rye/src/cli/mod.rs @@ -29,9 +29,10 @@ mod version; use git_testament::git_testament; -use crate::bootstrap::SELF_PYTHON_TARGET_VERSION; +use crate::bootstrap::{get_self_venv_status, SELF_PYTHON_TARGET_VERSION}; use crate::config::Config; use crate::platform::symlinks_supported; +use crate::pyproject::read_venv_marker; git_testament!(TESTAMENT); @@ -151,7 +152,19 @@ fn print_version() -> Result<(), Error> { std::env::consts::OS, std::env::consts::ARCH ); - echo!("self-python: {}", SELF_PYTHON_TARGET_VERSION); + + let self_venv_python = match get_self_venv_status() { + Ok(venv_dir) | Err((venv_dir, _)) => read_venv_marker(&venv_dir).map(|mark| mark.python), + }; + + if let Some(python) = self_venv_python { + echo!("self-python: {}", python); + } else { + echo!( + "self-python: not bootstrapped (target: {})", + SELF_PYTHON_TARGET_VERSION + ); + } echo!("symlink support: {}", symlinks_supported()); echo!("uv enabled: {}", Config::current().use_uv()); Ok(())