Skip to content

Commit

Permalink
[red-knot] Add support for --system-site-packages virtual environme…
Browse files Browse the repository at this point in the history
…nts (#12759)
  • Loading branch information
AlexWaygood authored Aug 9, 2024
1 parent 83db48d commit 37b9bac
Show file tree
Hide file tree
Showing 11 changed files with 772 additions and 201 deletions.
15 changes: 4 additions & 11 deletions crates/red_knot/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use salsa::plumbing::ZalsaDatabase;
use red_knot_python_semantic::{ProgramSettings, SearchPathSettings};
use red_knot_server::run_server;
use red_knot_workspace::db::RootDatabase;
use red_knot_workspace::site_packages::site_packages_dirs_of_venv;
use red_knot_workspace::site_packages::VirtualEnvironment;
use red_knot_workspace::watch;
use red_knot_workspace::watch::WorkspaceWatcher;
use red_knot_workspace::workspace::WorkspaceMetadata;
Expand Down Expand Up @@ -164,16 +164,9 @@ fn run() -> anyhow::Result<ExitStatus> {

// TODO: Verify the remaining search path settings eagerly.
let site_packages = venv_path
.map(|venv_path| {
let venv_path = SystemPath::absolute(venv_path, &cli_base_path);

if system.is_directory(&venv_path) {
Ok(site_packages_dirs_of_venv(&venv_path, &system)?)
} else {
Err(anyhow!(
"Provided venv-path {venv_path} is not a directory!"
))
}
.map(|path| {
VirtualEnvironment::new(path, &OsSystem::new(cli_base_path))
.and_then(|venv| venv.site_packages_directories(&system))
})
.transpose()?
.unwrap_or_default();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,6 @@ fn try_resolve_module_resolution_settings(
tracing::info!("Custom typeshed directory: {custom_typeshed}");
}

if !site_packages.is_empty() {
tracing::info!("Site-packages directories: {site_packages:?}");
}

let system = db.system();
let files = db.files();

Expand Down
9 changes: 9 additions & 0 deletions crates/red_knot_python_semantic/src/python_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ pub struct PythonVersion {
pub minor: u8,
}

impl PythonVersion {
pub fn free_threaded_build_available(self) -> bool {
self >= PythonVersion {
major: 3,
minor: 13,
}
}
}

impl TryFrom<(&str, &str)> for PythonVersion {
type Error = std::num::ParseIntError;

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 37b9bac

Please sign in to comment.