mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 02:38:25 +00:00
[ty] Resolving Python path using CONDA_PREFIX
variable to support Conda and Pixi (#18267)
This commit is contained in:
parent
a1399656c9
commit
53d19f8368
4 changed files with 89 additions and 1 deletions
|
@ -202,6 +202,10 @@ impl PythonPath {
|
|||
Self::SysPrefix(path.into(), SysPrefixPathOrigin::VirtualEnvVar)
|
||||
}
|
||||
|
||||
pub fn from_conda_prefix_var(path: impl Into<SystemPathBuf>) -> Self {
|
||||
Self::Resolve(path.into(), SysPrefixPathOrigin::CondaPrefixVar)
|
||||
}
|
||||
|
||||
pub fn from_cli_flag(path: SystemPathBuf) -> Self {
|
||||
Self::Resolve(path, SysPrefixPathOrigin::PythonCliFlag)
|
||||
}
|
||||
|
|
|
@ -580,6 +580,7 @@ impl fmt::Display for SysPrefixPath {
|
|||
pub enum SysPrefixPathOrigin {
|
||||
PythonCliFlag,
|
||||
VirtualEnvVar,
|
||||
CondaPrefixVar,
|
||||
Derived,
|
||||
LocalVenv,
|
||||
}
|
||||
|
@ -590,7 +591,7 @@ impl SysPrefixPathOrigin {
|
|||
pub(crate) fn must_be_virtual_env(self) -> bool {
|
||||
match self {
|
||||
Self::LocalVenv | Self::VirtualEnvVar => true,
|
||||
Self::PythonCliFlag | Self::Derived => false,
|
||||
Self::PythonCliFlag | Self::Derived | Self::CondaPrefixVar => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -600,6 +601,7 @@ impl Display for SysPrefixPathOrigin {
|
|||
match self {
|
||||
Self::PythonCliFlag => f.write_str("`--python` argument"),
|
||||
Self::VirtualEnvVar => f.write_str("`VIRTUAL_ENV` environment variable"),
|
||||
Self::CondaPrefixVar => f.write_str("`CONDA_PREFIX` environment variable"),
|
||||
Self::Derived => f.write_str("derived `sys.prefix` path"),
|
||||
Self::LocalVenv => f.write_str("local virtual environment"),
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue