From 2d0a69af97c111ee75527f97d67d14f9e3979c0e Mon Sep 17 00:00:00 2001 From: messense Date: Fri, 16 Sep 2022 16:26:49 +0800 Subject: [PATCH] Refactor virtualenv bin dir handling for Windows --- Changelog.md | 1 + src/target.rs | 31 +++++++++++++++++++------------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/Changelog.md b/Changelog.md index 1792e07b6..88771b8a6 100644 --- a/Changelog.md +++ b/Changelog.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] * Fix `Cargo.toml` in new project template in [#1109](https://github.com/PyO3/maturin/pull/1109) +* Fix `maturin develop` on Windows when using Python installed from msys2 in [#1112](https://github.com/PyO3/maturin/pull/1112) ## [0.13.3] - 2022-09-15 diff --git a/src/target.rs b/src/target.rs index 2667e7e19..dcbfc950f 100644 --- a/src/target.rs +++ b/src/target.rs @@ -566,25 +566,32 @@ impl Target { /// Returns the path to the python executable inside a venv pub fn get_venv_python(&self, venv_base: impl AsRef) -> PathBuf { - if self.is_windows() { - let path = venv_base.as_ref().join("Scripts").join("python.exe"); - if path.exists() { - path - } else { - // for conda environment - venv_base.as_ref().join("python.exe") - } + let python = if self.is_windows() { + "python.exe" } else { - venv_base.as_ref().join("bin").join("python") - } + "python" + }; + self.get_venv_bin_dir(venv_base).join(python) } /// Returns the directory where the binaries are stored inside a venv pub fn get_venv_bin_dir(&self, venv_base: impl AsRef) -> PathBuf { + let venv = venv_base.as_ref(); if self.is_windows() { - venv_base.as_ref().join("Scripts") + let bin_dir = venv.join("Scripts"); + if bin_dir.exists() { + return bin_dir; + } + // Python innstalled via msys2 on Windows might produce a POSIX-like venv + // See https://github.com/PyO3/maturin/issues/1108 + let bin_dir = venv.join("bin"); + if bin_dir.exists() { + return bin_dir; + } + // for conda environment + venv.to_path_buf() } else { - venv_base.as_ref().join("bin") + venv.join("bin") } }