mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-02 06:42:02 +00:00
Allow discovery of venv in VIRTUAL_ENV env variable (#16853)
## Summary Fixes #16744 Allows the cli to find a virtual environment from the VIRTUAL_ENV environment variable if no `--python` is set ## Test Plan Manual testing, of: - Virtual environments explicitly activated using `source .venv/bin/activate` - Virtual environments implicilty activated via `uv run` - Broken virtual environments with no `pyvenv.cfg` file
This commit is contained in:
parent
12725943cd
commit
cdafd8e32b
5 changed files with 111 additions and 34 deletions
|
@ -1,5 +1,6 @@
|
|||
use crate::module_resolver::SearchPaths;
|
||||
use crate::python_platform::PythonPlatform;
|
||||
use crate::site_packages::SysPrefixPathOrigin;
|
||||
use crate::Db;
|
||||
|
||||
use anyhow::Context;
|
||||
|
@ -142,7 +143,7 @@ pub enum PythonPath {
|
|||
/// `/opt/homebrew/lib/python3.X/site-packages`.
|
||||
///
|
||||
/// [`sys.prefix`]: https://docs.python.org/3/library/sys.html#sys.prefix
|
||||
SysPrefix(SystemPathBuf),
|
||||
SysPrefix(SystemPathBuf, SysPrefixPathOrigin),
|
||||
|
||||
/// Resolved site packages paths.
|
||||
///
|
||||
|
@ -150,3 +151,13 @@ pub enum PythonPath {
|
|||
/// because it would unnecessarily complicate the test setup.
|
||||
KnownSitePackages(Vec<SystemPathBuf>),
|
||||
}
|
||||
|
||||
impl PythonPath {
|
||||
pub fn from_virtual_env_var(path: impl Into<SystemPathBuf>) -> Self {
|
||||
Self::SysPrefix(path.into(), SysPrefixPathOrigin::VirtualEnvVar)
|
||||
}
|
||||
|
||||
pub fn from_cli_flag(path: SystemPathBuf) -> Self {
|
||||
Self::SysPrefix(path, SysPrefixPathOrigin::PythonCliFlag)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue