Skip to content

Commit

Permalink
Test for .venv symlink (#6597)
Browse files Browse the repository at this point in the history
For various reasons, I have a preference for out of tree virtual
environments. Things just work if I symlink, but I don't know that this
is guaranteed, so I thought I'd add a test for it. It looks like there's
another code path that matters (`FoundInterpreter::discover ->
PythonEnvironment::from_root`) for the higher level commands, but
couldn't spot a good place to test that.

Related discussion:
#1495 (comment) /
#1578 (comment)
  • Loading branch information
hauntsaninja committed Aug 26, 2024
1 parent 50997bc commit 6220532
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions crates/uv-python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1562,6 +1562,32 @@ mod tests {
Ok(())
}

#[test]
fn find_python_venv_symlink() -> Result<()> {
let context = TestContext::new()?;

let venv = context.tempdir.child("target").child("env");
TestContext::mock_venv(&venv, "3.10.6")?;
let symlink = context.tempdir.child("proj").child(".venv");
context.tempdir.child("proj").create_dir_all()?;
symlink.symlink_to_dir(venv)?;

let python = context.run(|| {
find_python_installation(
&PythonRequest::parse("../proj/.venv"),
EnvironmentPreference::Any,
PythonPreference::OnlySystem,
&context.cache,
)
})??;
assert_eq!(
python.interpreter().python_full_version().to_string(),
"3.10.6",
"We should find the symlinked venv"
);
Ok(())
}

#[test]
fn find_python_treats_missing_file_path_as_file() -> Result<()> {
let context = TestContext::new()?;
Expand Down

0 comments on commit 6220532

Please sign in to comment.