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

Refactor virtualenv bin dir handling for Windows #1112

Merged
merged 1 commit into from
Sep 16, 2022
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
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
31 changes: 19 additions & 12 deletions src/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Path>) -> 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<Path>) -> 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")
}
}

Expand Down