Skip to content

Commit

Permalink
fix: use correct python path for venv creation in windows
Browse files Browse the repository at this point in the history
  • Loading branch information
tisoft committed Jan 20, 2025
1 parent 491fb36 commit d7cf0cc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
6 changes: 2 additions & 4 deletions src/config/env_directive/venv.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::backend;
use crate::{backend, plugins};
use crate::cli::args::BackendArg;
use crate::cmd::CmdLineRunner;
use crate::config::config_file::trust_check;
Expand Down Expand Up @@ -48,9 +48,7 @@ impl EnvResults {
}
});
let python_path = tv.map(|tv| {
tv.install_path()
.join("bin")
.join("python")
plugins::core::python::python_path(tv)
.to_string_lossy()
.to_string()
});
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ mod erlang;
mod go;
mod java;
mod node;
mod python;
pub(crate) mod python;
#[cfg_attr(windows, path = "ruby_windows.rs")]
mod ruby;
mod rust;
Expand Down
22 changes: 11 additions & 11 deletions src/plugins/core/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ pub struct PythonPlugin {
ba: BackendArg,
}

pub fn python_path(tv: &ToolVersion) -> PathBuf {
if cfg!(windows) {
tv.install_path().join("python.exe")
} else {
tv.install_path().join("bin/python")
}
}

impl PythonPlugin {
pub fn new() -> Self {
let ba = plugins::core::new_backend_arg("python");
Expand Down Expand Up @@ -72,14 +80,6 @@ impl PythonPlugin {
Ok(())
}

fn python_path(&self, tv: &ToolVersion) -> PathBuf {
if cfg!(windows) {
tv.install_path().join("python.exe")
} else {
tv.install_path().join("bin/python")
}
}

fn fetch_precompiled_remote_versions(&self) -> eyre::Result<&Vec<(String, String, String)>> {
static PRECOMPILED_CACHE: Lazy<CacheManager<Vec<(String, String, String)>>> =
Lazy::new(|| {
Expand Down Expand Up @@ -322,7 +322,7 @@ impl PythonPlugin {
if !virtualenv.exists() {
if SETTINGS.python.venv_auto_create {
info!("setting up virtualenv at: {}", virtualenv.display());
let mut cmd = CmdLineRunner::new(self.python_path(tv))
let mut cmd = CmdLineRunner::new(python_path(tv))
.arg("-m")
.arg("venv")
.arg(&virtualenv)
Expand Down Expand Up @@ -351,7 +351,7 @@ impl PythonPlugin {

// fn check_venv_python(&self, virtualenv: &Path, tv: &ToolVersion) -> eyre::Result<()> {
// let symlink = virtualenv.join("bin/python");
// let target = self.python_path(tv);
// let target = python_path(tv);
// let symlink_target = symlink.read_link().unwrap_or_default();
// ensure!(
// symlink_target == target,
Expand All @@ -370,7 +370,7 @@ impl PythonPlugin {
pr: &Box<dyn SingleReport>,
) -> eyre::Result<()> {
pr.set_message("python --version".into());
CmdLineRunner::new(self.python_path(tv))
CmdLineRunner::new(python_path(tv))
.with_pr(pr)
.arg("--version")
.envs(config.env()?)
Expand Down

0 comments on commit d7cf0cc

Please sign in to comment.