Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion crates/pet-pyenv/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ fn get_pyenv_manager_version(
) -> Option<String> {
// In windows, the version is stored in the `.pyenv/.version` file

let pyenv_dir = get_pyenv_dir(environment)?;
// Try env var path first, then fall back to home directory
let pyenv_dir = get_pyenv_dir(environment)
.or_else(|| get_home_pyenv_dir(environment)?.parent().map(PathBuf::from))?;

let mut version_file = pyenv_dir.join(".version");
if !version_file.exists() {
// We might have got the path `~/.pyenv/pyenv-win`
Expand Down
57 changes: 57 additions & 0 deletions crates/pet-pyenv/tests/pyenv_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,63 @@

mod common;

#[test]
#[cfg(windows)]
fn gets_pyenv_manager_version_without_env_vars() {
use crate::common::{create_test_environment, resolve_test_path};
use pet_conda::Conda;
use pet_core::{
manager::{EnvManager, EnvManagerType},
Locator,
};
use pet_pyenv::PyEnv;
use pet_reporter::{cache::CacheReporter, collect};
use std::{collections::HashMap, sync::Arc};

// Test that pyenv-win version detection works when PYENV/PYENV_ROOT env vars are not set
// by falling back to the home directory path (~/.pyenv/.version)
let home = resolve_test_path(&["windows", "pyenv_no_env_vars", "user_home"]);
let pyenv_bin = resolve_test_path(&[
"windows",
"pyenv_no_env_vars",
"user_home",
".pyenv",
"pyenv-win",
"bin",
]);

// Create environment WITHOUT pyenv/pyenv_root env vars, but provide the bin path
// via known_global_search_locations (simulates pyenv being on PATH)
let environment =
create_test_environment(HashMap::new(), Some(home.clone()), vec![pyenv_bin], None);

let conda = Arc::new(Conda::from(&environment));
let locator = PyEnv::from(&environment, conda);
let reporter = Arc::new(collect::create_reporter());
locator.find(&CacheReporter::new(reporter.clone()));

let managers = reporter.managers.lock().unwrap().clone();

// Should find the pyenv manager with version from ~/.pyenv/.version
assert_eq!(managers.len(), 1);

let expected_manager = EnvManager {
executable: resolve_test_path(&[
"windows",
"pyenv_no_env_vars",
"user_home",
".pyenv",
"pyenv-win",
"bin",
"pyenv.exe",
]),
version: Some("3.5.0".to_string()),
tool: EnvManagerType::Pyenv,
};
assert_eq!(expected_manager.version, managers[0].version);
assert_eq!(expected_manager.tool, managers[0].tool);
}

#[test]
#[cfg(unix)]
fn does_not_find_any_pyenv_envs() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.5.0
Loading