Skip to content

Commit 0ee5e80

Browse files
authored
Replace unmaintained fs2 with fs4 (#2317)
* Replace unmaintained fs2 with fs4 * Locate python interpreter python after creating venv * Add timeout to rstest
1 parent ea2e54e commit 0ee5e80

File tree

5 files changed

+67
-58
lines changed

5 files changed

+67
-58
lines changed

Cargo.lock

+7-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ pretty_assertions = { version = "1.3.0", optional = true }
135135

136136
[dev-dependencies]
137137
expect-test = "1.4.1"
138-
fs2 = "0.4.3"
138+
fs4 = { version = "0.11.1", features = ["fs-err"] }
139139
indoc = "2.0.3"
140140
pretty_assertions = "1.3.0"
141141
rstest = "0.22.0"

tests/common/integration.rs

+54-49
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use crate::common::{
2-
check_installed, create_virtualenv, create_virtualenv_name, maybe_mock_cargo, test_python_path,
2+
check_installed, create_named_virtualenv, create_virtualenv, maybe_mock_cargo, test_python_path,
33
};
44
use anyhow::{bail, Context, Result};
55
#[cfg(feature = "zig")]
66
use cargo_zigbuild::Zig;
77
use clap::Parser;
8-
use fs2::FileExt;
8+
use fs4::fs_err::FileExt;
99
use fs_err::File;
1010
use maturin::{BuildOptions, PlatformTag, PythonInterpreter, Target};
1111
use normpath::PathExt;
@@ -38,25 +38,25 @@ pub fn test_integration(
3838
let shed = format!("test-crates/wheels/{unique_name}");
3939
let target_dir = format!("test-crates/targets/{unique_name}");
4040
let python_interp = test_python_path();
41-
let mut cli = vec![
42-
"build",
43-
"--quiet",
44-
"--manifest-path",
45-
&package_string,
46-
"--target-dir",
47-
&target_dir,
48-
"--out",
49-
&shed,
41+
let mut cli: Vec<std::ffi::OsString> = vec![
42+
"build".into(),
43+
"--quiet".into(),
44+
"--manifest-path".into(),
45+
package_string.into(),
46+
"--target-dir".into(),
47+
target_dir.into(),
48+
"--out".into(),
49+
shed.into(),
5050
];
5151

5252
if let Some(ref bindings) = bindings {
53-
cli.push("--bindings");
54-
cli.push(bindings);
53+
cli.push("--bindings".into());
54+
cli.push(bindings.into());
5555
}
5656

5757
if let Some(target) = target {
58-
cli.push("--target");
59-
cli.push(target)
58+
cli.push("--target".into());
59+
cli.push(target.into())
6060
}
6161

6262
#[cfg(feature = "zig")]
@@ -65,11 +65,11 @@ pub fn test_integration(
6565
let zig_found = false;
6666

6767
let test_zig = if zig && (env::var("GITHUB_ACTIONS").is_ok() || zig_found) {
68-
cli.push("--zig");
68+
cli.push("--zig".into());
6969
true
7070
} else {
71-
cli.push("--compatibility");
72-
cli.push("linux");
71+
cli.push("--compatibility".into());
72+
cli.push("linux".into());
7373
false
7474
};
7575

@@ -80,47 +80,52 @@ pub fn test_integration(
8080
.join("venvs");
8181
let cffi_provider = "cffi-provider";
8282
let cffi_venv = venvs_dir.join(cffi_provider);
83-
let target_triple = Target::from_target_triple(None)?;
84-
let python = target_triple.get_venv_python(&cffi_venv);
8583

8684
if let Some(interp) = python_interp.as_ref() {
87-
cli.push("--interpreter");
88-
cli.push(interp);
85+
cli.push("--interpreter".into());
86+
cli.push(interp.into());
8987
} else {
9088
// Install cffi in a separate environment
9189

9290
// All tests try to use this venv at the same time, so we need to make sure only one
9391
// modifies it at a time and that during that time, no other test reads it.
9492
let file = File::create(venvs_dir.join("cffi-provider.lock"))?;
95-
file.file().lock_exclusive()?;
96-
if !dbg!(venvs_dir.join(cffi_provider)).is_dir() {
97-
dbg!(create_virtualenv_name(
98-
cffi_provider,
99-
python_interp.clone().map(PathBuf::from)
100-
)?);
93+
file.lock_exclusive()?;
94+
let python = if !cffi_venv.is_dir() {
95+
create_named_virtualenv(cffi_provider, python_interp.clone().map(PathBuf::from))?;
96+
let target_triple = Target::from_target_triple(None)?;
97+
let python = target_triple.get_venv_python(&cffi_venv);
98+
assert!(python.is_file(), "cffi venv not created correctly");
10199
let pip_install_cffi = [
102100
"-m",
103101
"pip",
104102
"--disable-pip-version-check",
103+
"--no-cache-dir",
105104
"install",
106105
"cffi",
107106
];
108107
let output = Command::new(&python)
109108
.args(pip_install_cffi)
110-
.status()
111-
//.output()
112-
.context(format!("pip install cffi failed with {python:?}"))?;
113-
if !output.success() {
114-
bail!("Installing cffi into {} failed", cffi_venv.display());
109+
.output()
110+
.with_context(|| format!("pip install cffi failed with {python:?}"))?;
111+
if !output.status.success() {
112+
let stderr = String::from_utf8_lossy(&output.stderr);
113+
let stdout = String::from_utf8_lossy(&output.stdout);
114+
bail!(
115+
"Installing cffi into {} failed.\nstdout: {}\nstderr: {}",
116+
cffi_venv.display(),
117+
stdout,
118+
stderr
119+
);
115120
}
116-
}
117-
file.file().unlock()?;
118-
cli.push("--interpreter");
119-
cli.push(
120121
python
121-
.to_str()
122-
.context("non-utf8 python interpreter path")?,
123-
);
122+
} else {
123+
let target_triple = Target::from_target_triple(None)?;
124+
target_triple.get_venv_python(&cffi_venv)
125+
};
126+
file.unlock()?;
127+
cli.push("--interpreter".into());
128+
cli.push(python.as_os_str().to_owned());
124129
}
125130

126131
let options: BuildOptions = BuildOptions::try_parse_from(cli)?;
@@ -234,20 +239,20 @@ pub fn test_integration_conda(package: impl AsRef<Path>, bindings: Option<String
234239
}
235240

236241
// The first argument is ignored by clap
237-
let mut cli = vec![
238-
"build",
239-
"--manifest-path",
240-
&package_string,
241-
"--quiet",
242-
"--interpreter",
242+
let mut cli: Vec<std::ffi::OsString> = vec![
243+
"build".into(),
244+
"--manifest-path".into(),
245+
package_string.into(),
246+
"--quiet".into(),
247+
"--interpreter".into(),
243248
];
244249
for interp in &interpreters {
245-
cli.push(interp.to_str().unwrap());
250+
cli.push(interp.to_str().unwrap().into());
246251
}
247252

248253
if let Some(ref bindings) = bindings {
249-
cli.push("--bindings");
250-
cli.push(bindings);
254+
cli.push("--bindings".into());
255+
cli.push(bindings.into());
251256
}
252257

253258
let options = BuildOptions::try_parse_from(cli)?;

tests/common/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,14 @@ pub fn create_virtualenv(name: &str, python_interp: Option<PathBuf>) -> Result<(
126126
Err(_) => name.to_string(),
127127
};
128128

129-
let venv_dir = create_virtualenv_name(&venv_name, interp)?;
129+
let venv_dir = create_named_virtualenv(&venv_name, interp)?;
130130

131131
let target = Target::from_target_triple(None)?;
132132
let python = target.get_venv_python(&venv_dir);
133133
Ok((venv_dir, python))
134134
}
135135

136-
pub fn create_virtualenv_name(venv_name: &str, interp: Option<PathBuf>) -> Result<PathBuf> {
136+
pub fn create_named_virtualenv(venv_name: &str, interp: Option<PathBuf>) -> Result<PathBuf> {
137137
let venv_dir = PathBuf::from("test-crates")
138138
.normalize()?
139139
.into_path_buf()

tests/run.rs

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use maturin::pyproject_toml::SdistGenerator;
99
use rstest::rstest;
1010
use std::env;
1111
use std::path::Path;
12+
use std::time::Duration;
1213
use time::macros::datetime;
1314
use which::which;
1415

@@ -200,6 +201,7 @@ fn develop_uniffi_multiple_binding_files() {
200201
}
201202

202203
#[rstest]
204+
#[timeout(Duration::from_secs(60))]
203205
#[case(TestInstallBackend::Pip, "pip")]
204206
#[case(TestInstallBackend::Uv, "uv")]
205207
#[test]
@@ -226,6 +228,7 @@ fn develop_hello_world(#[case] backend: TestInstallBackend, #[case] name: &str)
226228
}
227229

228230
#[rstest]
231+
#[timeout(Duration::from_secs(60))]
229232
#[case(TestInstallBackend::Pip, "pip")]
230233
#[case(TestInstallBackend::Uv, "uv")]
231234
#[test]

0 commit comments

Comments
 (0)