Skip to content

Commit

Permalink
Report the actual self python version (#843)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluss authored Mar 6, 2024
1 parent 11af741 commit 831e7ee
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 8 deletions.
35 changes: 29 additions & 6 deletions rye/src/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf, (PathBuf, SelfVenvStatus)> {
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<PathBuf, Error> {
ensure_self_venv_with_toolchain(output, None)
Expand All @@ -75,19 +97,20 @@ pub fn ensure_self_venv_with_toolchain(
toolchain_version_request: Option<PythonVersionRequest>,
) -> Result<PathBuf, Error> {
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");
Expand Down
17 changes: 15 additions & 2 deletions rye/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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(())
Expand Down

0 comments on commit 831e7ee

Please sign in to comment.