2e0ce70d13
## Summary First batch of changes for windows support. Notable changes: * Fixes all compile errors and added windows specific paths. * Working venv creation on windows, both from a base interpreter and from a venv. This requires querying `stdlib` from the sysconfig paths to find the launcher. * Basic url/path conversion handling for windows. * `if cfg!(...)` instead of `#[cfg()]`. This should make it easier to keep everything compiling across platforms. ## Outlook Test summary: 402 tests run: 299 passed (15 slow), 103 failed, 1 skipped There are various reason for the remaining test failure: * Windows-specific colorama and tzdata dependencies that change the snapshot slightly. This is by far the biggest batch. * Some url-path handling issues. I fixed some in the PR, some remain. * Lack of the latest python patch versions for older pythons on my machine, since there are no builds for windows and we need to register them in the registry for them to be picked up for `py --list-paths` (CC @zanieb RE #1070). * Lack of entrypoint launchers. * ... likely more
59 lines
1.8 KiB
Rust
59 lines
1.8 KiB
Rust
#![allow(dead_code)]
|
|
|
|
use std::path::{Path, PathBuf};
|
|
|
|
use assert_cmd::Command;
|
|
use assert_fs::assert::PathAssert;
|
|
use assert_fs::fixture::PathChild;
|
|
use assert_fs::TempDir;
|
|
use insta_cmd::get_cargo_bin;
|
|
|
|
pub(crate) const BIN_NAME: &str = "puffin";
|
|
|
|
pub(crate) const INSTA_FILTERS: &[(&str, &str)] = &[
|
|
(r"--cache-dir .*", "--cache-dir [CACHE_DIR]"),
|
|
(r"(\d+\.)?\d+(ms|s)", "[TIME]"),
|
|
(r"v\d+\.\d+\.\d+", "v[VERSION]"),
|
|
// Rewrite Windows output to Unix output
|
|
(r"\\([\w\d])", "/$1"),
|
|
(r"puffin.exe", "puffin"),
|
|
// The exact message is host language dependent
|
|
(
|
|
r"Caused by: .* \(os error 2\)",
|
|
"Caused by: No such file or directory (os error 2)",
|
|
),
|
|
];
|
|
|
|
pub(crate) fn venv_to_interpreter(venv: &Path) -> PathBuf {
|
|
if cfg!(unix) {
|
|
venv.join("bin").join("python")
|
|
} else if cfg!(windows) {
|
|
venv.join("Scripts").join("python.exe")
|
|
} else {
|
|
unimplemented!("Only Windows and Unix are supported")
|
|
}
|
|
}
|
|
|
|
/// Create a virtual environment named `.venv` in a temporary directory.
|
|
pub(crate) fn create_venv_py312(temp_dir: &TempDir, cache_dir: &TempDir) -> PathBuf {
|
|
create_venv(temp_dir, cache_dir, "3.12")
|
|
}
|
|
|
|
/// Create a virtual environment named `.venv` in a temporary directory with the given
|
|
/// Python version. Expected format for `python` is "python<version>".
|
|
pub(crate) fn create_venv(temp_dir: &TempDir, cache_dir: &TempDir, python: &str) -> PathBuf {
|
|
let venv = temp_dir.child(".venv");
|
|
Command::new(get_cargo_bin(BIN_NAME))
|
|
.arg("venv")
|
|
.arg(venv.as_os_str())
|
|
.arg("--cache-dir")
|
|
.arg(cache_dir.path())
|
|
.arg("--python")
|
|
.arg(python)
|
|
.current_dir(temp_dir)
|
|
.assert()
|
|
.success();
|
|
venv.assert(predicates::path::is_dir());
|
|
venv.to_path_buf()
|
|
}
|