Fix venv PATH on windows (#1095)

Windows uses `;` instead of `:` to separate `PATH` entries. This pull
request switches from manually using `:` to the `std::env` functions.
This fixes

```
puffin pip install -e scripts/editable-installs/maturin_editable
```

on windows.
This commit is contained in:
konsti 2024-01-25 16:40:52 +01:00 committed by GitHub
parent 272555e915
commit 035cd81ac8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2,7 +2,7 @@
//!
//! <https://packaging.python.org/en/latest/specifications/source-distribution-format/>
use std::env;
use std::ffi::OsString;
use std::fmt::{Display, Formatter};
use std::io;
use std::io::BufRead;
@ -10,6 +10,7 @@ use std::path::{Path, PathBuf};
use std::process::Output;
use std::str::FromStr;
use std::sync::Arc;
use std::{env, iter};
use fs_err as fs;
use indoc::formatdoc;
@ -90,6 +91,8 @@ pub enum Error {
#[source]
missing_header_cause: MissingHeaderCause,
},
#[error("Failed to build PATH for build script")]
BuildScriptPath(#[source] env::JoinPathsError),
}
#[derive(Debug)]
@ -729,12 +732,13 @@ async fn run_python_script(
script: &str,
source_tree: &Path,
) -> Result<Output, Error> {
// `OsString` doesn't impl `Add`
let mut new_path = venv.bin_dir().into_os_string();
if let Some(path) = env::var_os("PATH") {
new_path.push(":");
new_path.push(path);
}
// Prepend the venv bin dir to PATH
let new_path = if let Some(old_path) = env::var_os("PATH") {
let new_path = iter::once(venv.bin_dir()).chain(env::split_paths(&old_path));
env::join_paths(new_path).map_err(Error::BuildScriptPath)?
} else {
OsString::from("")
};
Command::new(venv.python_executable())
.args(["-c", script])
.current_dir(source_tree)