| 1 |
use crate::common::{ |
| 2 |
check_installed, create_conda_env, create_virtualenv, maybe_mock_cargo, TestInstallBackend, |
| 3 |
}; |
| 4 |
use anyhow::Result; |
| 5 |
use maturin::{develop, CargoOptions, DevelopOptions}; |
| 6 |
use std::path::{Path, PathBuf}; |
| 7 |
use std::process::Command; |
| 8 |
use std::str; |
| 9 |
|
| 10 |
/// Creates a virtualenv and activates it, checks that the package isn't installed, uses |
| 11 |
/// "maturin develop" to install it and checks it is working |
| 12 |
pub fn test_develop( |
| 13 |
package: impl AsRef<Path>, |
| 14 |
bindings: Option<String>, |
| 15 |
unique_name: &str, |
| 16 |
conda: bool, |
| 17 |
test_backend: TestInstallBackend, |
| 18 |
) -> Result<()> { |
| 19 |
maybe_mock_cargo(); |
| 20 |
|
| 21 |
let package = package.as_ref(); |
| 22 |
let (venv_dir, python) = if conda { |
| 23 |
create_conda_env(&format!("maturin-{unique_name}"), 3, 10)? |
| 24 |
} else { |
| 25 |
create_virtualenv(unique_name, None)? |
| 26 |
}; |
| 27 |
|
| 28 |
// Ensure the test doesn't wrongly pass |
| 29 |
check_installed(package, &python).unwrap_err(); |
| 30 |
|
| 31 |
let uv = matches!(test_backend, TestInstallBackend::Uv); |
| 32 |
let mut pip_packages = Vec::new(); |
| 33 |
if unique_name.contains("cffi") { |
| 34 |
pip_packages.push("cffi"); |
| 35 |
} |
| 36 |
if cfg!(any( |
| 37 |
target_os = "linux", |
| 38 |
target_os = "macos", |
| 39 |
target_os = "windows" |
| 40 |
)) && uv |
| 41 |
{ |
| 42 |
pip_packages.push("uv"); |
| 43 |
} |
| 44 |
if !pip_packages.is_empty() { |
| 45 |
let mut cmd = Command::new(&python); |
| 46 |
cmd.args(["-m", "pip", "install", "--disable-pip-version-check"]) |
| 47 |
.args(pip_packages); |
| 48 |
let output = cmd.output()?; |
| 49 |
if !output.status.success() { |
| 50 |
panic!( |
| 51 |
"Failed to install cffi: {}\n---stdout:\n{}---stderr:\n{}", |
| 52 |
output.status, |
| 53 |
str::from_utf8(&output.stdout)?, |
| 54 |
str::from_utf8(&output.stderr)? |
| 55 |
); |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
let manifest_file = package.join("Cargo.toml"); |
| 60 |
let develop_options = DevelopOptions { |
| 61 |
bindings, |
| 62 |
release: false, |
| 63 |
strip: false, |
| 64 |
extras: Vec::new(), |
| 65 |
skip_install: false, |
| 66 |
pip_path: None, |
| 67 |
cargo_options: CargoOptions { |
| 68 |
manifest_path: Some(manifest_file), |
| 69 |
quiet: true, |
| 70 |
target_dir: Some(PathBuf::from(format!("test-crates/targets/{unique_name}"))), |
| 71 |
..Default::default() |
| 72 |
}, |
| 73 |
uv, |
| 74 |
compression: Default::default(), |
| 75 |
}; |
| 76 |
develop(develop_options, &venv_dir)?; |
| 77 |
|
| 78 |
check_installed(package, &python)?; |
| 79 |
Ok(()) |
| 80 |
} |