mirror of
https://github.com/astral-sh/uv.git
synced 2025-10-23 08:41:48 +00:00
Consolidate logic for checking for a virtual environment (#14214)
We were checking whether a path was an executable in a virtual environment or the base directory of a virtual environment in multiple places in the codebase. This PR consolidates this logic into one place. Closes #13947.
This commit is contained in:
parent
a9a9e71481
commit
6481aa3e64
5 changed files with 30 additions and 16 deletions
|
@ -130,14 +130,14 @@ pub(crate) fn virtualenv_from_working_dir() -> Result<Option<PathBuf>, Error> {
|
|||
|
||||
for dir in current_dir.ancestors() {
|
||||
// If we're _within_ a virtualenv, return it.
|
||||
if dir.join("pyvenv.cfg").is_file() {
|
||||
if uv_fs::is_virtualenv_base(dir) {
|
||||
return Ok(Some(dir.to_path_buf()));
|
||||
}
|
||||
|
||||
// Otherwise, search for a `.venv` directory.
|
||||
let dot_venv = dir.join(".venv");
|
||||
if dot_venv.is_dir() {
|
||||
if !dot_venv.join("pyvenv.cfg").is_file() {
|
||||
if !uv_fs::is_virtualenv_base(&dot_venv) {
|
||||
return Err(Error::MissingPyVenvCfg(dot_venv));
|
||||
}
|
||||
return Ok(Some(dot_venv));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue