mirror of
https://github.com/astral-sh/uv.git
synced 2025-07-07 21:35:00 +00:00
Don't copy gitignored files in workspace tests (#4012)
The workspace test directories can be used both in tests and directly for developing/debugging. In the latter, we shouldn't copy the venv and the lockfile when running tests. Using the ignore crate over manual recursion we exclude those files.
This commit is contained in:
parent
36f7fa3917
commit
da7d5549a3
5 changed files with 21 additions and 3 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -4383,6 +4383,7 @@ dependencies = [
|
||||||
"filetime",
|
"filetime",
|
||||||
"flate2",
|
"flate2",
|
||||||
"fs-err",
|
"fs-err",
|
||||||
|
"ignore",
|
||||||
"indicatif",
|
"indicatif",
|
||||||
"indoc",
|
"indoc",
|
||||||
"insta",
|
"insta",
|
||||||
|
|
|
@ -78,6 +78,7 @@ assert_fs = { version = "1.1.0" }
|
||||||
base64 = { version = "0.22.0" }
|
base64 = { version = "0.22.0" }
|
||||||
byteorder = { version = "1.5.0" }
|
byteorder = { version = "1.5.0" }
|
||||||
filetime = { version = "0.2.23" }
|
filetime = { version = "0.2.23" }
|
||||||
|
ignore = { version = "0.4.22" }
|
||||||
indoc = { version = "2.0.4" }
|
indoc = { version = "2.0.4" }
|
||||||
insta = { version = "1.36.1", features = ["filters", "json"] }
|
insta = { version = "1.36.1", features = ["filters", "json"] }
|
||||||
predicates = { version = "3.0.4" }
|
predicates = { version = "3.0.4" }
|
||||||
|
|
|
@ -628,6 +628,21 @@ pub fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> std::io::Re
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Recursively copy a directory and its contents, skipping gitignored files.
|
||||||
|
pub fn copy_dir_ignore(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> anyhow::Result<()> {
|
||||||
|
for entry in ignore::Walk::new(&src) {
|
||||||
|
let entry = entry?;
|
||||||
|
let relative = entry.path().strip_prefix(&src)?;
|
||||||
|
let ty = entry.file_type().unwrap();
|
||||||
|
if ty.is_dir() {
|
||||||
|
fs_err::create_dir(dst.as_ref().join(relative))?;
|
||||||
|
} else {
|
||||||
|
fs_err::copy(entry.path(), dst.as_ref().join(relative))?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
/// Utility macro to return the name of the current function.
|
/// Utility macro to return the name of the current function.
|
||||||
///
|
///
|
||||||
/// https://stackoverflow.com/a/40234666/3549270
|
/// https://stackoverflow.com/a/40234666/3549270
|
||||||
|
|
|
@ -4,7 +4,7 @@ use std::process::Command;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
|
||||||
use crate::common::{copy_dir_all, get_bin, uv_snapshot, TestContext, EXCLUDE_NEWER};
|
use crate::common::{copy_dir_ignore, get_bin, uv_snapshot, TestContext, EXCLUDE_NEWER};
|
||||||
|
|
||||||
mod common;
|
mod common;
|
||||||
|
|
||||||
|
@ -373,7 +373,7 @@ fn test_uv_run_with_package_virtual_workspace() -> Result<()> {
|
||||||
let context = TestContext::new("3.12");
|
let context = TestContext::new("3.12");
|
||||||
let work_dir = context.temp_dir.join("albatross-virtual-workspace");
|
let work_dir = context.temp_dir.join("albatross-virtual-workspace");
|
||||||
|
|
||||||
copy_dir_all(
|
copy_dir_ignore(
|
||||||
workspaces_dir().join("albatross-virtual-workspace"),
|
workspaces_dir().join("albatross-virtual-workspace"),
|
||||||
&work_dir,
|
&work_dir,
|
||||||
)?;
|
)?;
|
||||||
|
@ -444,7 +444,7 @@ fn test_uv_run_with_package_root_workspace() -> Result<()> {
|
||||||
let context = TestContext::new("3.12");
|
let context = TestContext::new("3.12");
|
||||||
let work_dir = context.temp_dir.join("albatross-root-workspace");
|
let work_dir = context.temp_dir.join("albatross-root-workspace");
|
||||||
|
|
||||||
copy_dir_all(workspaces_dir().join("albatross-root-workspace"), &work_dir)?;
|
copy_dir_ignore(workspaces_dir().join("albatross-root-workspace"), &work_dir)?;
|
||||||
|
|
||||||
// TODO(konsti): `--python` is being ignored atm, so we need to create the correct venv
|
// TODO(konsti): `--python` is being ignored atm, so we need to create the correct venv
|
||||||
// ourselves and add the output filters.
|
// ourselves and add the output filters.
|
||||||
|
|
1
scripts/workspaces/.gitignore
vendored
Normal file
1
scripts/workspaces/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
uv.lock
|
Loading…
Add table
Add a link
Reference in a new issue