Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use correct python path for venv creation in windows #4164

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,3 @@
use crate::backend;
use crate::cli::args::BackendArg;
use crate::cmd::CmdLineRunner;
use crate::config::config_file::trust_check;
Expand All @@ -8,6 +7,7 @@ use crate::env_diff::EnvMap;
use crate::file::{display_path, which_non_pristine};
use crate::toolset::ToolsetBuilder;
use crate::Result;
use crate::{backend, plugins};
use indexmap::IndexMap;
use std::path::{Path, PathBuf};

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
Loading