Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit bfa10a9

Browse files
committedMar 7, 2025
respect --project during uv python find (astral-sh#11990)
## Summary this pr updates a couple discovery-related functions to accept a directory argument, used as the root directory when searching for a virtual environment ## Test Plan todo
1 parent 40dce4e commit bfa10a9

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed
 

‎crates/uv-python/src/discovery.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use crate::managed::ManagedPythonInstallations;
2929
use crate::microsoft_store::find_microsoft_store_pythons;
3030
use crate::virtualenv::Error as VirtualEnvError;
3131
use crate::virtualenv::{
32-
conda_environment_from_env, virtualenv_from_env, virtualenv_from_working_dir,
32+
conda_environment_from_env, virtualenv_from_dir, virtualenv_from_env,
3333
virtualenv_python_executable, CondaEnvironmentKind,
3434
};
3535
#[cfg(windows)]
@@ -270,7 +270,7 @@ fn python_executables_from_virtual_environments<'a>(
270270
.flatten();
271271

272272
let from_discovered_environment = iter::once_with(|| {
273-
virtualenv_from_working_dir()
273+
virtualenv_from_dir(crate::current_dir()?)
274274
.map(|path| {
275275
path.map(virtualenv_python_executable)
276276
.map(|path| (PythonSource::DiscoveredEnvironment, path))

‎crates/uv-python/src/virtualenv.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,11 @@ pub(crate) fn conda_environment_from_env(kind: CondaEnvironmentKind) -> Option<P
121121
/// Searches for a `.venv` directory in the current or any parent directory. If the current
122122
/// directory is itself a virtual environment (or a subdirectory of a virtual environment), the
123123
/// containing virtual environment is returned.
124-
pub(crate) fn virtualenv_from_working_dir() -> Result<Option<PathBuf>, Error> {
125-
let current_dir = crate::current_dir()?;
126124
127-
for dir in current_dir.ancestors() {
125+
pub(crate) fn virtualenv_from_dir(dir: impl AsRef<Path>) -> Result<Option<PathBuf>, Error> {
126+
let dir = dir.as_ref();
127+
128+
for dir in dir.ancestors() {
128129
// If we're _within_ a virtualenv, return it.
129130
if dir.join("pyvenv.cfg").is_file() {
130131
return Ok(Some(dir.to_path_buf()));

0 commit comments

Comments
 (0)
Please sign in to comment.