Skip to content

Commit

Permalink
Merge pull request #1112 from messense/venv-python
Browse files Browse the repository at this point in the history
Refactor virtualenv bin dir handling for Windows
  • Loading branch information
messense committed Sep 16, 2022
2 parents c4d1a88 + 2d0a69a commit fb130c9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
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

0 comments on commit fb130c9

Please sign in to comment.