mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 18:58:04 +00:00
[ty] Resolve python environment in Options::to_program_settings
(#18960)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
parent
d00697621e
commit
1dcdf7f41d
11 changed files with 208 additions and 277 deletions
|
@ -21,7 +21,7 @@ use std::fmt::Write;
|
|||
use ty_python_semantic::pull_types::pull_types;
|
||||
use ty_python_semantic::types::check_types;
|
||||
use ty_python_semantic::{
|
||||
Program, ProgramSettings, PythonEnvironmentPath, PythonPlatform, PythonVersionSource,
|
||||
Program, ProgramSettings, PythonEnvironment, PythonPlatform, PythonVersionSource,
|
||||
PythonVersionWithSource, SearchPathSettings, SysPrefixPathOrigin,
|
||||
};
|
||||
|
||||
|
@ -259,6 +259,18 @@ fn run_test(
|
|||
|
||||
let configuration = test.configuration();
|
||||
|
||||
let site_packages_paths = if let Some(python) = configuration.python() {
|
||||
let environment =
|
||||
PythonEnvironment::new(python, SysPrefixPathOrigin::PythonCliFlag, db.system())
|
||||
.expect("Python environment to point to a valid path");
|
||||
environment
|
||||
.site_packages_paths(db.system())
|
||||
.expect("Python environment to be valid")
|
||||
.into_vec()
|
||||
} else {
|
||||
vec![]
|
||||
};
|
||||
|
||||
let settings = ProgramSettings {
|
||||
python_version: PythonVersionWithSource {
|
||||
version: python_version,
|
||||
|
@ -271,15 +283,7 @@ fn run_test(
|
|||
src_roots: vec![src_path],
|
||||
extra_paths: configuration.extra_paths().unwrap_or_default().to_vec(),
|
||||
custom_typeshed: custom_typeshed_path.map(SystemPath::to_path_buf),
|
||||
python_environment: configuration
|
||||
.python()
|
||||
.map(|sys_prefix| {
|
||||
PythonEnvironmentPath::explicit(
|
||||
sys_prefix.to_path_buf(),
|
||||
SysPrefixPathOrigin::PythonCliFlag,
|
||||
)
|
||||
})
|
||||
.unwrap_or(PythonEnvironmentPath::Testing(vec![])),
|
||||
site_packages_paths,
|
||||
}
|
||||
.to_search_paths(db.system(), db.vendored())
|
||||
.expect("Failed to resolve search path settings"),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue