Skip to content

Commit

Permalink
Use differnt test dir
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Aug 23, 2024
1 parent 996e59c commit bdb8f97
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 37 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion crates/distribution-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,6 @@ impl Dist {
return Err(Error::NotFound(url.to_url()));
}


// Determine whether the path represents a built or source distribution.
match ext {
DistExtension::Wheel => {
Expand Down
13 changes: 3 additions & 10 deletions crates/uv-fs/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,12 @@ use path_slash::PathExt;

/// The current working directory.
pub static CWD: LazyLock<PathBuf> =
LazyLock::new(|| {
std::env::var("UV_CWD")
.ok()
.map(PathBuf::from)
.unwrap_or_else(|| std::env::current_dir().expect("The current directory must exist"))
});
LazyLock::new(|| std::env::current_dir().expect("The current directory must exist"));

/// The current working directory, canonicalized.
pub static CANONICAL_CWD: LazyLock<PathBuf> = LazyLock::new(|| {
std::env::var("UV_CWD")
.ok()
.map(PathBuf::from)
.unwrap_or_else(|| std::env::current_dir().expect("The current directory must exist"))
std::env::current_dir()
.expect("The current directory must exist")
.canonicalize()
.expect("The current directory must be canonicalized")
});
Expand Down
1 change: 0 additions & 1 deletion crates/uv-installer/src/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ impl<'a> Planner<'a> {
return Err(Error::NotFound(url.to_url()).into());
}


let sdist = DirectorySourceDist {
name: requirement.name.clone(),
url: url.clone(),
Expand Down
3 changes: 0 additions & 3 deletions crates/uv-resolver/src/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1928,9 +1928,6 @@ impl Source {
}

fn from_path_source_dist(path_dist: &PathSourceDist, root: &Path) -> Result<Source, LockError> {



let path = relative_to(&path_dist.install_path, root)
.map_err(LockErrorKind::DistributionRelativePath)?;

Expand Down
2 changes: 0 additions & 2 deletions crates/uv-workspace/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,6 @@ impl Workspace {
pyproject_toml,
});



Self::collect_members(
workspace_root.clone(),
workspace_definition,
Expand Down
2 changes: 2 additions & 0 deletions crates/uv/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ assert_cmd = { version = "2.0.14" }
assert_fs = { version = "1.1.0" }
base64 = { version = "0.22.0" }
byteorder = { version = "1.5.0" }
etcetera = { workspace = true }
filetime = { version = "0.2.23" }
ignore = { version = "0.4.22" }
indoc = { version = "2.0.4" }
Expand All @@ -94,6 +95,7 @@ predicates = { version = "3.0.4" }
regex = { workspace = true }
reqwest = { workspace = true, features = ["blocking"], default-features = false }
similar = { version = "2.6.0" }
tempfile = { workspace = true }
zip = { workspace = true }

[package.metadata.cargo-shear]
Expand Down
45 changes: 30 additions & 15 deletions crates/uv/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use assert_cmd::assert::{Assert, OutputAssertExt};
use assert_fs::assert::PathAssert;
use assert_fs::fixture::{ChildPath, PathChild, PathCopy, PathCreateDir, SymlinkToFile};
use base64::{prelude::BASE64_STANDARD as base64, Engine};
use etcetera::BaseStrategy;
use indoc::formatdoc;
use itertools::Itertools;
use predicates::prelude::predicate;
Expand Down Expand Up @@ -72,10 +73,10 @@ pub const INSTA_FILTERS: &[(&str, &str)] = &[
/// * Set a cutoff for versions used in the resolution so the snapshots don't change after a new release.
/// * Set the venv to a fresh `.venv` in `temp_dir`
pub struct TestContext {
pub temp_dir: assert_fs::TempDir,
pub cache_dir: assert_fs::TempDir,
pub python_dir: assert_fs::TempDir,
pub home_dir: assert_fs::TempDir,
pub temp_dir: ChildPath,
pub cache_dir: ChildPath,
pub python_dir: ChildPath,
pub home_dir: ChildPath,
pub venv: ChildPath,
pub workspace_root: PathBuf,

Expand All @@ -87,6 +88,9 @@ pub struct TestContext {

/// Standard filters for this test context.
filters: Vec<(String, String)>,

#[allow(dead_code)]
_root: tempfile::TempDir,
}

impl TestContext {
Expand Down Expand Up @@ -168,18 +172,29 @@ impl TestContext {
///
/// See [`TestContext::new`] if only a single version is desired.
pub fn new_with_versions(python_versions: &[&str]) -> Self {
let temp_dir = assert_fs::TempDir::new().expect("Failed to create test working directory");
let cache_dir = assert_fs::TempDir::new().expect("Failed to create test cache directory");
let python_dir = assert_fs::TempDir::new().expect("Failed to create test Python directory");
let home_dir = assert_fs::TempDir::new().expect("Failed to create test home directory");
let state =
etcetera::base_strategy::choose_base_strategy().expect("Failed to find base strategy");
let bucket = state.data_dir().join("uv").join("tests");
fs_err::create_dir_all(&bucket).expect("Failed to create test bucket");

let root = tempfile::TempDir::new_in(bucket).expect("Failed to create temp dir");

let temp_dir = ChildPath::new(root.path()).child("temp");
fs_err::create_dir_all(&temp_dir).expect("Failed to create temp dir");

let cache_dir = ChildPath::new(root.path()).child("cache");
fs_err::create_dir_all(&cache_dir).expect("Failed to create cache dir");

let python_dir = ChildPath::new(root.path()).child("python");
fs_err::create_dir_all(&python_dir).expect("Failed to create python dir");

let home_dir = ChildPath::new(root.path()).child("home");
fs_err::create_dir_all(&home_dir).expect("Failed to create home dir");

// Canonicalize the temp dir for consistent snapshot behavior
let canonical_temp_dir = temp_dir.canonicalize().unwrap();
let venv = ChildPath::new(canonical_temp_dir.join(".venv"));

println!("temp_dir: {:?}", temp_dir.path());
println!("canonical_temp_dir: {:?}", canonical_temp_dir);

let python_version = python_versions
.first()
.map(|version| PythonVersion::from_str(version).unwrap());
Expand Down Expand Up @@ -334,6 +349,7 @@ impl TestContext {
python_version,
python_versions,
filters,
_root: root,
}
}

Expand Down Expand Up @@ -366,7 +382,6 @@ impl TestContext {
.env("UV_EXCLUDE_NEWER", EXCLUDE_NEWER)
.env("UV_CWD", self.temp_dir.path())
.current_dir(self.temp_dir.path());
println!("current_dir: {:?}", self.temp_dir.path());

if cfg!(all(windows, debug_assertions)) {
// TODO(konstin): Reduce stack usage in debug mode enough that the tests pass with the
Expand Down Expand Up @@ -857,7 +872,7 @@ pub fn get_python(version: &PythonVersion) -> PathBuf {
/// Create a virtual environment at the given path.
pub fn create_venv_from_executable<P: AsRef<std::path::Path>>(
path: P,
cache_dir: &assert_fs::TempDir,
cache_dir: &ChildPath,
python: &Path,
) {
assert_cmd::Command::new(get_bin())
Expand All @@ -884,7 +899,7 @@ pub fn get_bin() -> PathBuf {
///
/// Generally this should be used with `UV_TEST_PYTHON_PATH`.
pub fn python_path_with_versions(
temp_dir: &assert_fs::TempDir,
temp_dir: &ChildPath,
python_versions: &[&str],
) -> anyhow::Result<OsString> {
Ok(std::env::join_paths(
Expand All @@ -898,7 +913,7 @@ pub fn python_path_with_versions(
///
/// Generally this should be used with `UV_TEST_PYTHON_PATH`.
pub fn python_installations_for_versions(
temp_dir: &assert_fs::TempDir,
temp_dir: &ChildPath,
python_versions: &[&str],
) -> anyhow::Result<Vec<PathBuf>> {
let cache = Cache::from_path(temp_dir.child("cache").to_path_buf()).init()?;
Expand Down
8 changes: 3 additions & 5 deletions crates/uv/tests/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7106,8 +7106,6 @@ fn lock_sources_archive() -> Result<()> {
let mut workspace_archive_file = fs_err::File::create(&*workspace_archive)?;
std::io::copy(&mut response.bytes()?.as_ref(), &mut workspace_archive_file)?;



let pyproject_toml = context.temp_dir.child("pyproject.toml");
pyproject_toml.write_str(&formatdoc! {
r#"
Expand All @@ -7134,8 +7132,8 @@ fn lock_sources_archive() -> Result<()> {
// insta::with_settings!({
// filters => context.filters(),
// }, {
assert_snapshot!(
lock, @r###"
assert_snapshot!(
lock, @r###"
version = 1
requires-python = ">=3.12"
Expand Down Expand Up @@ -7195,7 +7193,7 @@ fn lock_sources_archive() -> Result<()> {
[package.metadata]
requires-dist = [{ name = "anyio" }]
"###
);
);
// });

// Re-run with `--locked`.
Expand Down

0 comments on commit bdb8f97

Please sign in to comment.